Menu

7 segment multiplexing - 16f877a

Help
2008-09-01
2013-05-30
  • Ricardo Lameiro

    Ricardo Lameiro - 2008-09-01

    Hi everyone.

    This is my firs try in GCBasic, so if the question is to newbie/lame please forgive me.

    I want to multiplex 2 7segments displays in just one port, in this case in the PORTB of the pic 16f877a. I know that I have enough pins to do that without multiplexing, but I am in the learning processes so I wanted to do this.

    the problem I have is how can I multiplex  really fast during an amount of time so that i seams that they are on? here is my attempt but the result is not so god, I cant read the diference between the numbers...

    '=================================================
    #chip 16F877A, 4

    #define StartUpDelay 10 ms

    'setting the 7 segment display with 2 displays
    #define displaycount 2

    #define DisplayPortA PORTB
    #define DisplayPortB PORTB

    #define DispselectA set PORTA.1 off set PORTA.2 on
    #define DispselectB set PORTA.1 on set PORTA.2 off

    Startup:
    Wait StartUpDelay
    '===> Timer interrupt example - Enable interrupt
    'Replace with your interrupt requirements
    'On Interrupt Timer1Overflow Call IncCounter

    '================================================================
    '===== MAIN PROGRAM LOOP
    '================================================================
    Main:

    for number = 0 to 9
        for counter = 0 to 2500
            displayvalue 1, number
            wait 1 us
            displayvalue 2, number
            wait 1 us
        next
    next

    Goto Main
    '================================================

    I omitted the ports defines and directions there are a lot off them :)

    please any help is welcome.

     
    • kent_twt4

      kent_twt4 - 2008-09-01

      How about giving the leds more on time?, sorta like 'counter = 1 to 100' and 'wait 5 ms' (Or?).   Don't think the '0' in '0 to 2500' is doing any good.

      When using word size variables, need the statement 'dim counter as word'.

       
    • Ricardo Lameiro

      Ricardo Lameiro - 2008-09-01

      thanks Kent, it worked :)
      but after that I noticed a problem,
      there are some segments missing in some numbers, and it is not a connection problem
      at number 1 the seg - C fails
      at number 2 the seg - D fails
      at number 4 the seg - C fails
      at number 7 the seg - C fails

      all the other numbers work ok, even the zero that has the C and D segments.

      any thoughts on this, library problem?

       
    • kent_twt4

      kent_twt4 - 2008-09-01

      Took a look at 7segment.h in the include\lowlevel folder, and it seems good.

      Check out the note at the top about multiplexing displays on a single port.  Must be some sort of problem there, so try un-commenting your 'DisplaySelectX' there to give you a 'nop' between operations for your port.

       
    • Ricardo Lameiro

      Ricardo Lameiro - 2008-09-02

      I looked at the include file and the lines 'DisplaySelectX' were already uncommented.  will try to know what is wrong. thank you anyway.

       
    • Ricardo Lameiro

      Ricardo Lameiro - 2008-09-03

      I found the problem. I wired the RA1 and RA2 pins bad, Wired the multiplexing wires thinking that the MCLR pin was RA0 - lame... but anyway thank you for the help, GCBASIC rocks!!! :)

       
  • Nobody/Anonymous

    Did not have a colon between the two ports on the displayselect definition.  I am using the b and d ports and the following works for  a counter 0 to 99.

    'Chip model
    #chip 16F877a, 4

    DIR PORTB b'00000000'
    DIR PORTD b'00000000'

    'setting the 7 segment display with 2 displays
    #define displaycount 2

    #define DisplayPortA PORTD
    #define DisplayPortB PORTD

    #define DispselectA set PORTB.0 off: set PORTB.1 on
    #define DispselectB set PORTB.0 on: set PORTB.1 off

    '================================================================
    '===== MAIN PROGRAM LOOP
    '================================================================
    Main:

    for W1 = 0 to 99
    for counter = 0 to 250
    B0 = W1/10
    displayvalue 1, B0
    wait 2 ms
    B1 = W1-(B0*10) ' Remove tens from W1
    displayvalue 2, B1
    wait 2 ms
    next
    next

    Goto Main

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.