multiplexing code problem

Discussion in 'Embedded Systems and Microcontrollers' started by sayf alawneh, Oct 7, 2014.

  1. sayf alawneh

    Thread Starter New Member

    Aug 4, 2014
    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 (Text):
    2. char x,y=0;
    3. unsigned short mask(unsigned short num){
    4. switch(num){
    5. case 0:return 0x3f;
    6. case 1:return 0x06;
    7. case 2:return 0x5B;
    8. case 3:return 0x4F;
    9. case 4:return 0x66;
    10. case 5:return 0x6D;
    11. case 6:return 0x7D;
    12. case 7:return 0x07;
    13. case 8:return 0x7F;
    14. case 9:return 0x6F;
    15. }
    16. }
    17. void main()
    18. {
    19. TRISB=0;// PORTB is output
    20. TRISD=0;// PORTD is output
    21. PORTB=0;// initialize PORTB
    22. PORTD=0;// initialize PORTD
    23. for(;;){ // ifinite loop
    24. PORTD=1; // transistor on RD0 is enabled and transistor on RD1 is disabled
    25. PORTB=mask(y); //tens digit
    26. delay_ms(10);// eye delay
    27. PORTD=2; // transistor on RD1 is enabled and transistor on RD0 is disabled
    28. PORTB=mask(x); //ones digit
    29. delay_ms(10); // eye dealy
    30. x++;
    31. if(x==10){x=0;y++;if(y==10)y=0;}
    32. delay_ms(1000);//over all delay between counting
    33. }
    34. }
    Last edited by a moderator: Oct 7, 2014
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    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.
    absf likes this.
  3. MrChips


    Oct 2, 2009
    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.
    absf likes this.