Multiplexing 7-Segment


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    May 2010
    Posts
    20

    Default Multiplexing 7-Segment

    Hi guys,

    I'm currently creating a project to learn with and it's all working except for one small thing. It uses 3 7-segment displays to basically create a counter that increases on an interrupt using a PIC16F685. I am using interrupt code from another forum post, could have been on here so I don't really understand it just yet. The rest of the code is my own as I have fiddled with multiplexing before. Here is the code I will post the problem after:

    Code:
    define OSC 4
    'LEDTOP         -->     PORTC.0
    'LEDTOPLEFT     -->     PORTC.1         
    'LEDTOPRIGHT    -->     PORTC.2      
    'LEDMIDDLE      -->     PORTC.3          
     
    'LEDBOTTOMRIGHT -->     PORTC.4
    'LEDBOTTOM      -->     PORTC.5
    'LEDBOTTOMLEFT  -->     PORTC.6
    'SEG1 --> PORTB.7
    'SEG2 --> PORTB.5
    'SEG3 --> PORTB.6
    TRISA = %11111111       
    TRISB = %00000000
    TRISC = %00000000
    ADCON1=%00000111
    ANSELH=0
    ANSEL=0
    CM1CON0=0
    CM2CON0=0
    num VAR WORD
    var1 VAR WORD
    var2 VAR WORD
    var3 VAR WORD
    num=0
    DisArray var byte[10]
    DisArray(0) = %01110111
    DisArray(1) = %01000010
    DisArray(2) = %01101101
    DisArray(3) = %00111101
    DisArray(4) = %00011110
    DisArray(5) = %00111011
    DisArray(6) = %01111010
    DisArray(7) = %00010101
    DisArray(8) = %01111111
    DisArray(9) = %00111111
    OPTION_REG = %00111000 
    INTCON.2 = 0 
    INTCON.5 = 1 
    TMR0 = $FF
     
    On Interrupt Goto incNum
     
    loop:
        var1 = num DIG 2 
        var2 = num DIG 1 
        var3 = num DIG 0 
     
        GOSUB selseg1
        PORTC = DisArray(var1)
        pause 5
        GOSUB selseg2
        PORTC = DisArray(var2)
        pause 5
        GOSUB selseg3
        PORTC = DisArray(var3)
        pause 3
    goto loop
    disable
    incNum:
    If INTCON.2 = 1 then
     num = num + 1
     endif
     TMR0 = $FF 
     INTCON.2 = 0 
    RETURN
    ENABLE
    Selseg1:
         portb = %01111111
         RETURN
    Selseg2:
         portb = %11011111
         Return
     
    Selseg3:
         portb = %10111111
         RETURN  
    End
    It is creating a feint shadow of the 3rd segments number on the 1st segment. In other words if I make it display the number "123", it displays the number perfectly clear, but if you look closesly or in a dark room you can see the number "3" over the number "1".

    I have tried fiddling with the delays but I can't get it right. Thanks

    Ross Steytler

  2. #2
    Join Date
    Feb 2005
    Location
    Holmfirth England
    Posts
    116


    Did you find this post helpful? Yes | No

    Default Re: Multiplexing 7-Segment

    Hi,

    I think you need to switch the port b off before going to set the segments, when you enable your port b the segments are briefly set to the previous number.

    Regards
    Bob...

  3. #3
    Join Date
    May 2010
    Posts
    20


    Did you find this post helpful? Yes | No

    Default Re: Multiplexing 7-Segment

    By switching off you mean assigning it %00000000 or in my case %11111111 since it is a common cathode display?

    I tried that out and still nothing, I also tried adding a small pause between selecting the other display and its still creating "shadows". Now that it is dark I see that it is doing it on all 3 segments. All "shadowing" the previous one.

    Thanks for your reply

  4. #4
    Join Date
    Oct 2004
    Posts
    448


    Did you find this post helpful? Yes | No

    Default Re: Multiplexing 7-Segment

    Quote Originally Posted by ross246 View Post
    By switching off you mean assigning it %00000000 or in my case %11111111 since it is a common cathode display?
    For common cathodes, wouldnt you need to assign 0's to the segments to blank them?

  5. #5
    Join Date
    May 2010
    Posts
    20


    Did you find this post helpful? Yes | No

    Default Re: Multiplexing 7-Segment

    Common cathode is common negative or ground so by assigning it 0's your making it negative so switching it on

    EDIT: assigning the cathode itself negative which is connected to portb, by assigning the segments (portc) 0's yea that would blank them.

    Ah by clearing portc which is connected to the segments i have solved the problem thanks so much guys
    Last edited by ross246; - 16th June 2011 at 20:01.

  6. #6
    Join Date
    Feb 2005
    Location
    Holmfirth England
    Posts
    116


    Did you find this post helpful? Yes | No

    Default Re: Multiplexing 7-Segment

    Hi Ross,

    Glad you got it to work. Now you can move on to not displaying any leading zero's.
    Very nice code by the way, much more efficient than what I came up with a few years back.

    Regards
    Bob...

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts