LED Maestro
Senior Member
Hi all,
Quick query. I'm making an LED clock, the intricacies I won't be going into here. It uses a PIC28x2, MAX7221 and a DS3234. The 7221 and the 3234 use SPI for comms. My knowledge of this protocol is still in its infancy but I have working code for communicating with both the 3234 and the 7221 separately (The code for the DS3234 was the example by Simmicht on the forum.) The 7221 code was adapted from a source which escapes my mind but it works though its probably crude to everyone here. Am I right in thinking it's using bit-banging?
My question is, I'm obviously using b0,b1,b2 etc for defining the variables but I've noticed that when I try to include the two separate codes together and change the bx values to accommodate, it won't communicate with either one of the chips. is there a way to overcome this? Obviously there is but I need guidance. See codes below.
Any and all help is greatly appreciated. If you need anything clarified then please let me know.
Thanks
DS3234
http://www.picaxeforum.co.uk/showthread.php?18557-DS3234-RTC-Code&highlight=DS3234
MAX7221
Quick query. I'm making an LED clock, the intricacies I won't be going into here. It uses a PIC28x2, MAX7221 and a DS3234. The 7221 and the 3234 use SPI for comms. My knowledge of this protocol is still in its infancy but I have working code for communicating with both the 3234 and the 7221 separately (The code for the DS3234 was the example by Simmicht on the forum.) The 7221 code was adapted from a source which escapes my mind but it works though its probably crude to everyone here. Am I right in thinking it's using bit-banging?
My question is, I'm obviously using b0,b1,b2 etc for defining the variables but I've noticed that when I try to include the two separate codes together and change the bx values to accommodate, it won't communicate with either one of the chips. is there a way to overcome this? Obviously there is but I need guidance. See codes below.
Any and all help is greatly appreciated. If you need anything clarified then please let me know.
Thanks
DS3234
http://www.picaxeforum.co.uk/showthread.php?18557-DS3234-RTC-Code&highlight=DS3234
MAX7221
Code:
#PICAXE28x2
'=======================================================
' MAX7221 PINS
'=======================================================
symbol MOSI = pinB.5 'Pic Pin 26
symbol CS = B.6 'Pic Pin 27
symbol Clk = C.3 'Pic Pin 28
'=======================================================
' MAX7221 Registers
' DO NOT ALTER
'=======================================================
symbol No_Op = 0
symbol Digit0 = 1
symbol Digit1 = 2
symbol Digit2 = 3
symbol Digit3 = 4 'for more digits, dig4 thru dig7 = 5 to 8 respectively
symbol Decode = 9
symbol Intens = 10
symbol ScanLim = 11
symbol ShutDwn = 12
symbol DigTest = 15
'=======================================================
' MAX7221 Register Constants
'=======================================================
symbol Set_Off = 0
symbol Set_On = 1
symbol ScanLimit = 2 'Scan limit for digits 0 to 1 = 2
symbol DecMode = 0
symbol Intensity = 8
'=======================================================
' Variables
'=======================================================
symbol Data_7221 = b0
symbol Register = b1
symbol Tens = b2
symbol Blanking = b3
'=======================================================
' Main Program
'=======================================================
Initialise:
DIRSB = %11100000
LOW CS
LOW clk
MOSI = 0
do
gosub Initialise7221
gosub DisplayTest
Loop
'=======================================================
' Main Subroutines
'=======================================================
Initialise7221:
Register = Decode : data_7221 = DecMode : gosub shiftto7221
Register = Intens : data_7221 = Intensity : gosub shiftto7221
Register = ScanLim : data_7221 = ScanLimit : gosub shiftto7221
Register = ShutDwn : data_7221 = Set_On : gosub shiftto7221
Register = DigTest : data_7221 = Set_Off : gosub shiftto7221
SetDigitDisplay:
if Blanking = Set_On then
Tens = 0
endif
Register = Digit0 : data_7221 = tens : gosub shiftto7221
Register = Digit1 : data_7221 = tens : gosub shiftto7221
return
DisplayTest:
Register = DigTest : data_7221 = Set_On : gosub shiftto7221
pause 2000
Register = DigTest : data_7221 = Set_Off : gosub shiftto7221
pause 1000
return
'=======================================================
' MAX7221 SPI I/O
'=======================================================
shiftto7221:
; pulsout clk, 1 ; bit 15 is don't care - enable if two or more MAX7219 are daisy chained
; pulsout clk, 1 ; bit 14 is don't care
; pulsout clk, 1 ; bit 13 is don't care
; pulsout clk, 1 ; bit 12 is don't care
MOSI = bit11 : pulsout clk, 1
MOSI = bit10 : pulsout clk, 1
MOSI = bit9 : pulsout clk, 1
MOSI = bit8 : pulsout clk, 1
MOSI = bit7 : pulsout clk, 1
MOSI = bit6 : pulsout clk, 1
MOSI = bit5 : pulsout clk, 1
MOSI = bit4 : pulsout clk, 1
MOSI = bit3 : pulsout clk, 1
MOSI = bit2 : pulsout clk, 1
MOSI = bit1 : pulsout clk, 1
MOSI = bit0 : pulsout clk, 1
pulsout CS, 1
return