كود:
// LCD module connections
sbit LCD_RS at RB7_bit;
sbit LCD_EN at RB6_bit;
sbit LCD_D4 at Rb5_bit;
sbit LCD_D5 at RB4_bit;
sbit LCD_D6 at RB3_bit;
sbit LCD_D7 at RB2_bit;
sbit LCD_RS_Direction at TRISB7_bit;
sbit LCD_EN_Direction at TRISB6_bit;
sbit LCD_D4_Direction at TRISb5_bit;
sbit LCD_D5_Direction at TRISB4_bit;
sbit LCD_D6_Direction at TRISB3_bit;
sbit LCD_D7_Direction at TRISB2_bit;
void on(){
Lcd_Out(1, 8,"ON");
}
void off(){
Lcd_Out(1, 8,"OFF");
}
int select, select_op, selection, submenu,valide,valide1;
char seg,m,h,dia;
char h1=0,m1=0,x=0,y=0,n=0,j=0,day;
char h2=0,m2=0,h3=0,m3=0,h0=0,m0=0,m5=0,h5=0,m4=0,h4=0,m6=0,h6=0,m7=0,h7=0;
char *text = "00:00:00";
char *text1 = "00:00";
char *text2 = "00:00";
char *text3 = "00:00";
char *text0 = "00:00";
char *text4= "00:00";
char *text5 = "00:00";
char *text6 = "00:00";
char *text7 = "00:00";
unsigned cnt;
char flags = 0;
void eeprom(){
seg = Eeprom_Read(3);
m = Eeprom_Read(2);
h = Eeprom_Read(1);
dia = Eeprom_Read(0);
m0 = Eeprom_Read(5);
h0 = Eeprom_Read(4);
m1 = Eeprom_Read(7);
h1 = Eeprom_Read(6);
m2 = Eeprom_Read(9);
h2 = Eeprom_Read(8);
m3 = Eeprom_Read(11);
h3 = Eeprom_Read(10);
m4 = Eeprom_Read(13);
h4 = Eeprom_Read(12);
m5 = Eeprom_Read(15);
h5 = Eeprom_Read(14);
m6 = Eeprom_Read(17);
h6 = Eeprom_Read(16);
m7 = Eeprom_Read(19);
h7 = Eeprom_Read(18);
} ////////////////////////
void time(){
text[6] = seg/10 + '0';
text[7] = seg%10 + '0';
text[3] = m/10 + '0';
text[4] = m%10 + '0';
text[0] = h/10 + '0';
text[1] = h%10 + '0';
Lcd_Out(1, 7, text);}
void time1(){
text1[3] = m1/10 + '0';
text1[4] = m1%10 + '0';
text1[0] = h1/10 + '0';
text1[1] = h1%10 + '0';
Lcd_Out(2, 6, text1);}
void time2(){
text2[3] = m2/10 + '0';
text2[4] = m2%10 + '0';
text2[0] = h2/10 + '0';
text2[1] = h2%10 + '0';
Lcd_Out(2, 6, text2);}
void time0(){
text0[3] = m0/10 + '0';
text0[4] = m0%10 + '0';
text0[0] = h0/10 + '0';
text0[1] = h0%10 + '0';
Lcd_Out(2, 6, text0);}
void time3(){
text3[3] = m3/10 + '0';
text3[4] = m3%10 + '0';
text3[0] = h3/10 + '0';
text3[1] = h3%10 + '0';
Lcd_Out(2, 6, text3);}
void time4(){
text4[3] = m4/10 + '0';
text4[4] = m4%10 + '0';
text4[0] = h4/10 + '0';
text4[1] = h4%10 + '0';
Lcd_Out(2, 6, text4);}
void time5(){
text5[3] = m5/10 + '0';
text5[4] = m5%10 + '0';
text5[0] = h5/10 + '0';
text5[1] = h5%10 + '0';
Lcd_Out(2, 6, text5);}
void time6(){
text6[3] = m6/10 + '0';
text6[4] = m6%10 + '0';
text6[0] = h6/10 + '0';
text6[1] = h6%10 + '0';
Lcd_Out(2, 6, text6);}
void time7(){
text7[3] = m7/10 + '0';
text7[4] = m7%10 + '0';
text7[0] = h7/10 + '0';
text7[1] = h7%10 + '0';
Lcd_Out(2, 6, text7);}
void relay(){
while(x==1){Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1, 2,"EVE1");
Lcd_Out(2, 2,"EVE2");
Lcd_Out(1,10,"EVE3");
Lcd_Out(2,10,"EVE4");
select = 1;
selection = 1;x=2;
while (x==2){
if (PORTc.f7 == 1) //When press RC0 '>' selecting display options
{
switch(selection)
{
case 1:
Lcd_Chr(1,1,'>');
selection = 2;
select = 1;
Lcd_Chr(2,9,' ');
delay_ms(200);
break;
case 2:
Lcd_Chr(2,1,'>');
selection = 3;
select = 2;
Lcd_Chr(1,1,' ');
delay_ms(200);
break;
case 3:
Lcd_Chr(1,9,'>');
selection = 4;
select = 3;
Lcd_Chr(2,1,' ');
delay_ms(200);
break;
case 4:
Lcd_Chr(2,9,'>');
selection = 1;
select = 4;
Lcd_Chr(1,9,' ');
delay_ms(200);
break;
}
}
if (PORTc.F6 == 1) //When press PORTA.F1 - choose selected option/menu
{
switch(select)
{
case 1:
y=2;x=0;
Lcd_Cmd(_LCD_CLEAR);
on() ;
Lcd_Out(2, 6, text1);
break;
case 2:
y=3;x=0;
Lcd_Cmd(_LCD_CLEAR);
on();
Lcd_Out(2, 6, text2);
break;
case 3:
y=4;x=0;
Lcd_Cmd(_LCD_CLEAR); //Clear LCD screen
on() ;
Lcd_Out(2, 6, text3);
break;
case 4:
y=5;x=0;
Lcd_Cmd(_LCD_CLEAR); //Clear LCD screen
on();
Lcd_Out(2, 6, text0);
break;
}
}
}
}}
void interrupt()
{
TMR0=5;
cnt++;
INTCON.TMR0IF=0;
if(cnt==1000){
cnt = 0;
seg++;
if(seg==60){seg=0;m++;
if(m==60){seg=0;m=0;h++;
if(h==24){seg=0;m=0;h=0;dia++;
if(dia==7){dia=0;
}
}
}
}
}
}
///////////////////////////////////////////////////////////////////////
void main()
{
TRISC =224;
portc=0;
TRISD = 60;
portd=0;
INTCON.GIE = 1;
INTCON.PEIE = 1;
INTCON.TMR0IE = 1;
OPTION_REG = 0b10000010;
TMR0 = 5;
eeprom();
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
while(1)
{
while(y==0){
time();
if(h0==h&& m0==m){portc.f0=1;}
if(h1==h&& m1==m){portc.f1=1;}
if(h2==h&& m2==m){portc.f2=1;}
if(h3==h&& m3==m){portd.f0=1;}
if(h4==h&& m4==m){portc.f1=0;}
if(h5==h&& m5==m){portc.f2=0;}
if(h6==h&& m6==m){portd.f0=0;}
if(h7==h&& m7==m){portc.f0=0;}
if(PORTd.F5) Flags.B0 = 1;
if(PORTd.F4) Flags.B1 = 1;
if(PORTC.F7) Flags.B2 = 1;
if(PORTd.F5==0 && Flags.B0)
{
Flags.B0 = 0;
m++;
if(m>=60) m=0;
Eeprom_Write(2, m);
}
if(PORTd.F4==0 && Flags.B1)
{
Flags.B1 = 0;
h++;
if(h>=24) h=0;
Eeprom_Write(1, h);
}
if(PORTc.F7==0 && Flags.B2)
{
Flags.B2 = 0;
dia++;
if(dia>=7) dia=0;
Eeprom_Write(0, dia);
}
if(portc.f5==1) {y=1;x=1;
}
}
relay();
while(y==2){
if(PORTd.F5==1)
{
delay_ms(200);
m1++;
if(m1>=60) m1=0;
Eeprom_Write(7, m1);
time1();
}
if(PORTd.F4==1)
{
delay_ms(200);
h1++;
if(h1>=24) h1=0;
Eeprom_Write(6, h1);time1();}
if(portc.f5==1){y=6;Lcd_Cmd(_LCD_CLEAR);}
}
while(y==3){
if(PORTd.F5==1)
{
delay_ms(200);
m2++;
if(m2>=60) m2=0;
Eeprom_Write(9, m2);time2();
}
if(PORTd.F4==1)
{
delay_ms(200);
h2++;
if(h2>=24) h2=0;
Eeprom_Write(8, h2);time2();
}
if(portc.f5==1){y=7;Lcd_Cmd(_LCD_CLEAR);}
}
while(y==4){
if(PORTd.F5==1)
{
delay_ms(200);
m3++;
if(m3>=60) m3=0;
Eeprom_Write(11, m3);
time3();
}
if(PORTd.F4==1)
{
delay_ms(200);
h3++;
if(h3>=24) h3=0;
Eeprom_Write(10, h3);time3();
}
if(portc.f5==1) {y=8;Lcd_Cmd(_LCD_CLEAR);}
}
while(y==5){
if(PORTd.F5==1)
{
delay_ms(200);
m0++;
if(m0>=60) m0=0;
Eeprom_Write(5, m0);time0();
}
if(PORTd.F4==1)
{
delay_ms(200);
h0++;
if(h0>=24) h0=0;
Eeprom_Write(4, h0);time0();
}
if(portc.f5==1){y=9;Lcd_Cmd(_LCD_CLEAR);}
}
while(y==6){
off(); Lcd_Out(2, 6, text4);
if(PORTd.F5==1)
{
delay_ms(200);
m4++;
if(m4>=60) m4=0;
Eeprom_Write(13, m4);
time4();
}
if(PORTd.F4==1)
{
delay_ms(200);
h4++;
if(h4>=24) h4=0;
Eeprom_Write(12, h4);time4();
}
if(portc.f6==1) {y=0;Lcd_Cmd(_LCD_CLEAR);}
}
while(y==7){off(); Lcd_Out(2, 6, text5);
if(PORTd.F5==1)
{
delay_ms(200);
m5++;
if(m5>=60) m5=0;
Eeprom_Write(15, m5);
time5();
}
if(PORTd.F4==1)
{
delay_ms(200);
h5++;
if(h5>=24) h5=0;
Eeprom_Write(14, h5);time5();
}
if(portc.f6==1) {y=0;Lcd_Cmd(_LCD_CLEAR);}
}
while(y==8){off(); Lcd_Out(2, 6, text6);
if(PORTd.F5==1)
{
delay_ms(200);
m6++;
if(m6>=60) m6=0;
Eeprom_Write(17, m6);
time6();
}
if(PORTd.F4==1)
{
delay_ms(200);
h6++;
if(h6>=24) h6=0;
Eeprom_Write(16, h6);time6();
}
if(portc.f6==1) {y=0;Lcd_Cmd(_LCD_CLEAR);}
}
while(y==9){off(); Lcd_Out(2, 6, text7);
if(PORTd.F5==1)
{
delay_ms(200);
m7++;
if(m7>=60) m7=0;
Eeprom_Write(17, m7);
time7();
}
if(PORTd.F4==1)
{
delay_ms(200);
h7++;
if(h7>=24) h7=0;
Eeprom_Write(16, h7);time7();
}
if(portc.f6==1) {y=0;Lcd_Cmd(_LCD_CLEAR);}
}
////////////////
////
} }