ledDriver_1_spi(_LED_DRIVER_SHUTDOWN_ADDRESS, _LED_DRIVER_NORMAL_OPERATION);
ledDriver_2_spi(_LED_DRIVER_SHUTDOWN_ADDRESS, _LED_DRIVER_NORMAL_OPERATION);
uint8_t ledDriver_1_spi (uint8_t address, uint8_t dataValue){
//write to first MAX7219
uint8_t result;
PORTB.SS_LED_DRIVER = 0;
result = spi(NO_OP_ADDRESS);
result = spi(NO_OP_ADDRESS);
result = spi(address);
result = spi(dataValue);
PORTB.SS_LED_DRIVER = 1;
return result;
}
uint8_t ledDriver_2_spi (uint8_t address, uint8_t dataValue){
//write to second MAX7219
uint8_t result;
PORTB.SS_LED_DRIVER = 0;
result = spi(address);
result = spi(dataValue);
result = spi(NO_OP_ADDRESS);
result = spi(NO_OP_ADDRESS);
PORTB.SS_LED_DRIVER = 1;
return result;
}
'7 segment multiplexing
'the symbols are the output pin numbers for your PICAXE
symbol load_7219 = 6
symbol din_7219 = 7
symbol clk_7219 = 5
'max7219 registers
symbol decode_mode = $09
symbol intensity = $0A
symbol scan_limit = $0B
symbol shutdown = $0C
symbol digit_test = $0F
start:
'initialize 7219
gosub initialize_7219
'turn on test mode
;b0 is the register
b0 = digit_test
;b1 is the data
b1 = $01
gosub send_data_7219
Main:
goto main
end
initialize_7219:
;b0 is the register
b0 = decode_mode
;b1 is the data
b1 = $FF ' code b decode all digits
gosub send_data_7219
;b0 is the register
b0 = intensity
;b1 is the data
b1 = $0F
gosub send_data_7219
;b0 is the register
b0 = scan_limit
;b1 is the data
b1 = $03
gosub send_data_7219
;b0 is the register
b0 = shutdown
;b1 is the data
b1 = $01
gosub send_data_7219
return
send_data_7219:
'send the data
'set the LOAD line low
low LOAD_7219
'send the register (b0)
pin7 = bit7
pulsout clk_7219, 1
pin7 = bit6
pulsout clk_7219, 1
pin7 = bit5
pulsout clk_7219, 1
pin7 = bit4
pulsout clk_7219, 1
pin7 = bit3
pulsout clk_7219, 1
pin7 = bit2
pulsout clk_7219, 1
pin7 = bit1
pulsout clk_7219, 1
pin7 = bit0
pulsout clk_7219, 1
'send the data (b1)
pin7 = bit15
pulsout clk_7219, 1
pin7 = bit14
pulsout clk_7219, 1
pin7 = bit13
pulsout clk_7219, 1
pin7 = bit12
pulsout clk_7219, 1
pin7 = bit11
pulsout clk_7219, 1
pin7 = bit10
pulsout clk_7219, 1
pin7 = bit9
pulsout clk_7219, 1
pin7 = bit8
pulsout clk_7219, 1
'set the LOAD line high
high load_7219
return
gosub send_data_7219
gosub send_data_7219 //send to the second MAX7219 (via the first one!)
gosub send_data_7219 //send to the first MAX7219
(yes - you can run two 7219s separately with the overhead of having two CS lines from the PICAXE with one going to each. However they are designed to be cascaded to avoid having to do this)... I believe the 17th bit sent will show up as the first bit on the 2nd chip. You could also control the 2nd chip with it's own CS?
ledDriver_1_spi(_LED_DRIVER_SHUTDOWN_ADDRESS, _LED_DRIVER_NORMAL_OPERATION);
ledDriver_2_spi(_LED_DRIVER_SHUTDOWN_ADDRESS, _LED_DRIVER_NORMAL_OPERATION);
ledDriver_1_spi (address, dataValue){
//write to first MAX7219, without affecting the second
CS = 0;
spi(NO_OP_ADDRESS);
spi(NO_OP_ADDRESS);
spi(address);
spi(dataValue);
CS = 1;
}
ledDriver_2_spi (address, dataValue){
//write to second MAX7219, without affecting the first
CS = 0;
spi(address);
spi(dataValue);
spi(NO_OP_ADDRESS);
spi(NO_OP_ADDRESS);
CS = 1;
}
'7 segment multiplexing
'the symbols are the output pin numbers for your PICAXE
symbol load_7219 = 6
symbol din_7219 = 7
symbol clk_7219 = 5
'max7219 registers
symbol decode_mode = $09
symbol intensity = $0A
symbol scan_limit = $0B
symbol shutdown = $0C
symbol digit_test = $0F
start:
'initialize 7219
gosub initialize_7219
'turn on test mode
;b0 is the register
b0 = digit_test
;b1 is the data
b1 = $01
'set the LOAD line low
low load_7219
gosub send_data_7219 '//send to the second MAX7219 (via the first one!)
gosub send_data_7219 '//send to the first MAX7219
'set the LOAD line high
high load_7219
main:
'just wait here
goto main
end
'///////////////////////////////////////
initialize_7219:
;b0 is the register
b0 = decode_mode
;b1 is the data
b1 = $FF ' code b decode all digits
'set the LOAD line low
low load_7219
gosub send_data_7219 '//send to the second MAX7219 (via the first one!)
gosub send_data_7219 '//send to the first MAX7219
'set the LOAD line high
high load_7219
;b0 is the register
b0 = intensity
;b1 is the data
b1 = $0F
'set the LOAD line low
low load_7219
gosub send_data_7219 '//send to the second MAX7219 (via the first one!)
gosub send_data_7219 '//send to the first MAX7219
'set the LOAD line high
high load_7219
;b0 is the register
b0 = scan_limit
;b1 is the data
b1 = $03
'set the LOAD line low
low load_7219
gosub send_data_7219 '//send to the second MAX7219 (via the first one!)
gosub send_data_7219 '//send to the first MAX7219
'set the LOAD line high
high load_7219
;b0 is the register
b0 = shutdown
;b1 is the data
b1 = $01
'set the LOAD line low
low load_7219
gosub send_data_7219 '//send to the second MAX7219 (via the first one!)
gosub send_data_7219 '//send to the first MAX7219
'set the LOAD line high
high load_7219
return
'///////////////////////////////////////
send_data_7219:
'send the data
'send the register (b0)
pin7 = bit7
pulsout clk_7219, 1
pin7 = bit6
pulsout clk_7219, 1
pin7 = bit5
pulsout clk_7219, 1
pin7 = bit4
pulsout clk_7219, 1
pin7 = bit3
pulsout clk_7219, 1
pin7 = bit2
pulsout clk_7219, 1
pin7 = bit1
pulsout clk_7219, 1
pin7 = bit0
pulsout clk_7219, 1
'send the data (b1)
pin7 = bit15
pulsout clk_7219, 1
pin7 = bit14
pulsout clk_7219, 1
pin7 = bit13
pulsout clk_7219, 1
pin7 = bit12
pulsout clk_7219, 1
pin7 = bit11
pulsout clk_7219, 1
pin7 = bit10
pulsout clk_7219, 1
pin7 = bit9
pulsout clk_7219, 1
pin7 = bit8
pulsout clk_7219, 1
return
Set CS low
Send No-Op
Send No-Op
Send address
Send data
Set CS high
Set CS low
Send address
Send data
Send No-Op
Send No-Op
Set CS high
Um, I think we're saying the same thing. From the MAX7219 datasheet:(no - the first 16 bits sent end up in the second chip, the last 16 bits end up in the first chip. Imagine the 7219s are in a pipe - you bits you send go through the first chip and into the second.)
I don't see a constant use of two MAX's for thisFalcon5252 said:I don't understand the constant use of two MAX7219's to run two 4 digit displays
I don't really understand the "why not" bit - that would be the completely standard way of using a MAX7219. It doesn't matter if you have 8x1 displays, 2x4 or 6+2 or whatever - all segments are "in parallel" and the common cathodes are connected to the MAX7219 DIGx pins.Falcon5252 said:Why Not Parallel the segments on two 4 digit displays and multiplex the eight CC digits 0 to 7 the chip is capable of..