Shop OBEX P1 Docs P2 Docs Learn Events
Writing to LED Display — Parallax Forums

Writing to LED Display

NewzedNewzed Posts: 2,503
edited 2004-08-13 03:20 in BASIC Stamp
I have a four digit LED clock display which I drive with two 595s.· One 595
triggers LED segments, the other triggers the cathode via a transistor.

I want to display the time which is generated on the Stamp with a DS1302.· I have a list of constants that says

one con 192
two con 182
and so on.· These cons trigger the segments to display the desired number.

I can solve the problem by writing:

hrs1 var hrs.highnib
hrs2 var hrs.lownib

IF hrs1 = 0 THEN hrs0 = 252··· 'LED displays 0
IF hrs1 = 1 THEN hrs1 = 192··· 'LED displays 1
IF hrs1 = 2 THEN hrs1 = 182

shiftout dat, clk, lsbfirst, [noparse][[/noparse]dig1, hrs1]
and so on for hrs, mins and secs.· This is an awful lot of if/thens.

There must be a better way to do it.confused.gif

Sid

Comments

  • AlWilliamsAWCAlWilliamsAWC Posts: 135
    edited 2004-08-12 13:09
    Why not use LOOKUP:

    Lookup hrs1,[noparse][[/noparse]zero,one,two,three....],led1
    . . .

    (Something like that, its early).

    Regards,

    Al Williams
    AWC
    8 Channels of PWM on a PCB:
    http://www.awce.com/gp6.htm
  • NewzedNewzed Posts: 2,503
    edited 2004-08-12 13:18
    Its not early - the morning is half gone.

    Are you saying:

    lookup hrs1, (252, 192, 182), led1

    lookup hrs2, (252, 192, 182, 230, 202, 110, 122,196, 254, 238). led2

    The numbers are shiftouts to the 595 to display 0, 1, 2, 3, 4 etc.

    Sid
  • AlWilliamsAWCAlWilliamsAWC Posts: 135
    edited 2004-08-12 13:38
    Yeah, why not? You could probably even put it back into the same variable if you are running low. Then just shift out the led1, led2. You could still use your constants in the lookup:

    lookup hrs1,(zero,one,two),hrs1· ' put back into hrs1 ought to work
    lookup hrs2,(zero,one,two,three,four,five,six,seven,eight,nine),hrs2
    shiftout....


    I think that will work. We are an hour behind you Sid, plus I've never been a morning person. Unfortunately, the wife is so that means for the last -- what -- 20 years I have had to be an early riser and go to bed before midnight, but I've never learned to like it in all that time.

    Al Williams
    AWC
    Floating Point for the Stamp or any Microcontroller
    http://www.awce.com/pak12.htm
    ·
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-08-12 13:43
    Al is right, LOOKUP will save a lot of trouble here, especially since you need to send eight bits to each ' 595.

    In past projects I've also used DATA statements to hold segment information; that way I can define them in binary and see which segments are going to be lit for a given value. Something like this:

    Digit0·· DATA·· %00000000·· ' put your segment values here
    Digit1·· DATA·· %00000000
    .
    .
    Digit9·· DATA·· %00000000



    Then....

    Get_Hrs_Segs:
    · READ (Digit0 + hrs.LOWNIB), segs01··· ' get 1's segments
    · READ (Digit0 + hrs.HIGHNIB), segs10·· ' get 10's segments


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office


    Post Edited (Jon Williams) : 8/12/2004 1:46:15 PM GMT
  • AlWilliamsAWCAlWilliamsAWC Posts: 135
    edited 2004-08-12 13:50
    There's no reason·he can't use binary in his CON statements, though. However, your (Jon's) method stores the patterns in program storage EEPROM once. Using the two lookups stores zero, one, and two in two different places, so that's an extra 3 bytes stored. I don't know about the relative efficiency of READ vs LOOKUP. However, if you had lots of digits to do, it might add up to have each "look up table" separate. Always more than one way to skin the cat I suppose.

    Regards,

    Al Williams
    AWC
    Kits
    http://www.awce.com/kits.htm
    ·
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-08-12 13:55
    LOOKUP, in effect, is a table read from EEPROM ... it's just not as spelled out as with my method. There is no speed penalty with my method, and as you point out there is a bit of EE space savings. About the only time I use LOOKUP is when I have a small table that is only used once; if I ever find that I'm putting the same values into two LOOKUP tables they are immediately moved to DATA statements.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • jakjrjakjr Posts: 88
    edited 2004-08-12 17:21
    Newzed said

    Its not early the morning - is half gone.
    My morning just started an hour ago·freaked.gif, but I usually stay up till 3 or 4 at night so I make up for it.

    Anyways, I've got some questions.

    1. whats a 595 and where can I get one?
    2. where did you get your 4 digit display? Online?, Instore?, salvaged from a clock?
    3. whats a DS1302 and where can I get one?
  • NewzedNewzed Posts: 2,503
    edited 2004-08-12 17:44
    73HC595 is a shift register -· Digikey

    DS 1302 is a clock chip - Parallax

    The LEDs are from eric.adams@verizon.net

    Sid
  • KenMKenM Posts: 657
    edited 2004-08-12 19:41
    The 595 is a serial shift register. A typical application is where the device is used to expand the number of output pins of your Stamp.

    Using 3 stamp pins, you have a net gain of 5 pins. But the device can be cascaded. So with 3 stamp pins you can get 8, 16, 24.......additional I/O pins.

    The parallax websight has a good tutorial on using the device with BS2 code to control it.

    Ken
    jakjr said...
    Newzed said

    Its not early the morning - is half gone.
    My morning just started an hour ago·freaked.gif, but I usually stay up till 3 or 4 at night so I make up for it.

    Anyways, I've got some questions.

    1. whats a 595 and where can I get one?
    2. where did you get your 4 digit display? Online?, Instore?, salvaged from a clock?
    3. whats a DS1302 and where can I get one?
  • jakjrjakjr Posts: 88
    edited 2004-08-12 20:02
    Thanks for the info, Ive been looking for something like that. I have a few 7·segment LED displays and was wanting to use 2 (or maybe 3) of them at a time to make a timer, however I couldnt do it due to the lack of I/O pins that would normally be needed.

    Ill have to look for that tutorial you mentioned.
  • NewzedNewzed Posts: 2,503
    edited 2004-08-12 20:08
    You need to wire all the segment pins in parallel, so that sending a signal to "a" goes to all digits.· This is called multiplexing.· Then you put a transistor in the cathode lead of each digit.· The shift register turns on what ever segments you select and you must turn on the digit transistor at the same time so that digit will light.· Turning on the digits must be done at a rate of about 1000 times per second in order for the LEDs not to flicker.· It takes one 595 to turn on the segments and another 595, daisy-chained - to turn on the transistor.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    USB-powered Stamp Board

    http://hometown.aol.com/newzed/index.html
    ·
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-08-12 20:18
    Multiplexing can create a whole bunch of complexity in PBASIC. If not using a devoted multiplexer like the MAX7219 (8 digits), MC14489 (5 digits, not as flexible as the '7219), or the A6276 (16 discrete outputs -- you map your own digits), then I recommend just using one 74HC595 per digit and make sure your power supply can handle the load. In this case, the outputs will drive the segments and each digit cathode will be grounded. Using this scheme you can set-and-forget your display -- you don't have to worry about updating it until you absolutely need to.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office


  • jakjrjakjr Posts: 88
    edited 2004-08-12 20:58
    I'll probobly end up using a max7219 to drive my 7 seg. LED's.
    But im intrerested in using a 595 to expand my stamps·I/O abbilities.
    kenM said...

    The 595 is a serial shift register. A typical application is where the device is used to expand the number of output pins of your Stamp.

    Using 3 stamp pins, you have a net gain of 5 pins. But the device can be cascaded. So with 3 stamp pins you can get 8, 16, 24.......additional I/O pins.

    The parallax websight has a good tutorial on using the device with BS2 code to control it.

    Ken

    Could you tell me where this document is located? I looked around but I couldnt find anything.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-08-12 21:42
    There is a lot of documentation on our web site (StampWorks uses the 595) -- even the help file has code for the '595 (see the example for SHIFTOUT).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • KenMKenM Posts: 657
    edited 2004-08-13 01:36
    http://www.parallax.com/dl/docs/books/sw/exp/sw23b.pdf

    Also, Maxim will send a free sample of the very pricey MAX7219. The datasheet for this device can also be a little intimidating.

    I posted code to control and hopefully a simple to understand explanation on using the MAX7219. In this forum t search on 7219.

    As Jon mentioned, the 595's work really well, "set it and forget it"

    The 7291 is a good alternative if board space is an issue.

    Ken
    jakjr said...
    Thanks for the info, Ive been looking for something like that. I have a few 7·segment LED displays and was wanting to use 2 (or maybe 3) of them at a time to make a timer, however I couldnt do it due to the lack of I/O pins that would normally be needed.

    Ill have to look for that tutorial you mentioned.
  • KenMKenM Posts: 657
    edited 2004-08-13 01:40
    Also, you wrote "jakjr said...
    I'll probobly end up using a max7219 to drive my 7 seg. LED's.
    But im intrerested in using a 595 to expand my stamps·I/O abbilities.
    "

    Just to clarify, the '595 only expands outputs, not inputs· ...."I/O abilities"......

    There is a 74LS299 (I think that is the number" that can be used to expand INPUT and OUTPUTs with one IC, or there are individual ICs to do output (595) or input. I think the 74LS166 does the input expansion. The Stampworks library on the Parallax sight should get you going in that direction.

    Ken
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-08-13 02:12
    For inputs the 74HC165 is a bit easier to use than the 74LS166. Both work though.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • jakjrjakjr Posts: 88
    edited 2004-08-13 03:20
    Thanks for all the info, I just ordered samples of the DS1302 timekeeping chip and the max7219 LED driver.


    Thanks again for all the help, By the way I checked out the stampworks manual and it has lots of good (very helpful) info in it. Only problem is now that I've seen its·manual it makes me want to buy the kit lol.gif.

    Post Edited (jakjr) : 8/19/2004 3:37:46 AM GMT
Sign In or Register to comment.