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
my project is to make a 00 to 99 counter using 2 common cathode 7 segments and pic 16f877a the segments are connected to portb the tens digit transistor is connected to RD0 and the ones digit transistor is connected to RD1
the problem is that the tens digit isnt showing but the ones digit is working well , i dont know where is the problem
here is the code
char x,y=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 main()
{
TRISB=0;// PORTB is output
TRISD=0;// PORTD is output
PORTB=0;// initialize PORTB
PORTD=0;// initialize PORTD
for(;{ // ifinite loop
PORTD=1; // transistor on RD0 is enabled and transistor on RD1 is disabled
PORTB=mask; //tens digit
delay_ms(10);// eye delay
PORTD=2; // transistor on RD1 is enabled and transistor on RD0 is disabled
PORTB=mask(x); //ones digit
delay_ms(10); // eye dealy
x++;
if(x==10){x=0;y++;if(y==10)y=0;}
delay_ms(1000);//over all delay between counting
}
}
- - - Updated - - -
here is a picture for the circuit
the problem is that the tens digit isnt showing but the ones digit is working well , i dont know where is the problem
here is the code
char x,y=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 main()
{
TRISB=0;// PORTB is output
TRISD=0;// PORTD is output
PORTB=0;// initialize PORTB
PORTD=0;// initialize PORTD
for(;{ // ifinite loop
PORTD=1; // transistor on RD0 is enabled and transistor on RD1 is disabled
PORTB=mask; //tens digit
delay_ms(10);// eye delay
PORTD=2; // transistor on RD1 is enabled and transistor on RD0 is disabled
PORTB=mask(x); //ones digit
delay_ms(10); // eye dealy
x++;
if(x==10){x=0;y++;if(y==10)y=0;}
delay_ms(1000);//over all delay between counting
}
}
- - - Updated - - -
here is a picture for the circuit