sayf alawneh
Junior Member level 3
- Joined
- Aug 15, 2014
- Messages
- 27
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 256
hello guys am doing a 24 hours digital clock consists of 6 multiplexed seven segments CC the problem is in the push buttons
i use 2 push buttons to incease the minutes (m1) and the other to increase the hours (h1)
but they dont obey my code for example when m1 reaches 9 it stops increasing and shows strange numbers the same for h1 given that my code is working fine when i dont use those 2 push buttons
here is my code
i use 2 push buttons to incease the minutes (m1) and the other to increase the hours (h1)
but they dont obey my code for example when m1 reaches 9 it stops increasing and shows strange numbers the same for h1 given that my code is working fine when i dont use those 2 push buttons
here is my code
Code:
char x=0,y=0,s1=0,s2=0,m1=0,m2=0,h1=0,h2=0;
unsigned short mask(unsigned short num){
switch(num){
case 0:return 0x3f;
case 1:return 0x06;
case 2:return 0x5B;
case 3:return 0x4F;
case 4:return 0x66;
case 5:return 0x6D;
case 6:return 0x7D;
case 7:return 0x07;
case 8:return 0x7F;
case 9:return 0x6F;
}
}
void Interrupt(){ //initializing timer 1 interrupt every 5 ms
if (TMR1IF_bit){
TMR1IF_bit = 0;
TMR1H = 0xD8;
TMR1L = 0xF0;
if(y==0){PORTD=1;PORTB=mask(s1);}//s1 and s2 are for seconds
if(y==1){PORTD=2;PORTB=mask(s2);}
if(y==2){PORTD=4;PORTB=mask(m1);}//m1 and m2 are for minutes
if(y==3){PORTD=8;PORTB=mask(m2);}
if(y==4){PORTD=16;PORTB=mask(h1);}h1 and h2 are for hours
if(y==5){PORTD=32;PORTB=mask(h2);}
y++; //increment y every 5 ms (eye delay)
x++;//increment x every 5 ms so when x is 200 we can get a 1 second delay to increment s1 counter
if(y==6)y=0;
if(x==200){s1++;x=0;}
}
}
void main() {
T1CON= 0x01;//
TMR1IF_bit=0;//
TMR1H=0xD8;// <~~~ setting the timer 1 interrupt for 5 ms
TMR1L=0xF0;//
TMR1IE_bit=1;//
INTCON=0xC0;//
PORTB=0;
TRISB=0; // port b as output for the 7 segments
TRISD=0; // port d as output for the transistors
TRISC=255;// port c as input for the switches
for(;;){
if(s1==10){s1=0;s2++;
if(s2==6){s2=0;m1++;
if(m1==10){m1=0;m2++;
if(m2==6){m2=0;h1++;
if(h1==10){h1=0;h2++;
if(h2==2&&h1==4){h2=0;h1=0;m2=0;m1=0;s2=0;s1=0; if the clock is 24 make all digits 0
}}}}}}
if(RC0_BIT==0){m1++;// if the button connected to rc0 is pushed increment 1 for the m1 digit
while(rc0_bit==0){}}// dont increment while the button is pushed
if(RC1_bit==0){h1++;// if the button connected to rc1 is pushed increment 1 for the h1 digit
while(rc0_bit==0){}}// dont increment while the button is pushed
}
}
Last edited by a moderator: