/* This is the EMBEDDED C code for Automatic Light Control system */
#include<AT89X51.H>#include<LCD_8_BIT.H>
//====================== ir pair init =========================
sbit ir1=P1^0;
sbit ir2=P1^1;
//====================== Lights init ==============================
sbit l1=P3^0;
sbit l2=P3^1;
sbit l3=P3^2;
sbit l4=P3^3;
//====================== delay function ========================
void Delay(unsigned int itime)
{
unsigned int i,j;
for(i=0;i<itime;i++)
for(j=0;j<1257;j++);
}
//====================== main function ===========================
void main()
{
ir1=1;ir2=1;
l1=0;l2=0;l3=0;l4=0;
lcd_init();
lcd_clear();
lcd_print(" Welcome To");
lcd_cmd(0xC0);
lcd_print(" Y.P.R College");
Delay(400);
lcd_clear();
lcd_print(" Automatic Room");
lcd_cmd(0xC0);
lcd_print(" Light Control");
Delay(200);
while(1)
{
//l1=1;l2=0;l3=0;l4=0;
if((ir1 == 1) && (ir2 == 1))
{
l1=1;l2=0;l3=0;l4=0;
Delay(200);
lcd_clear();
lcd_print("Normal Light");
lcd_cmd(0xC0);
lcd_print(" Is ON");
Delay(200);
}
else if((ir1 == 0) && (ir2 == 1))
{
l1=1;l2=1;l3=0;l4=0;
Delay(200);
lcd_clear();
lcd_print(" First Light");
lcd_cmd(0xC0);
lcd_print("With Normal Light");
Delay(200);
}
else if((ir1 ==1) && (ir2 == 0))
{
l1=1;l2=0;l3=1;l4=0;
Delay(200);
lcd_clear();
lcd_print(" Second Light");
lcd_cmd(0xC0);
lcd_print("With Normal Light");
Delay(200);
}
else if((ir1 ==0) && (ir2 == 0))
{
l1=1;l2=1;l3=1;l4=1;
Delay(200);
lcd_clear();
lcd_print("All Lights");
lcd_cmd(0xC0);
lcd_print(" Are ON");
Delay(200);
}
}
}
//LCD PROTOTYPES
void Delay();
void lcd_init(); //lcd initialisation
void lcd_clear(); //clear display
void lcd_cmd(unsigned char); //set the lcd address or command
void lcd_print(unsigned char *); //write the string to LCD
//===============================================
sbit RS =P3^6; //RESET
sbit EN =P3^7; //ENABLE
#define LCD P2 //DATA0-DATA7 TO P2
//===============================================
unsigned char i;
//===============================================
void Delay1()
{
unsigned char j;
for(i=0;i<15;i++)
for(j=0;j<100;j++);
}
//===============================================
void lcd_init()
{
lcd_cmd(0x38);
lcd_cmd(0x01);
lcd_cmd(0x0C);
lcd_cmd(0x06);
lcd_cmd(0x80);
}
//===============================================
void lcd_clear(void)
{
lcd_cmd(0x01);
lcd_cmd(0x80);
}
//===============================================
/* void lcd_char(unsigned char dat)
{
LCD =dat;
RS =1;
EN =1;
for(i=0;i<100;i++);
EN =0;
for(i=0;i<100;i++);
}
*/
//===============================================
void lcd_cmd(unsigned char cmd)
{
Delay1();
LCD =cmd;
RS =0;
EN =1;
for(i=0;i<120;i++);
EN =0;
for(i=0;i<120;i++);
}
//===============================================
void lcd_print(unsigned char *str)
{
while(*str)
{
LCD =*str;
RS =1;
EN =1;
Delay1();
EN =0;
str++;
}
}
//===============================================
No comments:
Post a Comment