7 Segment 3 Digit Display Problem

Discussion in 'Embedded Systems and Microcontrollers' started by beeson76, Mar 22, 2011.

  1. beeson76

    Thread Starter Member

    Apr 19, 2010
    185
    1
    Hello everyone.

    I am doing just a simple project to connect a 3 digit LED display to a PIC16F690 using the PICKIT 2 development board from Microchip.

    The program just counts up every second. I would first like to stick with the first digit, and when I get to ten jump to the second digit etc.

    I program the chip and on the 3 digit display it counts up, but all digits count instead of just one. I have all three digit pins grounded. I have tried to "shut off" the pins in the program but still to no avail.

    By the way, it is a common cathode display. It is made by Fairchild MST4141C. It is kinda hard to find the datasheet because it looks like Fairchild was bought by Everlight I believe.

    Here is the simple program.

    Code ( (Unknown Language)):
    1.  
    2.  
    3. #include <htc.h>
    4.  
    5. int ones = 0b00010000;
    6. int tens = 0b00100000;
    7. int hundreds = 0b01000000;
    8. int zero = 0b00000000;
    9. int one = 0b00000110;
    10. int two = 0b01011011;
    11. int three = 0b01001111;
    12. int four = 0b01100110;
    13. int five = 0b01101101;
    14. int six = 0b01111100;
    15. int seven = 0b00000111;
    16. int eight = 0b01111111;
    17. int nine = 0b01100111;
    18.  
    19. __CONFIG (INTIO & WDTDIS & MCLRDIS & UNPROTECT);
    20.  
    21. void pause (unsigned short usvalue);
    22.  
    23. main ()
    24. {
    25.  
    26. unsigned char state_led = 0;
    27.  
    28. ANSEL = 0;
    29. ANSELH = 0;
    30. CM1CON0 = 0;
    31. CM2CON0 = 0;
    32.  
    33. PORTB = 0xFF;
    34. PORTC = 0x00;
    35. TRISB = 0x00;
    36. TRISC = 0x00;
    37.  
    38. while (1==1)
    39.  
    40. {
    41.     state_led++;
    42.     switch (state_led)
    43.         {
    44.             case 1:
    45.                 PORTC = ones;
    46.                 PORTB = one;
    47.                 break;
    48.             case 2:
    49.                 PORTC = ones;
    50.                 PORTB = two;
    51.                 break;
    52.             case 3:
    53.                 PORTB = ones;
    54.                 PORTC = three;
    55.                 break;
    56.             case 4:
    57.                 PORTB = ones;
    58.                 PORTC = four;
    59.                 break;
    60.             case 5:
    61.                 PORTB = ones;
    62.                 PORTC = five;
    63.                 break;
    64.             case 6:
    65.                 PORTB = ones;
    66.                 PORTC = six;
    67.                 break;
    68.             case 7:
    69.                 PORTB = ones;
    70.                 PORTC = seven;
    71.                 break;
    72.             case 8:
    73.                 PORTB = ones;
    74.                 PORTC = eight;
    75.                 break;
    76.             case 9:
    77.                 PORTB = ones;
    78.                 PORTC = nine;
    79.                 break;
    80.             default:
    81.                 state_led = 0;
    82.                 PORTC = zero;
    83.                 break;
    84.         }
    85.  
    86.         pause(1000);
    87. }
    88. }
    89.  
    90.  
    Thanks for any help provided.
     
  2. maxloom

    New Member

    Mar 23, 2011
    1
    0
    hello

    You could show him a scheme? I have understood the problem according to you is that the 3 displays light equally
    right?
     
  3. beeson76

    Thread Starter Member

    Apr 19, 2010
    185
    1
    Yes. The datasheet shows that the left digit is digit 1 and the right digit is digit 3. I can get the display to "count" but all three digits count instead of just one digit.

    Some questions:

    To get digit 1 and 2 (Left digit and middle digit) to light, Do I have to "turn on" the digits to make them light or do they light automatically, and I have to turn them off? I know it probably depends on it being Common anode and Common cathode too.
     
  4. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    I found the datasheet. The display has 8 pins for the segments and decimal point and 3 pins for the common cathodes.
    With this display you have to multiplex, I'd recommend an NPN transistor between each common cathode and ground, with the bases connected to 3 PIC pins via resistors.
    Also individual current regulating resistors on all the segment pins.
    You turn each transistor on, one at a time, and output the required pins for segments of that digit. If you do it fast (I'd recommend at least 100Hz) they look like they are all lit.
     
  5. beeson76

    Thread Starter Member

    Apr 19, 2010
    185
    1
    Thanks Markd77. I appreciate very much your reply.

    I have been reading a little about multiplexing and was hoping I wouldnt have to do it. But I guess I have to learn to do it sometime:)

    I will work on getting the circuit put together right, and then I will work on the code.

    If I understand multiplexing right, you alternate so fast that the eye pretty much thinks both are lit. Would I actually alternate between whole digits (all segments) or between individual digit segments?
     
  6. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    You do each whole digit at a time. The eye sees anything that is flashing fast enough as continuous.
     
  7. beeson76

    Thread Starter Member

    Apr 19, 2010
    185
    1
    Thanks again Markd77 for the reply. I am laying out a schematic of it and I will post it here to get your comments, thoughts, and suggestions. Thanks again. I will use as my 3 transistors 2N3904.
     
  8. beeson76

    Thread Starter Member

    Apr 19, 2010
    185
    1
    I know its been awhile but I finally got my Schematic done. I don't yet have values on the current limiting resistors or the resisters tying the Microchip to the Transistors, but I was wanting to go ahead and post it to get ideas/suggestions/critiqueing.

    How does it look so far. I will next try out the programming side of things.

    The schematic is attached in PDF format.

    Thanks for all the help.
     
  9. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Looks good except MCLR should be pulled high (unless you are using it as an input).
    My recomendations:
    Segment resistors calculated to give slightly under 20mA.
    Base resistors calculated to give around 15mA. (Max collector current is 160mA with all segments lit, base current should be about 1/10th that value).
     
  10. nigelwright7557

    Senior Member

    May 10, 2008
    487
    71
    Sounds like your sending out segment data and putting on all 3 cathodes at the same time.
    You need to multiplex the display.
    1's data to segments and only enables 1's cathode.
    Then same for 10's then 100's
     
  11. beeson76

    Thread Starter Member

    Apr 19, 2010
    185
    1
    Thanks for the replies. I made a few changes to the code and just wanted to paste it here. I like keeping all the changes here as I progress so if it can help anyone, it will be posted. Not much has changed in the code. Sorry for not commmenting the code as of yet. I just havent gotten around to it.

    Code ( (Unknown Language)):
    1.  
    2. #include <htc.h>
    3.  
    4. int ones = 0b00010000;
    5. int tens = 0b00100000;
    6. int hundreds = 0b01000000;
    7. int zero = 0b00000000;
    8. int one = 0b00000110;
    9. int two = 0b01011011;
    10. int three = 0b01001111;
    11. int four = 0b01100110;
    12. int five = 0b01101101;
    13. int six = 0b01111100;
    14. int seven = 0b00000111;
    15. int eight = 0b01111111;
    16. int nine = 0b01100111;
    17.  
    18. __CONFIG (INTIO & WDTDIS & MCLRDIS & UNPROTECT);
    19.  
    20. void pause (unsigned short usvalue);
    21.  
    22. main ()
    23. {
    24.  
    25. unsigned char state_led = 0;
    26.  
    27. ANSEL = 0;
    28. ANSELH = 0;
    29. CM1CON0 = 0;
    30. CM2CON0 = 0;
    31.  
    32. PORTB = 0x00;
    33. PORTC = 0x00;
    34. TRISB = 0x00;
    35. TRISC = 0x00;
    36.  
    37. while (1==1)
    38.  
    39. {
    40.     RB4 = 1;
    41.     RB5 = 0;
    42.     RB6 = 0;   
    43.     state_led++;
    44.     switch (state_led)
    45.         {
    46.             case 1:
    47.                 PORTB = ones;
    48.                 PORTC = one;
    49.                 break;
    50.             case 2:
    51.                 PORTB = ones;
    52.                 PORTC = two;
    53.                 break;
    54.             case 3:
    55.                 PORTB = ones;
    56.                 PORTC = three;
    57.                 break;
    58.             case 4:
    59.                 PORTB = ones;
    60.                 PORTC = four;
    61.                 break;
    62.             case 5:
    63.                 PORTB = ones;
    64.                 PORTC = five;
    65.                 break;
    66.             case 6:
    67.                 PORTB = ones;
    68.                 PORTC = six;
    69.                 break;
    70.             case 7:
    71.                 PORTB = ones;
    72.                 PORTC = seven;
    73.                 break;
    74.             case 8:
    75.                 PORTB = ones;
    76.                 PORTC = eight;
    77.                 break;
    78.             case 9:
    79.                 PORTB = ones;
    80.                 PORTC = nine;
    81.                 break;
    82.             default:
    83.                 state_led = 0;
    84.                 PORTC = zero;
    85.                 break;
    86.         }
    87.  
    88.         pause(1000);
    89.  
    90.  
    91. }
    92. }
    93.  
     
  12. beeson76

    Thread Starter Member

    Apr 19, 2010
    185
    1
    Code ( (Unknown Language)):
    1.  
    2. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    3. //
    4. //This program controls a 3 Digit 8 Segment LED Display (7 Segments and . (dot).  
    5. //The objective of this program is to count from 0 to 999 and then restart at 0.  
    6. //The PIC16F886 Microcontroller from Microchip is being used.
    7. //
    8. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    9. #define _LEGACY_HEADERS
    10. #include <htc.h>
    11.  
    12. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    13. ////DEFINE STATEMENTS
    14. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    15.  
    16. #define DelayS(T)       {unsigned char i; for (i = 0; i < T * 10; i++) __delay_ms(100);}    //Delay Macro
    17. #define _XTAL_FREQ              4000000                             //Needs to be set for __delay_ms
    18. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    19.  
    20. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    21. ////CONFIGURATION FUSES (BITS)
    22. ////Master Clear Reset enabled & Internal RC No Clock & Watchdog Timer Disable & Power Up Timer On & Brown Out Reset Disabled &
    23. ////Low Voltage Porgramming Disabled & Code Unprotect
    24. __CONFIG (MCLREN & INTIO & WDTDIS & PWRTEN & BORDIS & LVPDIS & UNPROTECT);
    25. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    26.  
    27. main()
    28. {
    29.  
    30. void pause (unsigned short usvalue);
    31.  
    32. ANSEL = 0;                                          //Initialize A/D Ports off
    33. ANSELH = 0;                                         //Initialize ........
    34. CM1CON0 = 0;                                        //Initialize Comparator 1 off
    35. CM2CON0 = 0;                                        //Initialize Comparator 2 off
    36.  
    37. //OPTION = 0b01010101;                          //OPTION REG
    38.                                                     //xbxxxxx101  1:64
    39.                                                     //xbxxxx0xxx  Prescaler set to Timer0
    40.                                                     //xbxxx1xxxx  (T0SE) set to Increment on high-to-low transition on T0CKI pin
    41.                                                     //xbxx0xxxxx  (T0CS) Internal instruction cycle clock
    42.                                                     //xbx1xxxxxx  (INTEDG) Interrupt on rising edge of INT pin
    43.                                                     //xb0xxxxxxx  (RBPU) PORTB pull-ups are enabled by individual PORT latch values
    44. //RBPU = 0;                                         //Don't think I need this, but to be safe...PORTB Weak Internal Pullups enabled
    45. //WPUB0 = 0;                                            //COL_1 Weak pullup is individually DISABLED--OUTPUT
    46. //WPUB1 = 0;                                            //COL_2 Weak Pullup is inidivdually DISABLED--OUTPUT
    47. //WPUB2 = 0;                                            //Not being used...Weak Pullup is individually DISABLED
    48. //WPUB3 = 1;                                            //ROW_1 Weak Pullup is individually ENABLED--INPUT
    49. //WPUB4 = 1;                                            //ROW_2 Weak Pullup is individually ENABLED--INPUT
    50. //WPUB5 = 1;                                            //ROW_3 Weak Pullup is individually ENABLED--INPUT
    51. //WPUB6 = 1;                                            //ROW_4 Weak Pullup is individually ENABLED--INPUT
    52. //WPUB7 = 0;                                            //COL_3 Weak Pullup is individually DISABLED--INPUT
    53.  
    54. PORTA = 0x00;                                       //PORTA is cleared and set low
    55.                                                     //PORTA:B0 is set to low,low,low,low,low,low,low,low
    56. PORTC = 0x00;                                       //PORTC is cleared and set low
    57.                                                     //PORTC7:C0 is set to low,low,low,low,low,low,low,low
    58. TRISA = 0x00;                                       //PORTA is set to outputs
    59. TRISC = 0x00;                                       //PORTC is set to outputs
    60.  
    61. int ones = 0b00001000;
    62. int tens = 0b00010000;
    63. int hundreds = 0b00100000;
    64. int zero = 0b00000000;
    65. int one = 0b00000110;
    66. int two = 0b01011011;
    67. int three = 0b01001111;
    68. int four = 0b01100110;
    69. int five = 0b01101101;
    70. int six = 0b01111100;
    71. int seven = 0b00000111;
    72. int eight = 0b01111111;
    73. int nine = 0b01100111;
    74.  
    75. unsigned char state_led = 0;
    76.  
    77. while (1==1)
    78.  
    79. {
    80.     RA3 = 1;
    81.     RA4 = 0;
    82.     RA5 = 0;
    83.        
    84.     state_led++;
    85.    
    86.     switch (state_led)
    87.         {
    88.             case 1:
    89.                 PORTA = ones;
    90.                 PORTC = one;
    91.                 break;
    92.             case 2:
    93.                 PORTA = ones;
    94.                 PORTC = two;
    95.                 break;
    96.             case 3:
    97.                 PORTA = ones;
    98.                 PORTC = three;
    99.                 break;
    100.             case 4:
    101.                 PORTA = ones;
    102.                 PORTC = four;
    103.                 break;
    104.             case 5:
    105.                 PORTA = ones;
    106.                 PORTC = five;
    107.                 break;
    108.             case 6:
    109.                 PORTA = ones;
    110.                 PORTC = six;
    111.                 break;
    112.             case 7:
    113.                 PORTA = ones;
    114.                 PORTC = seven;
    115.                 break;
    116.             case 8:
    117.                 PORTA = ones;
    118.                 PORTC = eight;
    119.                 break;
    120.             case 9:
    121.                 PORTA = ones;
    122.                 PORTC = nine;
    123.                 break;
    124.             default:
    125.                 state_led = 0;
    126.                 PORTC = zero;
    127.                 break;
    128.         }
    129.  
    130.         pause(1000);
    131.  
    132.  
    133. }
    134. }
    135.  
    136.  
    Here is my most recent code. I also got the circuit breadboarded and of course it doesnt work.:):)

    If need be I can send a picture of the breadboarded design, but I pretty much followed my schematic.

    Can anyone see anything wrong from the code. I have been messing with it for a couple days now, and I just cant seem to get it to work.
     
  13. beeson76

    Thread Starter Member

    Apr 19, 2010
    185
    1
    Here is the latest schematic with updated Resistor Values.
     
  14. stahta01

    Member

    Jun 9, 2011
    133
    21
    Your master clear circuit is not what I think it should be; I suggest using the 10K as a pull-up instead of a pull-down. And connect the reset switch to ground and MCLR.

    See Figure 14-2 for the recommend circuit for MCLR connection. Note: This one did not have an external reset switch.

    Does your setup do anything?

    Tim S.
     
  15. beeson76

    Thread Starter Member

    Apr 19, 2010
    185
    1
    Thanks stahta01 for the reply. As of right now, its not doing anything, but that is usually common for me on my first try:):)

    Ok, I will use a 10k for the MCLR pin. But when you say pull-up instead of a pull-down, what do you mean. Is that how I initialize the Pin. It being "on" instead of "off" if that is the right terminology.

    Also the figure you refer to. Where is it located at.

    Thanks for the help. I appreciate it.
     
  16. stahta01

    Member

    Jun 9, 2011
    133
    21
    The datasheet says 1K pull-up resistor; so I would use 1K instead of 10K as your schematic showed; but the main thing is when MCLR is low the chip does nothing but reset itself. Please READ the data-sheet; if you do not want to fail.
    Note: Some PICs can turn off the MCLR in software; but this requires the PIC to leave the reset state.
    A pull-up resistor is one that connects to an high (in this case 5 volts).
    A Pull-down resistor is one that connects to a low (in this case, and almost all cases, ground).

    In the PIC datasheet for this chip; I think added the correct link to it.
    http://ww1.microchip.com/downloads/en/DeviceDoc/41291D.pdf


    Tim S.
     
    Last edited: Jul 7, 2011
  17. beeson76

    Thread Starter Member

    Apr 19, 2010
    185
    1
    Thanks stahta01 again. Sorry about the Diagram 14.1. I found out you meant in the Datasheet. I see that now.

    So I must use the Config1 register. I guess I use is something like this:

    CONFIG1 0b0000000000000000;

    ...since its 16 bits wide it looks like. So my resistor should be connected to a high, in my case the 5 volt rail.

    Is this correct.

    Thanks for the help.
     
  18. stahta01

    Member

    Jun 9, 2011
    133
    21
    I have only a slight idea what this post meant. So, I say it is not correct.

    I never set the CONFIG1 value directly.
    I always use the __CONFIG Macro.

    MCLR with an line above it means it is active low; This means a low input results in resetting the MCU. When in reset mode most MCUs do not do anything that is visible to users outside the chip.
    You MUST allow MCLR to raise up to a high value for the MCU to function. The datasheet implies it will work with no connection (it has an internal pull-up resistor, but if your pull-down resistor was too strong(pulled enough current) it would win; but, the preferred circuit is a 1K pull-up with cap connect to ground.

    The size of CONFIG1 has nothing to do with needing a high value on MCLR.

    Tim S.
     
    Last edited: Jul 7, 2011
  19. beeson76

    Thread Starter Member

    Apr 19, 2010
    185
    1
    Ok. I use the __CONFIG bit too. And I have it set (for my MCLR) as:

    __CONFIG (MCLREN & ......

    So it is enabled in my configuration. So from what I understand I shouldnt include it in my configuration. Or should I include it?
     
  20. stahta01

    Member

    Jun 9, 2011
    133
    21
    I am not sure but, this site says
    http://www.micro-examples.com/public/microex-navig/doc/205-faqs.html
    Note: Your chip data-sheet says use a resistor to high instead of tying it to high. Also says your MCLR has an internal pull-up so pulling it high with a resistor is likely not needed (From Table 1-1 on page 17 of data-sheet).

    Note: You need to read data-sheet page 206 note 4; it applies when internal OSC is used and MCLR is low.
    This might keep your circuit from working.
    I suggest YOU DO NOT try to use internal OSC and MCLR as input till you run out of all other inputs.
    It was not clear to me if when MCLR is disabled what would happen from the datasheet; I would guess the input being low would not disable the Internal Osc; but, I am not sure.


    NOTE: I have never used this chip before; all my info is from reading the data-sheet today.

    Tim S.
     
    Last edited: Jul 7, 2011
Loading...