Shop OBEX P1 Docs P2 Docs Learn Events
programming two(or more) 7-segment leds with pbasic2.5 — Parallax Forums

programming two(or more) 7-segment leds with pbasic2.5

FarNasFarNas Posts: 3
edited 2005-01-04 23:31 in Learn with BlocklyProp
hi im rather new to basic stamps and their programming, i was working on a project to create a simple clock and i stumbled upon the problem of driving two 7-segment led displays at once, with a pic16c57c. i managed to multiplex them and i think i have the wiring correct, but i cant seem to figure out how to control each digit separately through the code (using pbasic 2.5), i know i must be missing something small and simple, but i cant seem to figure it out. i'd appreciate any help, thanks =).

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-12-30 16:19
    Multiplexing is the process of momentarily selecting one digit (by activating its common line) and placing the segement data for it on the control pins. After a short period, the other digit is activated and its pattern is placed on the outputs.

    You can see how this is done with two dice patterns in the old Parallax application notes for the BS1. StampWorks shows how to do it with 7-segment displays and explains why it's not very practical (in most situations) to do this in PBASIC.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2004-12-31 00:07
    Jon,

    ·· Speaking of multiplexing, in a project you did for the StampWorks kit, you use the MAX7219 with 4 7-seg displays.· Your schematic doesn't show any resistors on the segments of the display, but the projects are all presumably written for the NX-1000 board, so are they assumed to be there?



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Knight Designs
    324 West Main Street
    P.O. Box 97
    Montour Falls, NY 14865
    (607) 535-6777

    Business Page:·· http://www.knightdesigns.com
    Personal Page:··· http://www.lightlink.com/dream/chris
    Designs Page:··· http://www.lightlink.com/dream/designs
    ·
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-12-31 01:20
    Indeed, the resistors are on the board. They're not really required with the MAX7219 because it controls the current through an external resistor. There is also manual multiplexing code in StampWorks to explain the process.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • FarNasFarNas Posts: 3
    edited 2004-12-31 21:39
    well so far im able to get two digits working that are connected onto the same bus, but they both display the same digits ( so far i have them counting 1-9 so i get a count of "11, 22, 33, 44, 55, 66...."). Im using a homework board and the common bus is connected to pins 8-15. i was hoping to get some hints on how to code them to count 1-99, basically im unable to get a number like "12," Assigning the digits values and assigning them different uotputs is easy, i guess im just having trouble seting it up. Im wondering if its necessary to have transistors to turn a digit on or off just using pins 0-7. also, where can i find example programs or perhaps a guide in dealing with 2 or more digits? thanks in advance.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-12-31 21:51
    You must take control of the 7-segment cathodes so that only one is on at a time. What happens is that you turn the on and off (in turn) so fast that the POV (persistance of vision) of your eyes will cause you to see them both on at the same time. If you post your code I will show you how since the hints I've dropped in this thread are not helping you.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • FarNasFarNas Posts: 3
    edited 2005-01-04 20:45
    ok, i think ive figured out how to control the led's seperately, now all i have to do as you said, turn each on on and off quickly with the pause command and it will seem as both are working simultaneously. Its not much yet but heres what i have so far:

    '{$STAMP BS2}
    '{$PBASIC 2.5}

    index VAR Nib

    OUTH = %00000000
    DIRH = %11111111


    FOR B1 = 0 TO 9
    B0 = B1
    GOSUB value
    B0 = index
    HIGH 0

    PAUSE 1000

    NEXT





    ' BAFG.CDE
    value: LOOKUP index, [noparse][[/noparse]%01110011,
    %00100100,
    %00100001,
    %01000011,
    %10000001,
    %10000000,
    %00110011,
    %00000000,
    %00000001,
    %00010000], outh
    return

    DIRH=%00000000

    END



    im using either HIGH 0 or HIGH 1 to tell which digit will be on. but one weird thing happens in this particular count, for displaying the numbers 2,3,4, and 7 (index values are 2, 3, 4, 7 as well) the A segment led stays off for sum reason, so 7 looks like a 1, when in displaying other numbers like 6, the A segment works fine....

    thanks for your help so far, jon.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-01-04 23:31
    You really don't need a PAUSE between showing each digit -- the instruction loading is going to take about 250 us and this is enough time for the LEDs to light up. I've done some experimenting with the SX and LED multiplexing (eight seven segment displays) and I found there was not change in percieved brightness when I was lighting each display for a few microseconds versus a few milliseconds.

    And you really want to break yourself of the habit of using internal variable names; this habit will ultimately lead to bugs that you'll tear your hair out trying to track down.· For example, you've declared a variable called idx and are using B0 in the programming.· What you may not recognize is that (due to the way the compiler works) that idx and B0 occupy the same RAM address.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
Sign In or Register to comment.