char s1,s2,m1,m2,h1,h2,p,j;
char t;
bit r;
sbit LCD_RS at RB6_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D7 at RB5_bit;
sbit LCD_D6 at RB4_bit;
sbit LCD_D5 at RB3_bit;
sbit LCD_D4 at RB2_bit;
sbit LCD_RS_Direction at TRISB6_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D7_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB2_bit;
void interrupt()
{
if(intcon.t0if){
t++;}
if(t==15){
s1++ ;
if(s1==58){s1= 48;}
t=0;
}
intcon.t0if=0;
if(intcon.intf){
r=~r;
}
intcon.intf=0;
}
void DisplayD()
{
if(j==1){Lcd_out(1,11,"MON");}
if(j==2){Lcd_out(1,11,"TUE");}
if(j==3){Lcd_out(1,11,"WED");}
if(j==4){Lcd_out(1,11,"THU");}
if(j==5){Lcd_out(1,11,"FRI");}
if(j==6){Lcd_out(1,11,"SAT");}
if(j==7){Lcd_out(1,11,"SUN");}
}
void Display (){
Lcd_chr(1,8,s1);
Lcd_chr(1,7,s2);
Lcd_chr(1,6,p);
Lcd_chr(1,5,m1);
Lcd_chr(1,4,m2);
Lcd_chr(1,3,p );
Lcd_chr(1,2,h1);
Lcd_chr(1,1,h2);
DisplayD();
}
void main() {
INTCON=0xB0;
OPTION_REG=0x17;
TRISB.b0=1;
PORTB.b0=0;
TRISA.b0=1;
PORTA.b0=0;
r=0;
tmr0=0;
Lcd_Init();
Lcd_cmd(_LCD_CURSOR_OFF);
Display ();
s1=s2=m1=m2=h1=h2=48;
p=58;
j=1;
for(;;){
Display ();
if (s1==58){s1=48;s2++;}
if (s2==54){s1=s2=48;m1++;}
if (m1==58){s1=s2=m1=48;m2++;}
if (m2==54){s1=s2=m1=m2=48;h1++;}
if (h1==58){s1=s2=m1=m2=h1=48;h2++;}
if (h1==52&&h2==50){s1=s2=m1=m2=h1=h2=48;j++;}
//CLOCK ADJUST
while(r==1){
INTCON=0x0;
//minutes
Lcd_cmd(_lcd_clear);delay_ms (500);Display (); delay_ms (500);Lcd_cmd(_lcd_clear);delay_ms(500);Display();delay_ms(500);
while(porta.b0==0){
Display();
m1++;
if(m1==58){m1=48;m2++;}
if(m2==54){m1=48;m2=48;}
delay_ms(500);
}
//Hours
Lcd_cmd(_lcd_clear);delay_ms (500);Display (); delay_ms (500);Lcd_cmd(_lcd_clear);delay_ms(500);Display();delay_ms(500);
while(porta.b0==0){
Display();
h1++;
if(h1==58){h1=48;h2++;}
if(h2==50&&h1==52){h1=48;h2=48;}
delay_ms(500);
}
//Days
Lcd_cmd(_lcd_clear);delay_ms (500);Display (); delay_ms (500);Lcd_cmd(_lcd_clear);delay_ms(500);Display();delay_ms(500);
while(porta.b0==0){
Display ();
j++;
if(j==8){j=1;}
delay_ms(500);
}
r=0;
INTCON=0xB0;
}
}
}