Shop OBEX P1 Docs P2 Docs Learn Events
mc14489 with 4 digit 7 segments parts of Bruce Reynolds code — Parallax Forums

mc14489 with 4 digit 7 segments parts of Bruce Reynolds code

MarkdahplumberMarkdahplumber Posts: 7
edited 2013-01-28 17:49 in BASIC Stamp
Hello
I like working with this display and can't thank everyone enough who loves to teach how code or projects are done.
When I use parts of Bruce R 's code and try to make a little code of my own with it , sometimes it works and sometimes it doesn't. I am using the stamp 2 nothing great compared to sx - p etc but its just perfect for my needs and since i have 3 of them, i figure well if i can get one to work anyone can! I have a question tho ( one of million) when i code my stamp like in A example below it works awsome and when I could it in B example it doesn't show the display and since I have to pound the books like 100 times in my head to get anywhere with EASY basic code I was wondering why that is or did I invent the impossible?
well take care

mark


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








EN PIN 2 ' Connect to SLED4C enable pin #5
CLK PIN 0 ' Connect to SLED4C clock pin #4
DOUT PIN 1 ' Connect to SLED4C data pin #3
motor PIN 15 ' this pin is connected to a led for similator a motor switch
ele PIN 14 ' this pin is connected to a led for sim heater element
warn PIN 13 ' this pin is connected to a led for sim incase the BS2 is on fire


'Variables
'

X VAR Word ' GP var bruce code
Y VAR Byte ' GP var
b VAR Byte ' Bank #1 controls the colon ":"
D2 VAR Byte ' SLED4C bank #2 digit (right)
D3 VAR Byte ' SLED4C bank #3
D4 VAR Byte ' SLED4C bank #4
D5 VAR Byte ' SLED4C bank #5 digit (left)
CFG VAR Byte ' Holds display configuration value
'

OUTPUT 15 ' my code
OUTPUT 14 ' << it wont work unless make these pins outputs
OUTPUT 13


'Initialization
'

DIRL = 255 'bruce code maybe someday i will figure it out
CFGN CON %11000001


START:
b = 0


GOTO FLASH


Help: ' Display H.E.L.P. while toggling brightness from 100% to 50%
CFG = %11101111 ' Digits 5,3,2,1 special decode, 4 HEX decode
GOSUB Config ' Configure display


' Now write H.E.L.P. to display blinking 50% to 100% brightness
Y = %00000111 ' Setup bit 3 for toggling display brightness
FOR X = 0 TO 4 ' and all DP's ON
EN = 0 ' Enable data input
Y.BIT3 = Y.BIT3 ^ 1' Flip Y.bit3 by XOR-ing with 1 [ 0=DIM, 1=BRIGHT ]
' Y = brightness & DP's 5 4 3 2 :=OFF
SHIFTOUT DOUT, CLK, MSBFIRST, [Y\4, $2\4, $E\4, $5\4, $8\4, $0\4]
EN = 1 ' Transfer data into display registers
PAUSE 40
NEXT
GOTO start


Config:
EN = 0 ' Enable data input
SHIFTOUT DOUT, CLK, MSBFIRST, [CFG] ' Write to display config register
EN = 1
PAUSE 1 ' Transfer data into display registers
RETURN
END
'

' my code and IT WORKS!!!
FLASH: ' this code is to just flash leds wasting power but kinda cool
b = b + 1
motor = 1
ele = 1
warn = 1
PAUSE 20
warn = 0
ele = 0
motor = 0
PAUSE 150
IF b = 2 THEN help
GOTO FLASH ' simple? YES understandable? NO
'


_______________________________________________________________________________________________________________


B example this will make the display not light up at all
' {$STAMP BS2}
' {$PBASIC 2.5}
' example A








EN PIN 2 ' Connect to SLED4C enable pin #5
CLK PIN 0 ' Connect to SLED4C clock pin #4
DOUT PIN 1 ' Connect to SLED4C data pin #3
motor PIN 15 ' this pin is connected to a led for similator a motor switch
ele PIN 14 ' this pin is connected to a led for sim heater element
warn PIN 13 ' this pin is connected to a led for sim incase the BS2 is on fire


'Variables
'

X VAR Word ' GP var bruce code
Y VAR Byte ' GP var
b VAR Byte ' Bank #1 controls the colon ":"
D2 VAR Byte ' SLED4C bank #2 digit (right)
D3 VAR Byte ' SLED4C bank #3
D4 VAR Byte ' SLED4C bank #4
D5 VAR Byte ' SLED4C bank #5 digit (left)
CFG VAR Byte ' Holds display configuration value
'

OUTPUT 15 ' my code
OUTPUT 14 ' << it wont work unless make these pins outputs
OUTPUT 13


'Initialization
'

DIRL = 255 'bruce code maybe someday i will figure it out
CFGN CON %11000001


START:
dont need B= 0 because of the loop for this code
GOTO FLASH


Help: ' Display H.E.L.P. while toggling brightness from 100% to 50%
CFG = %11101111 ' Digits 5,3,2,1 special decode, 4 HEX decode
GOSUB Config ' Configure display


' Now write H.E.L.P. to display blinking 50% to 100% brightness
Y = %00000111 ' Setup bit 3 for toggling display brightness
FOR X = 0 TO 4 ' and all DP's ON
EN = 0 ' Enable data input
Y.BIT3 = Y.BIT3 ^ 1' Flip Y.bit3 by XOR-ing with 1 [ 0=DIM, 1=BRIGHT ]
' Y = brightness & DP's 5 4 3 2 :=OFF
SHIFTOUT DOUT, CLK, MSBFIRST, [Y\4, $2\4, $E\4, $5\4, $8\4, $0\4]
EN = 1 ' Transfer data into display registers
PAUSE 40
NEXT
GOTO start


Config:
EN = 0 ' Enable data input
SHIFTOUT DOUT, CLK, MSBFIRST, [CFG] ' Write to display config register
EN = 1
PAUSE 1 ' Transfer data into display registers
RETURN
END
'

' my code and it wont light the led display to show help it just stays dead
FLASH: ' this code is to just flash leds wasting power but kinda cool
DO UNTIL 2 < this code is changed from b= b + 1
motor = 1
ele = 1
warn = 1
PAUSE 20
warn = 0
ele = 0
motor = 0
PAUSE 150
LOOP and changed the if b = 2 then help
GOTO help

' simple? YES understandable for me? NO
'

Comments

  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-01-25 15:25
    First, you should place your code inside Code Brackets. I am by no means an expert at this, but it seems to me that the code will never hit the GOTO help with the LOOP where it is.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-01-27 15:41
    Better still attach the code so it can be clicked on and load right into the editor with full formatting. ;)
  • MarkdahplumberMarkdahplumber Posts: 7
    edited 2013-01-28 15:40
    well sorry about that when i posted this thread I didn't read the "how to post code" till i already posted it but true makes it way easier. I'm a rookie still learning the awesome BS2 wish i could download more brains tho. One small bit for parallax and one GIANT leap for me when i flash a led from the stamp.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-01-28 16:02
    One small bit for parallax and one GIANT leap for me when i flash a led from the stamp.

    Believe me, We ALL know that feeling!!!! Wait until you get motors to turn and sensors to work!!! Oh, and Welcome to the Forums!!
  • MarkdahplumberMarkdahplumber Posts: 7
    edited 2013-01-28 17:49
    Thanks NWCCTV I think its great that parallax has these chips and I'm actually getting somewhere. Back in 1998 I was using BS2 but never learned much more then PAUSE, IF THEN , HIGH ,LOW so it sat collecting dust and me forgetting most of it ...now I'm trying to get back into coding I must say the BS editor 2.5 so far is amazingly way better to get a hold of so far for me. I don't know if i am supposed to type so much but I have been reading different books and I still don't understand how on the shiftout works on the mc14489 maybe its to big of a question and i need to study more but thought i would ask anyway.

    SHIFTOUT DOUT, CLK, MSBFIRST [ data? ]
    like what does [ ] mean? I know DOUT , CLK, MSBFIRST but do not know the [ ] in the index it shows 4 bit \4 etc but doesn't explain the [ ]
    well thanks in advance
Sign In or Register to comment.