Hi All!!!!!!!!!!!
We have a miracle!!!
I know it doesn't mean completion just yet, but......
I have changed the display_time module to 4 seperate digit modules and update each digit in sequence from the main_loop for normal operation.
This has allowed me to update each single digit as the new information is entered via the keypad and then update the rtc once the "Set_Time" key is pressed.
I am currently running on the simulator so that I could follow the code and press the keypad at the appropriate times.
I know that's not real life, but for me, the code is finally working properly and I can get ready for running it on the PicAxe.
Hippy:
I need to put the WaitForNoKeyPressed code back in now that everything is working properly, and I still want to blank the digits and display the input one digit at a time as it goes in from the keypad.
I couldn't wait to share the news that I have so far
The updated version of the code is below in the event that it might help others.
Thanks
Tim
' PicAxe 28x
' Digit Alarm Clock with 16 Key Keypad Interface and
' Max 7219 Display driver and
' DS1307 RTC
'control level outputs
symbol load_7219 = 6
symbol din_7219 = 7
symbol clk_7219 = 5
'data variables
symbol DisplayMinuteUnit = $c0
symbol DisplayMinuteTen = $c1
symbol DisplayHourUnit = $c2
symbol DisplayHourTen = $c3
symbol display_blank = $0F
'max7219 registers
symbol decode_mode = $09
symbol intensity = $0A
symbol scan_limit = $0B
symbol shutdown = $0C
symbol digit_test = $0F
'keypad variables
SYMBOL V_ROW3 = 195
SYMBOL V_ROW2 = 150
SYMBOL V_ROW1 = 105
SYMBOL V_ROW0 = 40
symbol keypress = b8
symbol hourT = b9
symbol hourU = b10
symbol minsT = b11
symbol minsU = b12
rtc initialization
i2cslave %11010000, i2cslow, i2cbyte
pause 100
writei2c 0, ($00, $00, $12, $01, $01, $01, $06, $10)
pause 40
START:
poke DisplayMinuteUnit, display_blank
poke DisplayMinuteTen, display_blank
poke DisplayHourUnit, display_blank
poke DisplayHourTen, display_blank
initialize 7219
GOSUB INITIALIZE_7219
'turn on test mode
b0 = digit_test
b1 = $01
GOSUB SEND_DATA_7219
pause 1000
'turn off test mode
b0 = digit_test
b1 = $00
GOSUB SEND_DATA_7219
'set displays zero
poke DisplayMinuteUnit, 0
poke DisplayMinuteTen, 0
poke DisplayHourUnit, 0
poke DisplayHourTen, 0
END_START:
goto MAIN_LOOP
INITIALIZE_7219:
b0 = decode_mode
b1 = $FF ' code b decode all digits
GOSUB SEND_DATA_7219
b0 = intensity
b1 = $0F
GOSUB SEND_DATA_7219
b0 = scan_limit
b1 = $03
GOSUB SEND_DATA_7219
b0 = shutdown
b1 = $01
GOSUB SEND_DATA_7219
END_INITIALIZE_7219:
return
MAIN_LOOP:
GOSUB READ_RTC
GOSUB DISPLAY_MINS_UNIT
GOSUB DISPLAY_MINS_TENS
GOSUB DISPLAY_HOUR_UNIT
GOSUB DISPLAY_HOUR_TENS
gosub get_new_time
gosub update_rtc
IF keyPress <> $81 THEN MAIN_LOOP
END_MAIN_LOOP:
SEND_DATA_7219:
'send the data
low LOAD_7219
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
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
high load_7219
END_SEND_DATA_7219:
return
READ_RTC:
readi2c 0, (b5, b6, b7)
b3 = b6 & %00001111
poke DisplayMinuteUnit, b3
b3 = b6 / 16
poke DisplayMinuteTen, b3
b3 = b7 & %00001111
poke DisplayHourUnit, b3
b3 = b7 / 16
poke DisplayHourTen, b3
END_READ_RTC:
return
DISPLAY_TIME:
DISPLAY_MINS_UNIT:
peek DisplayMinuteUnit, b1
b0 = $03
gosub send_data_7219
return
DISPLAY_MINS_TENS:
peek DisplayMinuteTen, b1
b0 = $04
gosub send_data_7219
return
DISPLAY_HOUR_UNIT:
peek DisplayHourUnit, b1
b0 = $02
gosub send_data_7219
return
DISPLAY_HOUR_TENS:
peek DisplayHourTen, b1
b0 = $01
gosub send_data_7219
END_DISPLAY_TIME:
return
GET_KEY_PRESS:
b0=12
READADC 3,b1
IF b1 > V_ROW0 THEN FIND_KEY
b0=8
READADC 2,b1
IF b1 > V_ROW0 THEN FIND_KEY
b0=4
READADC 1,b1
IF b1 > V_ROW0 THEN FIND_KEY
b0=0
READADC 0,b1
IF b1 > V_ROW0 THEN FIND_KEY
END_GET_KEY_PRESS:
return
FIND_KEY:
IF b1 < V_ROW1 THEN GOT_KEY_PRESS
b0 = b0+1
IF b1 < V_ROW2 THEN GOT_KEY_PRESS
b0 = b0+1
IF b1 < V_ROW3 THEN GOT_KEY_PRESS
b0 = b0+1
END_FIND_KEY:
GOT_KEY_PRESS:
lookup b0,($00, $07, $04, $01, $00, $08, $05, $02, $0d, $09, $06, $03, $0d, $0c, $0e, $81), keypress
END_GOT_KEY_PRESS:
return
GET_NEW_TIME:
keypress = $80
SET_HOUR_T:
GOSUB GET_KEY_PRESS
IF keyPress = $81 THEN UPDATE_RTC
IF keyPress > 2 THEN SET_HOUR_T
hourT = keypress
POKE DisplayHourTen, keyPress ; 0..2
GOSUB DISPLAY_HOUR_TENS
SET_HOUR_U:
GOSUB GET_KEY_PRESS
IF keyPress = $81 THEN UPDATE_RTC
IF keyPress > 9 THEN SET_HOUR_U
IF hourT = 2 AND keyPress > 3 THEN SET_HOUR_U
hourU = keypress
POKE DisplayHourUnit, keyPress ; 0..9
GOSUB DISPLAY_HOUR_UNIT
SET_MINS_T:
GOSUB GET_KEY_PRESS
IF keyPress = $81 THEN UPDATE_RTC
IF keyPress > 5 THEN SET_MINS_T
minst = keypress
POKE DisplayMinuteTen, keyPress ; 0..5
GOSUB DISPLAY_MINS_TENS
SET_MINS_U:
GOSUB GET_KEY_PRESS
IF keyPress = $81 THEN UPDATE_RTC
IF keyPress > 9 THEN SET_MINS_U
minsU = keypress
POKE DisplayMinuteUnit, keyPress ; 0..9
GOSUB DISPLAY_MINS_UNIT
GOTO SET_HOUR_T ; Keep updating until Set Time key
END_GET_NEW_TIME:
UPDATE_RTC:
b3 = hourT & $000F
b7 = b3 * $10 + hourU
b4 = minsT & $000F
b6 = b4 * $10 + minsU
writei2c 0, (b5,b6,b7) ; Write null--> seconds, then minutes and hours
keypress = 0
GOTO MAIN_LOOP
END_UPDATE_RTC: