Toll-Free Customer Support 24/7

GAS ATMEL CODE



/*
 * Project name:
    GAS sensor  
 * Copyright
     (c) Researchdesignlab.com
 * Description:
    
 * Test configuration:
     MCU:             AT89S52
     Dev.Board:       8051
     Oscillator:      11.0592 MHz
     Software:        Keil uVision3

*/


#include<reg51.h>  

#define LCD_PORT P2                    // LCD D0-D7 PINS connected P2
sbit rs=P3^5;                        // LCD RS PIN connected P3.5
sbit en=P3^7;                        // LCD EN PIN connected P3.7
sbit D7=P2^7;
sbit rw=P3^6;                         // LCD RW PIN connected P3.6

sbit GAS=P1^0;                        // GAS sensor PIN connected P1.0



void busy();                          //LCD busy
void CMD_WRT(unsigned char);           //To write the commands to the LCD
void DATA_WRT(unsigned char);         //To write the data to the LCD
void LCD_WRT(unsigned char *);
void DELAY();


 void main()
  {
   unsigned char CMD[]={0x38,0x01,0x0f,0x06,0x80},TEMP1,i;

    for(i=0;i<5;i++)
    {
    TEMP1=CMD[i];                         //write the commands to the LCD
    CMD_WRT(TEMP1);
    }
    
   while(1)
   {
    if(GAS==1)                             
    {
    CMD_WRT(0X01);                        // LCD clear cmd
    CMD_WRT(0X80);                        // LCD 1st line cmd
       LCD_WRT("GAS ACTIVATED");                    // Display the data on LCD
    DELAY();
    }
    else                                 
    {
    CMD_WRT(0X01);                        // LCD clear cmd
    CMD_WRT(0X80);                        // LCD 2nd line cmd
       LCD_WRT("GAS DEACTIVATED");                    // Display the data on LCD
    DELAY();
    }
   }


  }

    
    void DELAY()
    {                                  //delay of 3ms
    unsigned int X=800000;
    while(X--);
    }
    
    
    void busy()
    {
    D7=1;
    rs=0;                             //cmd mode
    rw=1;                             //read
    while(D7!=0)                    //wait till LCD is ready
    {
    en=0;
    en=1;                            // low to high latch
    }
    }
    
    
    
    void CMD_WRT(unsigned char val)
    {
    busy();
    LCD_PORT=val;                   //write cmd to P2
    rs=0;                           //cmd mode
    rw=0;                           //write
    en=1;
    en=0;                           //high to low latch
    }
    
    
    void DATA_WRT(unsigned char ch)
    {
    busy();
    LCD_PORT = ch;                  //write cmd to P2
    rs=1;                          //data mode
    rw=0;                          //write
    en=1;
    en=0;                          //high to low latch
    }
    
    void LCD_WRT(unsigned char *string)
    {
    while(*string)                  
    DATA_WRT(*string++);
    }
    

Back to top