Let's Make Robots!

7 segment display problem

Hey!

So I'm testing my PICkit2 with PIC16F690 to make a 7 segment display work, and it's doing what it should do.

Now I wanted to add a second display, and make the pic count from 0 to 59, and display it on the 2 displays.

The program quite works, but I got a problem with segment c, e, f, and g from the right (unit)display, (connected to respectively RC4, RC2, RC1 and RC0). The problem is that sometimes (not always) that segment just flickers once, and then goes off. If I test the displays seperately (so the left one counts from 0 to 5 quite slow, and the right one from 0 to 9 10 times faster), then it works. but put together, those few segments seem to fail sometimes, and not always on the same numbers. Most of the time it's on 02, 03, 04, 13, and some more further on.

Does anyone have a clue what the problem is?

Thanks in advance,

 

_ZlaTanskY_

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

It would be best to post your code, maybe we can see what's wrong with it.

Oke this is weird.

I've changed my code (the pin connections) a little bit, to make the wiring and the coding easier, I used whole port A (from RA5 to RA0) and 1 pin of portB for display 2 (the tens) and whole port C (RA6 to RA0) for display 1 (the units).

It worked better, only 1 segment wasn't working -> the d-segment of display 2 (tens) which was connected to RA3, the input button on the pickit2. I have no idea why this was, because I declared it to be an output. But I changed that connection from RA3 to one of port B, and now it seems to work...

I don't understand, why can't I use RA3 as an input?

 

Btw here's the code:

#define _LEGACY_HEADERS
#include <htc.h>
#include <math.h>
/*  c7Segment.c - Roll through 60 Digits on 2x7 Segment LED Display

This program will display each of the 60 digits on 2x 7
  Segment Common Cathode LED Display. 

Hardware Notes:

SSD1:
RC6 - Segment a
RC5 - Segment b
RC4 - Segment c
RC3 - Segment d
RC2 - Segment e
RC1 - Segment f
RC0 - Segment g

SSD2:
RB6 - Segment a
RA5 - Segment b
RA4 - Segment c
RB4 - Segment d
RA2 - Segment e
RA1 - Segment f
RA0 - Segment g


*/

__CONFIG(INTIO & WDTDIS & PWRTEN & MCLRDIS & UNPROTECT \
  & UNPROTECT & BORDIS & IESODIS & FCMDIS);


int a,b,c,i, j;

const char LEDDigit[10] = {
//    RRRRRRR - PIC16F690 Pin
//    ACCCCCC
//    5543210
//    abcdefg - LED Segment
    0b1111110,                  //  Digit Zero
    0b0110000,                  //  Digit One
    0b1101101,                  //  Digit Two
    0b1111001,                  //  Digit Three
    0b0110011,                  //  Digit Four
    0b1011011,                  //  Digit Five
    0b1011111,                  //  Digit Six
    0b1110000,                  //  Digit Seven
    0b1111111,                  //  Digit Eight
    0b1111011};                 //  Digit Nine
 
main()
{
   
    PORTA = 0;
    PORTB = 0;
    PORTC = 0;
//    CMCON0 = 7;                 //  Turn off Comparators
    ANSEL = 0;                  //  Turn off ADC
    TRISA = 0;           //  All Bits of PORTA are Outputs
    TRISB = 0;           //  All Bits of PORTB are Outputs
    TRISC = 0;          // All Bits of PORTC are Outputs

    c = 0;                      //  Start at Digit 0

    while(1 == 1)               //  Loop Forever
    {    
        for (i = 0; i < 255; i++)  //  Simple Delay Loop
            for (j = 0; j < 199; j++);
            a = (int)floor(c/10);            // Split the digit into 2 numbers, left and right display
            b = c%10;

            PORTC = LEDDigit[b] & 0x07F;    //     Pass Data Bits to LED Bits
           
            RB6 = LEDDigit[a] >> 6;
            RB4 = LEDDigit[a] << 3 >> 6;
            PORTA = LEDDigit[a] & 0x037;
            
            c = (c + 1) % 60;
    
       
    }
}

Good to see you got it working. The reason RA3 did not work is because it is also MCLR which can only be an input.

Oh I see, just checked the datasheets, didn't know what mclr was so, oke, now I know, thanks ^^

Now on to 4 displays and let's make a clock!

Are you using any kind of current limiting resistors between your 7 segment and your uC?

When you were asking about your protoboard earlier, I had mentioned the resistors --did you install them?

Yes, I'm using 7 resistors of each 470 Ohm for each display.

powering the LEDs through transistors, or, are you driving them right off the pins? Microcontrollers can only supply so much current per pin and they have a limit on how much they can supply over the whole package.

PIC16F690 can handle 200 mA on PORTA,B,C combined. How much current are you running through those 7 segs Zla?

If you limit each segment to 5mA thats 14 x 5 = 70mA well within limit. 1 k resistors on each segment will limit you to 5mA.

I'm not using transistors, connected directly to the pins of the microcontroller.

Also, I'm not sure about the current trough the display segments, because I don't own a multimeter and I have no clue about the resistance of the display, so I can't calculate it either. But I'm using 470 Ohm resistors, perhaps i'll try 1k resistors tomorrow, but I doubt that will be the problem, because the displays are working with all but 2 segments out, and the 'problem' of one or two defecting is for example in the number 13, which only uses 7 segments out of 14, while 08 uses 13 out of 14 segments, and thats working fine.

 

Also I had some trouble regarding pins RB5 and RB6, they weren't working at all. At first I thought it was a soldering problem, but then I touched the pin of the controller instead, with the male connecting cable, and I got no signal whatsoever. But thats 'fixed' by using other ports.