MAX7219 instructions can be found here ( multiplex driving LEDs)
KenM
Posts: 657
Note that the code was written for the SX, and therefore comments are preceeded by
a semicolon instead of the BS2 comment· '
;
[noparse][[/noparse]MAX7219 Operation]
;The 7219 must first be initialized. Initialization is done by sending serial
;data to the IC. Four 16 bit values sent will complete the initialization.
The initialization sets
1) decode mode
2) shutdown mode
3) scanlimit
4) intensity
;To send a 16 bit value load (p16 of 7219) is brought LOW, then each of 16 bits (msb 1st) is
;clocked into the IC, and load is then brought HIGH to complete the shifting
;of 16 bits into the device
;For each word sent to the IC, the most significant byte is·an address and the
;lower byte sets the option for each particular function.
;For the descriptions that follow values will be shown as $Xx. The upper case x
;represents the upper nibble of a byte and the value is "don't care" and the lower case
;x represents some actual value
;DECODE MODE - Address $X9
;Options
;· $X0 = No decoding
;··$X1 = Decode digit 0 (BCD)
;··$XF = Decode digits 0-3 (BCD)
;··$FF = Decode digits 0-7 (BCD)
;Sending $09FF sets decode mode for all digits and instructs that the least
;sig nibble is BCD
The basic stamp code to do the above is:
DIRS = $000E············ 'pins 1 2 3 output,all other pins inputs
DOUT PIN 1·············· 'pin 1 of stamp to pin 1 of 7219
Load PIN 2·············· 'pin 2 of stamp to pin 12 of 7219
CLK PIN 3··············· 'pin 3 of stamp to pin 13 of 7219
;in my program there is a call to the subroutine DecodeMode:
DecodeMode:
· LOW Load
· SHIFTOUT DOUT, CLK, MSBFIRST,[noparse][[/noparse]$09FF\16]
· HIGH Load
· RETURN
; next you need to set the shutdown mode to active
;SHUTDOWN MODE - Address $XC
;Options·$X0 = Shutdown
;·$X1 = Normal Operation
;Sending $0C01 sets the IC for normal operation
;The BS2 code to do the above is:
;in my program there is a call to the subroutine ShutDownMode:
ShutDownMode:
· LOW Load
· SHIFTOUT DOUT, CLK, MSBFIRST,[noparse][[/noparse]$0C01\16]
· HIGH Load
· RETURN
;Next you need to tell the 7219 how many digits are to be used.
;SCANLIMIT - Address $XB
;Options·$Xx where the least significant nibble sets the number of digits
;to enable. digit 0, x = 0. digits 0 & 1 x = 1. digits 0, 1, & 2 x = 2
;Sending $0B02 enbables digts 0, 1 & 2
;Sending $0B07 enables all 8 digits
;the BS2 code to do the above is:
;again, this is called with a subroutine
ScanLimit:
· LOW Load
· SHIFTOUT DOUT, CLK, MSBFIRST,[noparse][[/noparse]$0B07\16]
· HIGH Load
· RETURN
;Next set the intensity of the the LED segments
;INTENSITY - Address $XA
;Options·$00 = minimum intensity
;$FF = maximum intensity
;See MAX7219 data sheet for resistor selection and current
;To set "medium" intensity ( I had a 47 k ohm resistor from pin 18 of the 7219 to vcc)
The bs2 code to do this is:
'Set intensity of LEDs
'LSNibble 0 = min intensity and F = max intensity
Intensity:
· LOW Load
· SHIFTOUT DOUT, CLK, MSBFIRST,[noparse][[/noparse]$0A07\16]
· HIGH Load
· RETURN
NOW THE DEVICE IS SET TO USE ALL DIGITS, BCD, MEDIUM INTENSITY.
NOW TO SEND VALUES TO EACH DIGIT
I AM GOING TO SHOW ONLY ONE DIGIT WITH AN EXPLANATION. FROM HERE I
HOPE IT IS CLEAR HOW TO DO THE REST OF THE DIGITS
PRIOR TO THE SEQUENCE OF COMMANDS BELOW, DIGIT 0 WAS INITIALIZED
TO MAKE THE VALUE 0 or 1 or 2 BY....
Dig0 = $0100
'to make digit·zero 1
Dig0 = $0101
'to make digit·zero 2
Dig0 = $0102
'etc
··· LOW Load
··· SHIFTOUT DOUT, CLK, MSBFIRST,[noparse][[/noparse]Dig0\16]
··· HIGH Load
··· PAUSE 40
Attached·is my actual program. I·deleted it from the text portion of the·thread·so the message is not so long.
Post Edited (KenM) : 7/26/2004 1:40:30 PM GMT
a semicolon instead of the BS2 comment· '
;
[noparse][[/noparse]MAX7219 Operation]
;The 7219 must first be initialized. Initialization is done by sending serial
;data to the IC. Four 16 bit values sent will complete the initialization.
The initialization sets
1) decode mode
2) shutdown mode
3) scanlimit
4) intensity
;To send a 16 bit value load (p16 of 7219) is brought LOW, then each of 16 bits (msb 1st) is
;clocked into the IC, and load is then brought HIGH to complete the shifting
;of 16 bits into the device
;For each word sent to the IC, the most significant byte is·an address and the
;lower byte sets the option for each particular function.
;For the descriptions that follow values will be shown as $Xx. The upper case x
;represents the upper nibble of a byte and the value is "don't care" and the lower case
;x represents some actual value
;DECODE MODE - Address $X9
;Options
;· $X0 = No decoding
;··$X1 = Decode digit 0 (BCD)
;··$XF = Decode digits 0-3 (BCD)
;··$FF = Decode digits 0-7 (BCD)
;Sending $09FF sets decode mode for all digits and instructs that the least
;sig nibble is BCD
The basic stamp code to do the above is:
DIRS = $000E············ 'pins 1 2 3 output,all other pins inputs
DOUT PIN 1·············· 'pin 1 of stamp to pin 1 of 7219
Load PIN 2·············· 'pin 2 of stamp to pin 12 of 7219
CLK PIN 3··············· 'pin 3 of stamp to pin 13 of 7219
;in my program there is a call to the subroutine DecodeMode:
DecodeMode:
· LOW Load
· SHIFTOUT DOUT, CLK, MSBFIRST,[noparse][[/noparse]$09FF\16]
· HIGH Load
· RETURN
; next you need to set the shutdown mode to active
;SHUTDOWN MODE - Address $XC
;Options·$X0 = Shutdown
;·$X1 = Normal Operation
;Sending $0C01 sets the IC for normal operation
;The BS2 code to do the above is:
;in my program there is a call to the subroutine ShutDownMode:
ShutDownMode:
· LOW Load
· SHIFTOUT DOUT, CLK, MSBFIRST,[noparse][[/noparse]$0C01\16]
· HIGH Load
· RETURN
;Next you need to tell the 7219 how many digits are to be used.
;SCANLIMIT - Address $XB
;Options·$Xx where the least significant nibble sets the number of digits
;to enable. digit 0, x = 0. digits 0 & 1 x = 1. digits 0, 1, & 2 x = 2
;Sending $0B02 enbables digts 0, 1 & 2
;Sending $0B07 enables all 8 digits
;the BS2 code to do the above is:
;again, this is called with a subroutine
ScanLimit:
· LOW Load
· SHIFTOUT DOUT, CLK, MSBFIRST,[noparse][[/noparse]$0B07\16]
· HIGH Load
· RETURN
;Next set the intensity of the the LED segments
;INTENSITY - Address $XA
;Options·$00 = minimum intensity
;$FF = maximum intensity
;See MAX7219 data sheet for resistor selection and current
;To set "medium" intensity ( I had a 47 k ohm resistor from pin 18 of the 7219 to vcc)
The bs2 code to do this is:
'Set intensity of LEDs
'LSNibble 0 = min intensity and F = max intensity
Intensity:
· LOW Load
· SHIFTOUT DOUT, CLK, MSBFIRST,[noparse][[/noparse]$0A07\16]
· HIGH Load
· RETURN
NOW THE DEVICE IS SET TO USE ALL DIGITS, BCD, MEDIUM INTENSITY.
NOW TO SEND VALUES TO EACH DIGIT
I AM GOING TO SHOW ONLY ONE DIGIT WITH AN EXPLANATION. FROM HERE I
HOPE IT IS CLEAR HOW TO DO THE REST OF THE DIGITS
PRIOR TO THE SEQUENCE OF COMMANDS BELOW, DIGIT 0 WAS INITIALIZED
TO MAKE THE VALUE 0 or 1 or 2 BY....
Dig0 = $0100
'to make digit·zero 1
Dig0 = $0101
'to make digit·zero 2
Dig0 = $0102
'etc
··· LOW Load
··· SHIFTOUT DOUT, CLK, MSBFIRST,[noparse][[/noparse]Dig0\16]
··· HIGH Load
··· PAUSE 40
Attached·is my actual program. I·deleted it from the text portion of the·thread·so the message is not so long.
Post Edited (KenM) : 7/26/2004 1:40:30 PM GMT
bs2
3K