Ga-Retired
New Member
Hi everyone,been trying to work with the Max7219 to drive a simple indoor temperature display which is a 2 digit CC Led display.To keep this post simple and to the point, I'm using modified programming from the great examples from Westaust55 and Martin57. Unfortunately,the Max7219's that I'm using to do the prototyping with are questionable at best,( Gotten off E-Bay) and give varying results,especially when displaying the test mode.I'm well aware of the associated problems with these counterfeits and believe may be the very source of my frustration.With that being said, I ordered a couple from an reputable dealer (Mouser.)While waiting for the Max7219's to arrive, I'd like to post my code for scrutiny to make sure I've got all my bases covered.All comments are welcome and with this being just my 3rd Picaxe project I'm definitely in the learning stages with this chip.
Code:
#Picaxe 08M2
; SYMBOL Definitions
;
; Control signal lines from PICAXE to MAX7219
SYMBOL DIn_7219 = PinC.0
SYMBOL Load_7219 = C.1
SYMBOL Clk_7219 = C.2
SYMBOL DS18B20 = C.4
SYMBOL No_Op = 0
;Registers
SYMBOL Decode = 9
SYMBOL Intens =10
SYMBOL ScanLim =11
SYMBOL ShutDwn =12
SYMBOL Digtest =15
;
; MAX7219 Data Constants
SYMBOL Set_Off = 0
SYMBOL Set_On = 1
SYMBOL blank = 15
SYMBOL Digit0 = 1
SYMBOL Digit1 = 2
SYMBOL No_Digits = 1 ; Scan limit for digits 0 to 1
SYMBOL Dec_Digits = 15 ; decode digits 0 to 1 according to "code B"
SYMBOL Init_Inten = 13 ; 0 (=1/32 PWM on time) to 15 (=31/32 PWM on time)
SYMBOL DigBlank = 15 ; "Code B" value to black a digit
SYMBOL Decimal = 10
SYMBOL On_Off = 12
; Define variables
SYMBOL Temperature= b0
SYMBOL Data_7219 = b2
SYMBOL Register = b1
SYMBOL Units = b3
Symbol Tens = b4
;
;
;===============================================
; Initialise the PICAXE Pins for communication with the MAX7219
;===============================================
Init:
DirsC= %11100000
LOW Load_7219
LOW Clk_7219
din_7219= 0
;===============================================
; Main Program loop
;===============================================
Main:
Do
GOSUB Initialise7219
GOSUB Displaytest
'
GOSUB Aquiretemp
Pause 1000
Loop
;===============================================
; Subroutines
;===============================================
; Subroutine to initialise the MAX7219 7-Seg LED display driver
Initialise7219:
Register = Decode : Data_7219 = Dec_Digits : GOSUB ShiftTo7219
Register = Intens : Data_7219 = Init_Inten : GOSUB ShiftTo7219
Register = ScanLim : Data_7219 = No_Digits : GOSUB ShiftTo7219
Register = ShutDwn : Data_7219 = Set_on : GOSUB ShiftTo7219
Register = Digtest : Data_7219 = set_off : GOSUB ShiftTo7219
Return
; subroutine to send the data for display on the 2 digits to the MAX7219
; leading zero blanking applied when the blanking flag is set to "on"
return
'Subroutine "Displaytest" test all segments of all digits as a test
Displaytest:
register =Digtest:Data_7219=set_on :GOSUB Shiftto7219
pause 5000
register =Digtest:Data_7219=set_off:GOSUB Shiftto7219
pause 1000
Return
; Subroutine to shift the register address and data value out to the MAX7219
; Tests have identified that the MAX7219 incoming data is clocked in through the lsb towards the msb.
; If only one MAX7219 is conencted then the first four significant bits of data can be ignored to
; improve the data transfer speed by 25%
;
ShiftTo7219:
DIn_7219 = bit11: PULSOUT Clk_7219, 1
DIn_7219 = bit10: PULSOUT Clk_7219, 1
DIn_7219 = bit9 : PULSOUT Clk_7219, 1
DIn_7219 = bit8 : PULSOUT Clk_7219, 1
DIn_7219 = bit7 : PULSOUT Clk_7219, 1
DIn_7219 = bit6 : PULSOUT Clk_7219, 1
DIn_7219 = bit5 : PULSOUT Clk_7219, 1
DIn_7219 = bit4 : PULSOUT Clk_7219, 1
DIn_7219 = bit3 : PULSOUT Clk_7219, 1
DIn_7219 = bit2 : PULSOUT Clk_7219, 1
DIn_7219 = bit1 : PULSOUT Clk_7219, 1
DIn_7219 = bit0 : PULSOUT Clk_7219, 1
PULSOUT Load_7219,1
return
AquireTemp:
Readtemp DS18B20,Temperature
Convert:Temperature = Temperature *9/5+32
'send temp data to the 2 digits
Tens=Temperature/10
Units=Temperature//10
If tens=0 then
tens=blank
endif
register = Digit1 : Data_7219 = Tens : GOSUB ShiftTo7219
register = Digit0 : Data_7219 = Units : GOSUB ShiftTo7219
SERTXD (CR, LF, "Temperature ",#Temperature," Degrees F", CR, LF)
pause 1000
goto AquireTemp
Last edited: