#include<reg52.h>
#include<ee.h>
#include<eprom.h>
#include<lcdfuncs.h>
sbit relay1=P3^1;
sbit relay2=P3^5;
sbit relay3=P3^6;
//sbit relay4=P3^7;
sbit i1=P1^5;
sbit i2=P1^6;
sbit i3=P1^4;
char char_sel=1,screen_no,ccc1,ccc2,ccc3;
unsigned int on_time_rl1,on_time_rl2,on_time_rl3;
unsigned int off_time_rl1,off_time_rl2,off_time_rl3;
unsigned int t_i1_on=0,t_i2_on=0,t_i3_on=0;
unsigned int t_i1_off=0,t_i2_off=0,t_i3_off=0;
char on_time1_rl1,on_time2_rl1,on_time3_rl1;
char on_time1_rl2,on_time2_rl2,on_time3_rl2;
char on_time1_rl3,on_time2_rl3,on_time3_rl3;
char off_time1_rl1,off_time2_rl1,off_time3_rl1;
char off_time1_rl2,off_time2_rl2,off_time3_rl2;
char off_time1_rl3,off_time2_rl3,off_time3_rl3;
bit in_1_on_flag=0,in_2_on_flag=0,in_3_on_flag=0;
bit in_1_off_flag=0,in_2_off_flag=0,in_3_off_flag=0;
int k;
unsigned int temp_time=0;
char *x;
key_pressed();
void delay(unsigned int del)
{
unsigned long int j;
for(j=0;j<del*2;j++);
}
display_count (unsigned char c3,unsigned char c2,unsigned char c1)
{
write_LCD_byte(LCD_CONTROL,LINE_2 + 8);
write_LCD_byte(LCD_DATA,c3 + 0x30);
write_LCD_byte(LCD_CONTROL,LINE_2 + 9);
write_LCD_byte(LCD_DATA,'.');
write_LCD_byte(LCD_CONTROL,LINE_2 + 10);
write_LCD_byte(LCD_DATA,c2 + 0x30);
write_LCD_byte(LCD_CONTROL,LINE_2 + 11);
write_LCD_byte(LCD_DATA,c1 + 0x30);
write_LCD_byte(LCD_CONTROL,LINE_2 + 13);
write_LCD_byte(LCD_DATA,'S');
write_LCD_byte(LCD_CONTROL,LINE_2 + 14);
write_LCD_byte(LCD_DATA,'e');
write_LCD_byte(LCD_CONTROL,LINE_2 + 15);
write_LCD_byte(LCD_DATA,'c');
switch(char_sel)
{
case 1: write_LCD_byte(LCD_CONTROL,0x0E);
write_LCD_byte(LCD_CONTROL,LINE_2 + 11);
break;
case 2: write_LCD_byte(LCD_CONTROL,0x0E);
write_LCD_byte(LCD_CONTROL,LINE_2 + 10);
break;
case 3: write_LCD_byte(LCD_CONTROL,0x0E);
write_LCD_byte(LCD_CONTROL,LINE_2 + 8);
break;
default: write_LCD_byte(LCD_CONTROL,0x0C);
break;
}
}
main()
{
delay(100);
// P0=0xff;
P2=0XFF;
P1=0xff;
P3=0xff;
SP=0x7f;
TL1=0x2f;
TH1=0xf8;
TMOD=(TMOD & 0x0f) | 0x10;
ET1=1;
IT1=1;
EA=1;
WP=0;
sda=1;
scl=1;
delay(100);
init_2_line_LCD();
delay(10);
ee_byte_from_ee(0x0b,&on_time1_rl1);delay(10);
ee_byte_from_ee(0x1b,&on_time2_rl1);delay(10);
ee_byte_from_ee(0x2b,&on_time3_rl1);delay(10);
ee_byte_from_ee(0x4b,&on_time1_rl2);delay(10);
ee_byte_from_ee(0x5b,&on_time2_rl2);delay(10);
ee_byte_from_ee(0x6b,&on_time3_rl2);delay(10);
ee_byte_from_ee(0x7b,&on_time1_rl3);delay(10);
ee_byte_from_ee(0x8b,&on_time2_rl3);delay(10);
ee_byte_from_ee(0x9b,&on_time3_rl3);delay(10);
ee_byte_from_ee(0xab,&off_time1_rl1);delay(10);
ee_byte_from_ee(0xbb,&off_time2_rl1);delay(10);
ee_byte_from_ee(0xcb,&off_time3_rl1);delay(10);
ee_byte_from_ee(0xdb,&off_time1_rl2);delay(10);
ee_byte_from_ee(0xeb,&off_time2_rl2);delay(10);
ee_byte_from_ee(0x43,&off_time3_rl2);delay(10);
ee_byte_from_ee(0x53,&off_time1_rl3);delay(10);
ee_byte_from_ee(0x63,&off_time2_rl3);delay(10);
ee_byte_from_ee(0x73,&off_time3_rl3);delay(10);
on_time_rl1=on_time1_rl1+(10*on_time2_rl1)+(100*on_time3_rl1);
on_time_rl2=on_time1_rl2+(10*on_time2_rl2)+(100*on_time3_rl2);
on_time_rl3=on_time1_rl3+(10*on_time2_rl3)+(100*on_time3_rl3);
off_time_rl1=off_time1_rl1+(10*off_time2_rl1)+(100*off_time3_rl1);
off_time_rl1=off_time1_rl2+(10*off_time2_rl2)+(100*off_time3_rl2);
off_time_rl1=off_time1_rl3+(10*off_time2_rl3)+(100*off_time3_rl3);
delay(10);
screen_no=0;
clear_lcd();
write_LCD_line(LINE_1+2,"WELCOME TO");
write_LCD_line(LINE_2+4,"ALLIED ENGG.");
delay(150);
TR1=1;
while(1)
{
if(i1==0 & relay1==1 & relay2==1 & relay3==1) in_1_on_flag=1; else in_1_on_flag=0;
if(i2==0 & relay1==1 & relay2==1 & relay3==1) in_2_on_flag=1; else in_2_on_flag=0;
if(i3==0 & relay1==1 & relay2==1 & relay3==1) in_3_on_flag=1; else in_3_on_flag=0;
if(i1==1)
{
in_1_off_flag=1;
in_1_on_flag=0;
t_i1_on=0;
} else{ in_1_off_flag=0; t_i1_off=0; }
if(i2==1)
{
in_2_off_flag=1;
in_2_on_flag=0;
t_i2_on=0;
} else{ in_2_off_flag=0; t_i2_off=0;}
if(i3==1)
{
in_3_off_flag=1;
in_3_on_flag=0;
t_i3_on=0;
} else{ in_3_off_flag=0; t_i3_off=0;}
if(t_i1_on>=on_time_rl1)
{
relay1=0;
in_1_on_flag=0;
t_i1_on=0;
in_1_off_flag=0;
t_i1_off=0;
}
if(t_i2_on>=on_time_rl2)
{
relay2=0;
in_2_on_flag=0;
t_i2_on=0;
in_2_off_flag=0;
t_i2_off=0;
}
if(t_i3_on>=on_time_rl3)
{
relay3=0;
in_3_on_flag=0;
t_i3_on=0;
in_3_off_flag=0;
t_i3_off=0;
}
if(t_i1_off>=off_time_rl1 & i1==1)
{
relay1=1;
in_1_off_flag=0;
t_i1_off=0;
}
if(t_i2_off>=off_time_rl2 & i2==1)
{
relay2=1;
in_2_off_flag=0;
t_i2_off=0;
}
if(t_i3_off>=off_time_rl3 & i3==1)
{
relay3=1;
in_3_off_flag=0;
t_i3_off=0;
}
if(P2!=0xff)
key_pressed();
}
} // End of Main routine.
key_pressed()
{
delay(1500);
switch(P2)
{
case 0x7f : // SET key
clear_lcd();
if(screen_no==0)
{
screen_no=1;
write_LCD_line(LINE_1,"I/P 1 ON TIME:");
char_sel=1;
ccc1=on_time1_rl1;
ccc2=on_time2_rl1;
ccc3=on_time3_rl1;
}
else if(screen_no==1)
{
on_time1_rl1=ccc1;
on_time2_rl1=ccc2;
on_time3_rl1=ccc3;
on_time_rl1=on_time1_rl1+(10*on_time2_rl1)+(100*on_time3_rl1);
ee_byte_to_ee(0x0b,on_time1_rl1);delay(10);
ee_byte_to_ee(0x1b,on_time2_rl1);delay(10);
ee_byte_to_ee(0x2b,on_time3_rl1);delay(10);
screen_no=2;
write_LCD_line(LINE_1,"I/P 2 ON TIME:");
char_sel=1;
ccc1=on_time1_rl2;
ccc2=on_time2_rl2;
ccc3=on_time3_rl2;
}
else if(screen_no==2)
{
on_time1_rl2=ccc1;
on_time2_rl2=ccc2;
on_time3_rl2=ccc3;
on_time_rl2=on_time1_rl2+(10*on_time2_rl2)+(100*on_time3_rl2);
ee_byte_to_ee(0x4b,on_time1_rl2); delay(10);
ee_byte_to_ee(0x5b,on_time2_rl2); delay(10);
ee_byte_to_ee(0x6b,on_time3_rl2);delay(10);
screen_no=3;
write_LCD_line(LINE_1,"I/P 3 ON TIME:");
char_sel=1;
ccc1=on_time1_rl3;
ccc2=on_time2_rl3;
ccc3=on_time3_rl3;
}
else if(screen_no==3)
{
on_time1_rl3=ccc1;
on_time2_rl3=ccc2;
on_time3_rl3=ccc3;
on_time_rl3=on_time1_rl3+(10*on_time2_rl3)+(100*on_time3_rl3);
ee_byte_to_ee(0x7b,on_time1_rl3); delay(10);
ee_byte_to_ee(0x8b,on_time2_rl3); delay(10);
ee_byte_to_ee(0x9b,on_time3_rl3); delay(10);
screen_no=4;
write_LCD_line(LINE_1,"I/P 1 OFF TIME:");
char_sel=1;
ccc1=off_time1_rl1;
ccc2=off_time2_rl1;
ccc3=off_time3_rl1;
}
else if(screen_no==4)
{
off_time1_rl1=ccc1;
off_time2_rl1=ccc2;
off_time3_rl1=ccc3;
off_time_rl1=off_time1_rl1+(10*off_time2_rl1)+(100*off_time3_rl1);
ee_byte_to_ee(0xab,off_time1_rl1); delay(10);
ee_byte_to_ee(0xbb,off_time2_rl1); delay(10);
ee_byte_to_ee(0xcb,off_time3_rl1); delay(10);
screen_no=5;
write_LCD_line(LINE_1,"I/P 2 OFF TIME:");
char_sel=1;
ccc1=off_time1_rl2;
ccc2=off_time2_rl2;
ccc3=off_time3_rl2;
}
else if(screen_no==5)
{
off_time1_rl2=ccc1;
off_time2_rl2=ccc2;
off_time3_rl2=ccc3;
off_time_rl2=off_time1_rl2+(10*off_time2_rl2)+(100*off_time3_rl2);
ee_byte_to_ee(0xdb,off_time1_rl2); delay(10);
ee_byte_to_ee(0xeb,off_time2_rl2); delay(10);
ee_byte_to_ee(0x43,off_time3_rl2); delay(10);
screen_no=6;
write_LCD_line(LINE_1,"I/P 3 OFF TIME:");
char_sel=1;
ccc1=off_time1_rl3;
ccc