BGAmodz
Member
Hello everyone .
I have designed an LCD clock based on PIC16F84A , the program works this way :
I have two buttons , when i click the BT2 , i get LDC binking ( 3 fast blinkings) for 3 times each time is a preparation for a specified setting .
Preparation one : minutes .
Two : hours
three : Days
For example in the first blinking i need to keep the BT1 pressed to adjust minutes before the first blinking ends , if i do nothing in that first linking , i get another blinking , but this second one is for hours .and so on for days .
Now the problem is only in the days settings , when i get the third blinking specifically for day adjustment , i can adjust days but i get weard characters in the seconds right digit , its like when that digit reachs 10 it keeps incrementing and does not get back to zero .
I only got that problem when i used the TMR0 interrupt witch i configured using the OPTION_REG register to have an exact 1 SECOND for the clock .
Here's a picture of the glitch accompanied with program text :
I have designed an LCD clock based on PIC16F84A , the program works this way :
I have two buttons , when i click the BT2 , i get LDC binking ( 3 fast blinkings) for 3 times each time is a preparation for a specified setting .
Preparation one : minutes .
Two : hours
three : Days
For example in the first blinking i need to keep the BT1 pressed to adjust minutes before the first blinking ends , if i do nothing in that first linking , i get another blinking , but this second one is for hours .and so on for days .
Now the problem is only in the days settings , when i get the third blinking specifically for day adjustment , i can adjust days but i get weard characters in the seconds right digit , its like when that digit reachs 10 it keeps incrementing and does not get back to zero .
I only got that problem when i used the TMR0 interrupt witch i configured using the OPTION_REG register to have an exact 1 SECOND for the clock .
Here's a picture of the glitch accompanied with program text :
Code:
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");}
if(j=8){j=1;}
}
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){
//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(100);
}
//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(200);
}
//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++;
delay_ms(1000);
if(j==8){j=1;}
}
r=0;
}
}
}
Last edited: