7 Segment Displays
FTFDH
Posts: 2
Does anyone have any examples of driving multiple 7 segment displays using the STAMP? I need to construct a timing display board with 12 characters and was think of using the STAMP with some I2C driver chips...
Comments
I think one of the best chips out there to do just what you want is the MAX7219 chip
It is a driver chip that controls 8 separate seven-segment displays!
This chip is also great for using it with the 5x7 or 8x8 matrix type display boards because you can control 64 separate LEDS with this chip!
Here are a couple of MAX7219 programs I found:
I hope this helps!
Joe
========================================================================
' Program: MAXTest.bs2 (based on MAX7219.B2)
' Author: C. Richardson
' This program runs test patterns and checks specific LED combinations
' for the MAX7219 display controller.
' Hardware interface with the 7219:
DATA_n CON 7 ' Bits are shifted out this pin # to 7219.
CLK CON 5 ' Data valid on rising edge of this clock pin.
Load CON 6 ' Tells 7219 to transfer data to LEDs.
' Register addresses for the MAX7219. To control a given attribute
' of the display, for instance its brightness or the number shown
' in a particular digit, you write the register address followed
' by the data. For example, to set the brightness, you'd send
' 'brite' followed by a number from 0 (off) to 15 (100% bright).
decode CON 9 ' Decode register; a 1 turns on BCD decoding.
brite CON 10 ' "······ "·· " intensity register.
scan CON 11 ' "······ "·· " scan-limit register.
switch CON 12 ' "······ "·· " on/off register.
test CON 15 ' Activates test mode (all digits on, 100% bright)
' Variables used in the program.
max_dat VAR Word ' Word to be sent to MAX7219.
index VAR Nib ' Index into setup table.
scanNumber VAR Nib 'Number of Digits/Rows
temp VAR Byte ' Temporary variable used in outputting digits.
odd VAR index.BIT0 ' Lsb of index.
' The program begins by setting up all pins to output low, matching
' the state established by the pulldown resistors.
OUTS = 0 ' All output latches low.
DIRS = $FFFF ' All pins to output.
··· scanNumber = 0 ' Number of digits/rows...
Main:
·· GOSUB SetupCodeB
·· GOSUB DisplayChar
·· GOSUB SetupNoCode
·· GOSUB DisplayEach
·· GOSUB TestChar
GOTO Main
SetupNoCode:
FOR index = 0 TO 7 ' Retrieve 8 setup bytes from table.
··· LOOKUP index,[noparse][[/noparse]scan,scanNumber,brite,3,decode,$00,switch,1],max_dat 'Get the byte...
··· SHIFTOUT DATA_n,CLK,MSBFIRST,[noparse][[/noparse]max_dat]· 'Send it...
··· IF odd = 0· THEN NoLoad· ' If both bytes have been sent, pulse Load line.
··· PULSOUT Load,1
··· NoLoad: ' Else, don't pulse.
NEXT ' Get next item from table.
RETURN
SetupCodeB:
FOR index = 0 TO 7 ' Retrieve 8 setup bytes from table.
··· LOOKUP index,[noparse][[/noparse]scan,scanNumber,brite,1,decode,$01,switch,1],max_dat 'Get the byte...
··· SHIFTOUT DATA_n,CLK,MSBFIRST,[noparse][[/noparse]max_dat] 'Send it...
··· IF odd = 0· THEN NoLoad2· ' If both bytes have been sent, pulse Load line.
··· PULSOUT Load,1
··· NoLoad2:
NEXT ' Get next item from table.
RETURN
DisplayEach: 'Cycles through all possible led combinations on each row/digit...
FOR index = 1 TO (scanNumber+1)
··· FOR temp = 1 TO 255
······· SHIFTOUT DATA_n,CLK,MSBFIRST,[noparse][[/noparse]index] ' Send the row/digit...
······· SHIFTOUT DATA_n,CLK,MSBFIRST,[noparse][[/noparse]temp] ' ...then send the segment id's.
······· PULSOUT Load,5 ' And load the display.
······· DEBUG "Current Display: "
······· DEBUG DEC index, CR
······· DEBUG "Current Config: "
······· DEBUG DEC temp, CR
······· PAUSE 100
··· NEXT
NEXT
RETURN
DisplayChar: 'Displays all possible CodeB characters...
FOR index = 1 TO (scanNumber+1)
··· FOR temp = 0 TO 16
······· SHIFTOUT DATA_n,CLK,MSBFIRST,[noparse][[/noparse]index] ' Send the row/digit...
······· SHIFTOUT DATA_n,CLK,MSBFIRST,[noparse][[/noparse]temp] ' ...then send the CodeB character ID.
······· PULSOUT Load,5 ' And load the display.
······· DEBUG "Current Display: "
······· DEBUG DEC index, CR
······· DEBUG "Current Character Code: "
······· DEBUG DEC temp, CR
······· PAUSE 100
··· NEXT
NEXT
RETURN
TestChar: 'Displays specific LED segment combinations for testing..
······· SHIFTOUT DATA_n,CLK,MSBFIRST, ' Send the row/digit...
······· SHIFTOUT DATA_n,CLK,MSBFIRST,[noparse][[/noparse]255] ' Enter value to test and see if you've made a specific character...
······· PULSOUT Load,5 ' And load the display.
······· PAUSE 20000 ' Pause for 20 seconds...
RETURN
·==============================================================================
SECOND program!
' Program: MAXTest.bs2 (based on MAX7219.B2)
' Author: C. Richardson
' This program runs test patterns and checks specific LED combinations
' for the MAX7219 display controller.
' Hardware interface with the 7219:
DATA_n CON 7 ' Bits are shifted out this pin # to 7219.
CLK CON 5 ' Data valid on rising edge of this clock pin.
Load CON 6 ' Tells 7219 to transfer data to LEDs.
' Register addresses for the MAX7219. To control a given attribute
' of the display, for instance its brightness or the number shown
' in a particular digit, you write the register address followed
' by the data. For example, to set the brightness, you'd send
' 'brite' followed by a number from 0 (off) to 15 (100% bright).
decode CON 9 ' Decode register; a 1 turns on BCD decoding.
brite CON 10 ' "······ "·· " intensity register.
scan CON 11 ' "······ "·· " scan-limit register.
switch CON 12 ' "······ "·· " on/off register.
test CON 15 ' Activates test mode (all digits on, 100% bright)
' Variables used in the program.
max_dat VAR Word ' Word to be sent to MAX7219.
index VAR Nib ' Index into setup table.
scanNumber VAR Nib 'Number of Digits/Rows
temp VAR Byte ' Temporary variable used in outputting digits.
odd VAR index.BIT0 ' Lsb of index.
' The program begins by setting up all pins to output low, matching
' the state established by the pulldown resistors.
OUTS = 0 ' All output latches low.
DIRS = $FFFF ' All pins to output.
··· scanNumber = 0 ' Number of digits/rows...
Main:
·· GOSUB SetupCodeB
·· GOSUB DisplayChar
·· GOSUB SetupNoCode
·· GOSUB DisplayEach
·· GOSUB TestChar
GOTO Main
SetupNoCode:
FOR index = 0 TO 7 ' Retrieve 8 setup bytes from table.
··· LOOKUP index,[noparse][[/noparse]scan,scanNumber,brite,3,decode,$00,switch,1],max_dat 'Get the byte...
··· SHIFTOUT DATA_n,CLK,MSBFIRST,[noparse][[/noparse]max_dat]· 'Send it...
··· IF odd = 0· THEN NoLoad· ' If both bytes have been sent, pulse Load line.
··· PULSOUT Load,1
··· NoLoad: ' Else, don't pulse.
NEXT ' Get next item from table.
RETURN
SetupCodeB:
FOR index = 0 TO 7 ' Retrieve 8 setup bytes from table.
··· LOOKUP index,[noparse][[/noparse]scan,scanNumber,brite,1,decode,$01,switch,1],max_dat 'Get the byte...
··· SHIFTOUT DATA_n,CLK,MSBFIRST,[noparse][[/noparse]max_dat] 'Send it...
··· IF odd = 0· THEN NoLoad2· ' If both bytes have been sent, pulse Load line.
··· PULSOUT Load,1
··· NoLoad2:
NEXT ' Get next item from table.
RETURN
DisplayEach: 'Cycles through all possible led combinations on each row/digit...
FOR index = 1 TO (scanNumber+1)
··· FOR temp = 1 TO 255
······· SHIFTOUT DATA_n,CLK,MSBFIRST,[noparse][[/noparse]index] ' Send the row/digit...
······· SHIFTOUT DATA_n,CLK,MSBFIRST,[noparse][[/noparse]temp] ' ...then send the segment id's.
······· PULSOUT Load,5 ' And load the display.
······· DEBUG "Current Display: "
······· DEBUG DEC index, CR
······· DEBUG "Current Config: "
······· DEBUG DEC temp, CR
······· PAUSE 100
··· NEXT
NEXT
RETURN
DisplayChar: 'Displays all possible CodeB characters...
FOR index = 1 TO (scanNumber+1)
··· FOR temp = 0 TO 16
······· SHIFTOUT DATA_n,CLK,MSBFIRST,[noparse][[/noparse]index] ' Send the row/digit...
······· SHIFTOUT DATA_n,CLK,MSBFIRST,[noparse][[/noparse]temp] ' ...then send the CodeB character ID.
······· PULSOUT Load,5 ' And load the display.
······· DEBUG "Current Display: "
······· DEBUG DEC index, CR
······· DEBUG "Current Character Code: "
······· DEBUG DEC temp, CR
······· PAUSE 100
··· NEXT
NEXT
RETURN
TestChar: 'Displays specific LED segment combinations for testing..
······· SHIFTOUT DATA_n,CLK,MSBFIRST, ' Send the row/digit...
······· SHIFTOUT DATA_n,CLK,MSBFIRST,[noparse][[/noparse]255] ' Enter value to test and see if you've made a specific character...
······· PULSOUT Load,5 ' And load the display.
······· PAUSE 20000 ' Pause for 20 seconds...
RETURN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
“Intellectual growth should commence at birth and cease only at death”
Albert Einstein
Thanks heaps for that...looks like a winner!
Stuart