Shop OBEX P1 Docs P2 Docs Learn Events
A binary programing question... — Parallax Forums

A binary programing question...

DaphylDaphyl Posts: 17
edited 2006-11-08 17:17 in General Discussion
I have created a·scrolling LED·display that uses two 74LS154 (4 x 16 decoder chips).· The hardware works fine.· The problem is with the binary addressing of the four output pins to the demultiplexor.· I can manually set the lines (P1 to P4)·to address the proper output lines on the decoder, but·I'd rather not do that.·I'd rather let the program increment the binary number and set the output pins (P1 to P4) accordingly, but I'm not proficient enough with my programming skills to do this.· Is there a way to·let the program send a binary·number to the four output lines (P1 to P4) so that each of the four lines contains one bit of the four bit number and then the progam will incement the number and reset the pins for the new number?· If I've totally confused you, let me know and I'll try to explain it better.

Thanks,
David···

Comments

  • HobbybotistHobbybotist Posts: 4
    edited 2006-11-07 19:14
    This sounds like a project that I did when I was at ITT.· I made a kind of track and field game.· I had LEDs in a circle.· To get the LEDs to light up around the circle you had to rapidly press a momentary switch.· If I remember the switch was basically the clock for a decade counter.· I'll look for my old notes if this sounds like it will help.



    Ed
  • DaphylDaphyl Posts: 17
    edited 2006-11-07 19:29
    I'd be happy for any info you've got.

    Thanks,

    David
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2006-11-07 19:44
    Hi David, this is one solution

    idx VAR Nib
    idx=1
    DIRA = %1111··· 'Set pins 0 to 3 as outputs
    main:
    OUTA = idx····· 'Switch each output high in turn as you loop through "main"
    idx=idx <<1···· 'Bit shift left......see Pbasic Syntax Guide/Pbasic Operators
    IF idx=0 THEN
    idx=1·········· 'Reload idx with one after output high on pin3
    ENDIF
    PAUSE 750··· 'Pause between outputs
    GOTO main

    NOTE: as it is it uses Pins 0 through 3 not 1 through 4 as you described, is that a problem?

    Jeff T.
  • DaphylDaphyl Posts: 17
    edited 2006-11-07 20:08
    Is this acually going to count in binary to 15 ( 0001, 0010, 0011, 0100, 0101, etc to 1111) with each of the four pins being set as a bit, or is this going to just shift a bit across the four pins setting one pin at a time high (0001, 0010, 0100, 1000)?

    David
  • Beau SchwabeBeau Schwabe Posts: 6,563
    edited 2006-11-07 21:57
    Daphyl,
    I think this is what you are after.· This will produce a binary output on P1 through P4.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
     
    idx VAR Nib
    DIRL = %00011110    'Set pins 1 to 4 as outputs
    main:
    FOR idx = 0 TO 15
        OUTL = idx <<1  'Binary increment pins 1 to 4
        PAUSE 750       'Pause between outputs
    NEXT
    GOTO main
    
    

    Edit:
    If you intended for the binary output to be on pins 0 to 3 instead, then the code below should help you get started
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
     
    StartPin  VAR Nib
    idx       VAR Nib
    PinMask   VAR Word
     
    StartPin = 0                                          'First output pin of 4 contiguous output pins
    PinMask = %1111 << StartPin                           'Create Pin Mask
    DIRS = DIRS | PinMask                                 'Set Selected pins as outputs
    main:
    FOR idx = 0 TO 15
        OUTS = (OUTS -(OUTS & PinMask))+(idx << StartPin) 'Mask data out to selected pins only
        PAUSE 50
    NEXT
    GOTO main
    
    

    ·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 11/8/2006 7:40:59 PM GMT
  • DaphylDaphyl Posts: 17
    edited 2006-11-08 05:44
    Thanks to all,

    I'll try these suggestions and see how they work.· I had designated pin 0 (through an inverter) to be my chip select·0(low)=first 74LS154, and 1(high)=second 74LS154 chip.· The beauty of bread boards is that by moving a couple of wires, I could use pins 0 to 3 or 1 to 4 or just about any thing else.·

    Once again, thank you all!

    David
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2006-11-08 17:17
    Hi David, I have to apologise for my post earlier I misread what you wanted and replied in error, thankfully Beau Schwabe corrected that and put you on the right track. I noticed that you also could see that my snippet was wrong which means that your understanding of binary is better than you might think and Im sure you can grasp it quiet quickly.

    take care

    Jeff T.
Sign In or Register to comment.