multiplexing code problem

Thread Starter

sayf alawneh

Joined Aug 4, 2014
20
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
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(y); //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
}
}
 
Last edited by a moderator:

ErnieM

Joined Apr 24, 2011
8,377
You should add two things: a schematic so we have a clue where you connect things, and code tags so your code is readable.

Then we can really help. :)

(Code tags are hidden under the "Insert" button above the typing window in the "More Options" area.
 

MrChips

Joined Oct 2, 2009
30,707
The problem is in your use of delay_ms(1000).

The tens digit is only on for a very short length of time, while the ones digit is on 100 times longer than the tens digit.
 
Top