Temperature monitoring using LM35 sensor with 8051 microcontroller

 In this project we measure the environment Temperature using LM35 Sensor. 

We measure the temperature and displayed on LCD. LM35 is a analog sensor, but microcontroller does not recognize the analog signal. So we convert the analog output of sensor to digital signal using ADC (Analog to Digital Converter). In this project we use ADC0808 IC. This ADC have 8 input pins and 8 Out pins. The output is displayed on LCD screen. 

Connection: 


Program:

#include<reg51.h>

#define adc_data P1
#define lcd  P0

unsigned char temp, gas;

sbit rs=P3^0;
sbit rw=P3^1;
sbit en=P3^2;

sbit OE     =P2^0;
sbit EOC    =P2^2;
sbit START  =P2^1;
sbit AA     =P2^4;
sbit BB     =P2^5;
sbit CC     =P2^6;
sbit ALE    =P2^7;

unsigned char adc_val;

void lcd_int();
void cmd(unsigned int b);
void dat(unsigned int c);
void show(unsigned char *s);
void lcd_delay();

unsigned char adc(unsigned int ch);
void ch_sel(unsigned int sel);

void  main()
{
    lcd_int();
    show("TEMP: ");
    cmd(0xc0);
    //show("GAS : ");
    while(1) {
        cmd(0x86);
        temp=adc(0); //Reading Value from ADC Channel 0
        dat((temp/100)%10 +0x30);
        dat((temp/10)%10 +0x30);
        dat(temp%10 +0x30);
dat('C');
    }
}
void lcd_int()
{
    cmd(0x38);
    cmd(0x0e);
    cmd(0x06);
    cmd(0x01);
    cmd(0x80);
}

void cmd(unsigned int b)
{
    lcd=b;
    rs=0;
    rw=0;
    en=1;
    lcd_delay();
    en=0;
}

void dat(unsigned int c)
{
    lcd=c;
    rs=1;
    rw=0;
    en=1;
    lcd_delay();
    en=0;
}
void show(unsigned char *s)
{
    while(*s) {
        dat(*s++);
    }
}

void lcd_delay()
{
    unsigned int lcd_delay;
    for(lcd_delay=0;lcd_delay<=1000;lcd_delay++);
}

unsigned char adc(unsigned int ch)
{
    adc_data=0xff;

    ALE=START=OE=AA=BB=CC=0;
    EOC=1;

    ch_sel(ch);

    ALE=1;
    START=1;
    ALE=0;
    START=0;
    while(EOC==1);
    while(EOC==0);
    OE=1;
    adc_val=adc_data;
    OE=0;
    return adc_val;
}

void ch_sel(unsigned int sel)
{
    switch(sel) {
        case 0: CC=0;BB=0;AA=0; break;          //000
        case 1: CC=0;BB=0;AA=1; break;          //001
        case 2: CC=0;BB=1;AA=0; break;          //010
        case 3: CC=0;BB=1;AA=1; break;          //011
        case 4: CC=1;BB=0;AA=0; break;          //100
        case 5: CC=1;BB=0;AA=1; break;          //101
        case 6: CC=1;BB=1;AA=0; break;          //110
        case 7: CC=1;BB=1;AA=1; break;          //111
    }
}

Output:



Comments

Popular posts from this blog