data logging too collect and display temperature with time and date

Upload: kranthikumar

Post on 03-Jun-2018

221 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/11/2019 Data Logging Too Collect and Display Temperature With Time and Date

    1/31

  • 8/11/2019 Data Logging Too Collect and Display Temperature With Time and Date

    2/31

    CONTENTS

    1.INTRODUCTION

    2.BLOCK DIAGRAM

    8051 MICROCONTROLLER

    RTC

    ADC

    RS232/MAX232

    LM35

    PC HYPERTERMINAL

    3. SIMULATION CIRCUIT

    4.PCB DESIGN

    5.APPLICATIONS

    6.SOURCE CODE

    7.LIST OF HARDWARE COMPONENTS

  • 8/11/2019 Data Logging Too Collect and Display Temperature With Time and Date

    3/31

    INTRODUCTION

    The main object of our project is to update the analog data to the server with period of

    each second, display and store the data with temperature ,time and day through serial

    communication.

    In this project we are doing simulation in PROTEUS 6.9 using AT89c51,Analog toDigital converter(ADC),Real time clock(RTC),Temperature sensor(LM35),RS232 and designing

    the PCB using EAGLE software.

    Here the temperature is obtained as analog value and later it is converted to digital value by

    analog-to-digital converter.By using Real time Clock,time and day are displayed.Temperature is

    displayed using LM35 sensor(100oC). The whole data which is collected is displayed on the PC

    screen in the hyperterminal console using RS232.

  • 8/11/2019 Data Logging Too Collect and Display Temperature With Time and Date

    4/31

    BLOCK DIAGRAM:

    PCHYPERTERMINAL

    RS232 MAX232TEMPERATURESENSOR (LM35)

    ADC

    RTC

    8051

    MICRO

    CONTROLLER

  • 8/11/2019 Data Logging Too Collect and Display Temperature With Time and Date

    5/31

    8051 MICROCONTROLLER:

    The 8051 micro controller generic part number actually includes a whole family of

    microcontrollers that have numbers ranging from 8031 to 8751 and are available in N-channelmetal oxide silicon (NMOS) and complementary metal oxide silicon (CMOS) construction in

    variety of packages.

    The Intel 8051 is an 8-bit microcontroller which means that most available operations are

    limited to 8-bit. There are 3 basic sizes of the 8051:short, standard, and extended. The short and

    standard chips are often available in DIP(dual in-line package) form, but the Extended 8051

    models often have a different form factor, and are not drop-in compatible. All these things arecalled 8051 because they can all be programmed using 8051 assembly language, and they all

    share certain features (although the different models all have their own special features).

    FEATURES OF 8051:

    8-bit data bus

    16-bit address bus

    32 general purpose registers each 8 bits

    16 bit timers(usually 2, but may have more, or less)

    3 internal and 2 external interrupts.

    Bit as well as byte addressable RAM area of 16 bytes.

    Four 8-bit ports, (short models have two 8-bit ports).

  • 8/11/2019 Data Logging Too Collect and Display Temperature With Time and Date

    6/31

    16-bit program counter and data pointer.

    8051 models may also have a number of special, model-specific features, such as UARTs, ADC,

    OpAmps ,etc..

    TMOD is dedicated solely to the two timers and can be considered to be two duplicate 4-

    bit registers each of which controls the action of one of the timers. TCON has control bits and

    flags for the timers in the upper nibble and control bits and flags for the external interrupts in the

    lower nibble.

    PIN CONFIGURATION OF 8051:

  • 8/11/2019 Data Logging Too Collect and Display Temperature With Time and Date

    7/31

    123

    45678910111213

    14151617181920

    403938

    37363534333231302928

    27262524232221

    P1.0P1.1P1.2

    P1.3P1.4P1.5P1.6P1.7RST

    (RXD)P3.0(TXD)P3.1

    (T0)P3.4(T1)P3.5

    XTAL2XTAL1

    GND

    (INT0)P3.2(INT1)P3.3

    (RD)P3.7(WR)P3.6

    VccP0.0(AD0)P0.1(AD1)

    P0.2(AD2)P0.3(AD3)P0.4(AD4)P0.5(AD5)P0.6(AD6)P0.7(AD7)EA/VPP

    ALE/PROGPSENP2.7(A15)

    P2.6(A14)P2.5(A13)P2.4(A12)P2.3(A11)P2.2(A10)P2.1(A9)P2.0(A8)

    8051

    INPUT/OUTPUT PORTS:

    One major feature of a micro controller is the versatility built into the input/output

    circuits that connect the 8051 to the outside world. Given the pin flexibility, the 8051 may be

    simply applied as a single component with input/output only, or it may be expanded to include

    additional memory, parallel ports, and serial data communication by using the alternate pin

    assignments. Those locations weve just added are called ports. There are several types of

    ports: input, output or bi-directional ports. When working with ports, first of all it is necessary to

    choose which port we need to work with, and then to send data to, or take it from the port.

    When working with it the port acts like a memory location. Something is simply being

    written into or read from it, and it could be noticed on the pins of the micro-controller.

    There are 4 8-bit ports P0, P1, P2, P3.

  • 8/11/2019 Data Logging Too Collect and Display Temperature With Time and Date

    8/31

    PORT P1(pins 1 to 8): the port P1 is general purpose input/output port which can be used

    for a variety of interfacing tasks. The ports P0, P2 and P3 have duel roles or additional functions

    associated with them based upon the context of their usage.

    PORT P3(pins 7 to 17): PORT P3 acts a normal IO port, but port P3 has additionalfunctions such as, serial transmit and receive pins, 2 external interrupt pins, 2 external counter

    inputs, read and write pins for memory access.

    PORT P2(pins 21 to 28): PORT P2 can also be used as a general purpose 8 bit port when

    no external memory is present, but if external memory access is required then PORT P2 will act

    as an address bus in conjunction with PORT P0 to access external memory. PORT P2 acts as A8-

    A15.

    PORT0(pins 32 to 39): PORT P0 can be used as a general purpose 8 bit port when no

    external memory is present, but if external memory access is required then PORT P0 acts as a

    multiplexed address and data bus that can be used to access external memory is conjunction with

    PORT P2. P0 acts as AD0-AD7.

    RTC REAL TIME CLOCK:

    A real time clock is basically just like a watch - it runs on a battery and keeps time

    for you even when there is a power outage. Using an RTC, you can keep track of long timelines,

    even if you reprogram your microcontroller or disconnect it from USB or a power plug. A RTC

    is a computer clock that keeps the track of current time. RTCs are present in almost any

    electronic device which needs to keep accurate time. RTCs often have an alternate source of

    power, so they can continue to keep time while the primary source of power is off or

    unavailable.

    Most RTCs use a crystal oscillator but some use the power line frequency. In many

    cases the oscillators frequency is 32.768 kHz. This is the same frequency used in quartz clocks

    and watches, and for the same reasons ,namely that frequency is exactly 215 cycles per second,

    which is convenient rate to use with simple binary counter circuits.

  • 8/11/2019 Data Logging Too Collect and Display Temperature With Time and Date

    9/31

    RS232:

    In telecommunications, RS-232 (Recommended Standard 232) is the traditional name

    for a series of standards for serial binary single-ended data and control signals connecting

    between a DTE (Data Terminal Equipment) and a DCE (Data Circuit-terminating Equipment). It

    is commonly used in computer serial ports. The standard defines the electrical characteristics and

    timing of signals, the meaning of signals, and the physical size and pinout of connectors. The

    current version of the standard is TIA-232-F Interface Between Data Terminal Equipment and

    Data Circuit-Terminating Equipment Employing Serial Binary Data Interchange, issued in 1997.

    In RS-232, user data is sent as a time-series of bits. Both synchronous and asynchronous

    transmissions are supported by the standard. In addition to the data circuits, the standard definesa number of control circuits used to manage the connection between the DTE and DCE. Each

    data or control circuit only operates in one direction, that is, signaling from a DTE to the

    attached DCE or the reverse. Since transmit data and receive data are separate circuits, the

    interface can operate in a full duplex manner, supporting concurrent data flow in both directions.

    The standard does not define character framing within the data stream, or character encoding.

    RS-232 devices may be classified as Data Terminal Equipment (DTE) or Data

    Communication Equipment (DCE); this defines at each device which wires will be sending and

    receiving each signal. In general and according to the standard, terminals and computers have

    male connectors with DTE pin functions, and modems have female connectors with DCE pin

    functions. Other devices may have any combination of connector gender and pin definitions.

    Many terminals were manufactured with female terminals but were sold with a cable with male

    connectors at each end; the terminal with its cable satisfied the recommendations in the standard.

    PIN DIAGRAM OF RS232

    http://en.wikipedia.org/wiki/Telecommunicationshttp://en.wikipedia.org/wiki/Serial_communicationshttp://en.wikipedia.org/wiki/Single-ended_signallinghttp://en.wikipedia.org/wiki/Data_signalhttp://en.wikipedia.org/wiki/Control_signalhttp://en.wikipedia.org/wiki/Data_Terminal_Equipmenthttp://en.wikipedia.org/wiki/Data_circuit-terminating_equipmenthttp://en.wikipedia.org/wiki/Computerhttp://en.wikipedia.org/wiki/Serial_porthttp://en.wikipedia.org/wiki/Time-serieshttp://en.wikipedia.org/wiki/Bithttp://en.wikipedia.org/wiki/Full_duplexhttp://en.wikipedia.org/wiki/Full_duplexhttp://en.wikipedia.org/wiki/Bithttp://en.wikipedia.org/wiki/Time-serieshttp://en.wikipedia.org/wiki/Serial_porthttp://en.wikipedia.org/wiki/Computerhttp://en.wikipedia.org/wiki/Data_circuit-terminating_equipmenthttp://en.wikipedia.org/wiki/Data_Terminal_Equipmenthttp://en.wikipedia.org/wiki/Control_signalhttp://en.wikipedia.org/wiki/Data_signalhttp://en.wikipedia.org/wiki/Single-ended_signallinghttp://en.wikipedia.org/wiki/Serial_communicationshttp://en.wikipedia.org/wiki/Telecommunications
  • 8/11/2019 Data Logging Too Collect and Display Temperature With Time and Date

    10/31

    SERIAL COMMUNICATION :

    Serial communication is often used either to control or to receive data from an embedded

    microprocessor. Serial communication is a form of I/O in which the bits of a byte begin

    transferred appear one after the other in a timed sequence on a single wire. Serial communicationhas become the standard for intercomputer communication. In this project, we'll try to build a

    serial link between 8051 and PC using RS232.

    8051 provides a transmit channel and a receive channel of serial communication. The transmit

    data pin (TXD) is specified at P3.1, and the receive data pin (RXD) is at P3.0. The serial signals

    provided on these pins are TTL signal levels.All modes are controlled through SCON, the Serial

    CONtrol register. The SCON bits are defined as SM0, SM1, SM2, REN, TB8, RB8, TI, RI from

    MSB to LSB. The timers are controlled using TMOD, the Timer MODe register, and TCON, theTimer CONtrol register.

    TEMPERATURE SENSOR(LM35):

  • 8/11/2019 Data Logging Too Collect and Display Temperature With Time and Date

    11/31

    The LM35 sensor series(shown in figure) are precision integrated-circuit temperature

    sensors, whose output voltage is linearly proportional to the Celsius (Centigrade) temperature.

    The LM35 sensor thus has an advantage over linear temperature sensors calibrated in Kelvin,

    as the user is not required to subtract a large constant voltage from its output to obtain

    convenient Centigrade scaling. The LM35 sensor does not require any external calibration or

    trimming to provide typical accuracies of C at room temperature and C over a full -55 to

    +150C temperature range. The LM35's low output impedance, linear output, and precise

    inherent calibration make interfacing to readout or control circuitry especially easy. It can be

    used with single power supplies, or with plus and minus supplies. As it draws only 60 mA from

    its supply, it has very low self-heating, less than 0.1C in still air. The LM35 is rated to operate

    over a b55 to a150C temperature range, while the LM35C is rated for a b40 to a110Crange

    (b10 with improved accuracy).

    ADC: ANALOG TO DIGITAL CONVERTER:

    Analog-to-Digital converters are among the most widely used devices for data

    acquisition. An analog-to-digital converter (abbreviated ADC , A/D or A to D ) is a device that

    converts a continuous quantity to a discrete digital number. The reverse operation is performed

    by a digital-to-analog converter (DAC ).

    Typically, an ADC is an electronic device that converts an input analog voltage (or

    current) to a digital number proportional to the magnitude of the voltage or current. However,

    some non-electronic or only partially electronic devices, such as rotary encoders, can also be

    considered ADCs.

    http://en.wikipedia.org/wiki/Discrete_signalhttp://en.wikipedia.org/wiki/Digitalhttp://en.wikipedia.org/wiki/Digital-to-analog_converterhttp://en.wikipedia.org/wiki/Electronicshttp://en.wikipedia.org/wiki/Voltagehttp://en.wikipedia.org/wiki/Electric_currenthttp://en.wikipedia.org/wiki/Digitalhttp://en.wikipedia.org/wiki/Rotary_encoderhttp://en.wikipedia.org/wiki/Rotary_encoderhttp://en.wikipedia.org/wiki/Digitalhttp://en.wikipedia.org/wiki/Electric_currenthttp://en.wikipedia.org/wiki/Voltagehttp://en.wikipedia.org/wiki/Electronicshttp://en.wikipedia.org/wiki/Digital-to-analog_converterhttp://en.wikipedia.org/wiki/Digitalhttp://en.wikipedia.org/wiki/Discrete_signal
  • 8/11/2019 Data Logging Too Collect and Display Temperature With Time and Date

    12/31

    The digital output may use different coding schemes. Typically the digital output will be a

    two's complement binary number that is proportional to the input, but there are other

    possibilities. An encoder, for example, might output a Gray code.

    An ADC might be used to make an isolated measurement. ADCs are also used to

    quantize time-varying signals by turning them into a sequence of digital samples. The result is

    quantized in both time and value.

    SIMULATION CIRCUIT:

    http://en.wikipedia.org/wiki/Two%27s_complementhttp://en.wikipedia.org/wiki/Gray_codehttp://en.wikipedia.org/wiki/Signal_(information_theory)http://en.wikipedia.org/wiki/Signal_(information_theory)http://en.wikipedia.org/wiki/Gray_codehttp://en.wikipedia.org/wiki/Two%27s_complement
  • 8/11/2019 Data Logging Too Collect and Display Temperature With Time and Date

    13/31

    PCB DESIGN:

  • 8/11/2019 Data Logging Too Collect and Display Temperature With Time and Date

    14/31

    APPLICATIONS:

    Environmental study center.

    SOURCE CODE:

    #include

  • 8/11/2019 Data Logging Too Collect and Display Temperature With Time and Date

    15/31

    #include

    #include

    sbit WRITE=P2^5;

    sbit READ=P2^6;

    sbit INTR=P2^7;

    sfr ldata=0x90;

    void delay(int);

    char RTC_ARR[7]; // Buffer for second,minute,.....,year

    void main()

    {

    char value1,value2,var;

    INTR=1;

    WRITE=1;

    READ=1;

    while(1)

    { ReadRTC(&RTC_ARR[0]);

    RTC_ARR[0] = RTC_ARR[0] & 0x7F; // enable oscillator (bit 7=0)

    RTC_ARR[1] = 0x50; // minute = 59

    RTC_ARR[2] = 0x12; // hour = 05 ,24-hour mode(bit 6=0)

    RTC_ARR[3] = 0x03; // Day = 1 or sunday

  • 8/11/2019 Data Logging Too Collect and Display Temperature With Time and Date

    16/31

    RTC_ARR[4] = 0x10; // Date = 30

    RTC_ARR[5] = 0x08; // month = August

    RTC_ARR[6] = 0x10; // year = 05 or 2005

    WriteRTC(&RTC_ARR[0]); // Set RTC

    WRITE=0;

    delay(10);

    WRITE=1;

    while(INTR==1);

    READ=0;

    delay(10);

    TMOD=0x20;

    TH1=0xfd;

    SCON=0x52;

    TR1=1;

    ReadRTC(&RTC_ARR[0]);

    //putchar(0x0C);

    printf("\n Data Logging \n");

    printf(" ____________ \n\n");

    printf("Time : %02bX:%02bX:%02bX",RTC_ARR[2],RTC_ARR[1],RTC_ARR[0]);

    printf(" %s\r",Int2Day(RTC_ARR[3]));

    delay(10);

  • 8/11/2019 Data Logging Too Collect and Display Temperature With Time and Date

    17/31

    printf("\n Temperature = ");

    delay(10);

    var=ldata;

    //var=ldata*10/7.66;

    if(ldata>=10)

    {

    value1=(var/10)+0x30;

    SBUF=value1;

    delay(10);

    value2=(var%10)+0x30;

    SBUF=value2;

    delay(10);

    }

    else

    {

    value2=(var%10)+0x30;

    SBUF=value2;

    delay(10);

    }

    printf(" deg");

    while(TI==0);

  • 8/11/2019 Data Logging Too Collect and Display Temperature With Time and Date

    18/31

    TI=0;

    delay(10);

    READ=1;

    delay(1000);

    }}

    void delay(int time)

    {

    int i,j;

    for(i=0;i

  • 8/11/2019 Data Logging Too Collect and Display Temperature With Time and Date

    19/31

    unsigned char i;

    const unsigned char * DayStr[7] = {{"Sun"},

    {"Mon"},

    {"Tue"},

    {"Wen"},

    {"The"},

    {"Fri"},

    {"Sat"}};

    const unsigned char * MonthStr[12] ={{"Jan"},

    {"Feb"},

    {"Mar"},

    {"Apr"},

    {"May"},

    {"Jun"},

    {"Jul"},

    {"Aug"},

    {"Sep"},

    {"Oct"},

  • 8/11/2019 Data Logging Too Collect and Display Temperature With Time and Date

    20/31

    {"Nov"},

    {"Dec"}};

    sbit SDA = P2^1; // connect to SDA pin (Data)

    sbit SCL = P2^0; // connect to SCL pin (Clock)

    //-------------------------------

    // Convert BCD 1 byte to HEX 1 byte

    //-------------------------------

    /*unsigned char BCD2HEX(unsigned int bcd)

    {

    unsigned char temp;

    temp=((bcd>>8)*100)|((bcd>>4)*10)|(bcd&0x0f);

    return temp;

    } */

    //-------------------------------

  • 8/11/2019 Data Logging Too Collect and Display Temperature With Time and Date

    21/31

    // start I2C

    //-------------------------------

    void Start(void)

    {

    SDA = 1;

    SCL = 1;

    _nop_();_nop_();

    SDA = 0;

    _nop_();_nop_();

    SCL = 0;

    _nop_();_nop_();

    }

    //-------------------------------

    // stop I2C

    //-------------------------------

    void Stop(void)

    {

    SDA = 0;

    _nop_();_nop_();

    SCL = 1;

  • 8/11/2019 Data Logging Too Collect and Display Temperature With Time and Date

    22/31

    _nop_();_nop_();

    SDA = 1;

    }

    //-------------------------------

    // Write I2C

    //-------------------------------

    void WriteI2C(unsigned char Data)

    {

    for (i=0;i

  • 8/11/2019 Data Logging Too Collect and Display Temperature With Time and Date

    23/31

    }

    //-------------------------------

    // Read I2C

    //-------------------------------

    unsigned char ReadI2C(bit ACK_Bit)

    {

    unsigned char Data=0;

    SDA = 1;

    for (i=0;i

  • 8/11/2019 Data Logging Too Collect and Display Temperature With Time and Date

    24/31

    SDA = 0; // Send ACK

    else

    SDA = 1; // Send NO ACK

    _nop_();_nop_();

    SCL = 1;

    _nop_();_nop_();

    SCL = 0;

    return Data;

    }

    // Read RTC (all real time)

    //-------------------------------

    void ReadRTC(unsigned char * buff)

    {

    Start();

    WriteI2C(0xD0);

    WriteI2C(0x00);

  • 8/11/2019 Data Logging Too Collect and Display Temperature With Time and Date

    25/31

    Start();

    WriteI2C(0xD1);

    *(buff+0)=ReadI2C(ACK); // Second

    *(buff+1)=ReadI2C(ACK); // Minute

    *(buff+2)=ReadI2C(ACK); // hour

    *(buff+3)=ReadI2C(ACK); // Day

    *(buff+4)=ReadI2C(ACK); // date

    *(buff+5)=ReadI2C(ACK); // month

    *(buff+6)=ReadI2C(NO_ACK); // year

    Stop();

    }

    //-------------------------------

    // Write RTC

    //-------------------------------

    void WriteRTC(unsigned char *buff)

    {

    Start();

    WriteI2C(0xD0);

  • 8/11/2019 Data Logging Too Collect and Display Temperature With Time and Date

    26/31

    WriteI2C(0x00);

    WriteI2C(*(buff+0));

    WriteI2C(*(buff+1));

    WriteI2C(*(buff+2));

    WriteI2C(*(buff+3));

    WriteI2C(*(buff+4));

    WriteI2C(*(buff+5));

    WriteI2C(*(buff+6));

    Stop();

    }

    //-------------------------------

    // Convert date (BCD) to string of Day

    // 1=Sanday

    // 2=Monday

    // And so on

    //-------------------------------

    char * Int2Day(unsigned char day)

    {

    return DayStr[day-1];}

    #include

    #include

  • 8/11/2019 Data Logging Too Collect and Display Temperature With Time and Date

    27/31

    #include

    sbit WRITE=P2^5;

    sbit READ=P2^6;

    sbit INTR=P2^7;

    sfr ldata=0x90;

    void delay(int);

    char RTC_ARR[7]; // Buffer for second,minute,.....,year

    void main()

    {

    char value1,value2,var;

    INTR=1;

    WRITE=1;

    READ=1;

    while(1)

    { ReadRTC(&RTC_ARR[0]);

    RTC_ARR[0] = RTC_ARR[0] & 0x7F; // enable oscillator (bit 7=0)

    RTC_ARR[1] = 0x50; // minute = 59

    RTC_ARR[2] = 0x12; // hour = 05 ,24-hour mode(bit 6=0)

    RTC_ARR[3] = 0x03; // Day = 1 or sunday

    RTC_ARR[4] = 0x10; // Date = 30

  • 8/11/2019 Data Logging Too Collect and Display Temperature With Time and Date

    28/31

    RTC_ARR[5] = 0x08; // month = August

    RTC_ARR[6] = 0x10; // year = 05 or 2005

    WriteRTC(&RTC_ARR[0]); // Set RTC

    WRITE=0;

    delay(10);

    WRITE=1;

    while(INTR==1);

    READ=0;

    delay(10);

    TMOD=0x20;

    TH1=0xfd;

    SCON=0x52;

    TR1=1;

    ReadRTC(&RTC_ARR[0]);

    //putchar(0x0C);

    printf("\n Data Logging \n");

    printf(" ____________ \n\n");

    printf("Time : %02bX:%02bX:%02bX",RTC_ARR[2],RTC_ARR[1],RTC_ARR[0]);

    printf(" %s\r",Int2Day(RTC_ARR[3]));

    delay(10);

    printf("\n Temperature = ");

  • 8/11/2019 Data Logging Too Collect and Display Temperature With Time and Date

    29/31

  • 8/11/2019 Data Logging Too Collect and Display Temperature With Time and Date

    30/31

    delay(10);

    READ=1;

    delay(1000);

    }}

    void delay(int time)

    {

    int i,j;

    for(i=0;i

  • 8/11/2019 Data Logging Too Collect and Display Temperature With Time and Date

    31/31

    COMPONENT

    1. Adapter socket 1

    2. Regulator 1

    3. On-off switch 1

    4. CMOS battery with holder 1

    5. Serial port 1

    6. 8051 microcontroller 1

    7. RS232 1

    8. DS1307 1

    9. LM35 1

    10. Resistors 10k1k

    43

    11. Capacitors 1000uF,35V

    10uF,50V

    33pF

    1uF tantalum

    1

    3

    3

    4

    12. Pull up resistors 1k 113. Pot 10K 1

    14. Crystal 11.0592MHz 1

    15. LED 1

    16. Push button 1

    17. Bergsticks 40

    18. Diodes 4

    19. Reed 1

    20. LDR 1