SilentScreamer
Senior Member
Whenever I try to test this code it always skips waiting for a digit to be pressed on the keypad and "makes on up" it seems to change what digit it uses as well (I've used to debug command). Any idea's why?
Here is all the code I've currently written(not finished yet but the password entry is there).
However I think it is something to do with this subroutine
And I forgot to mention, its an alarm with a reprogrammable 4 digit code and LCD display for my GCSE electronics.
Any ideas, the whole thing test correctly in the programming editor (on the simulate mode) but not on a breadboard.
Here is all the code I've currently written(not finished yet but the password entry is there).
Code:
#picaxe 28X1 ' Tell the simulator a PICAXE 28X1 chip is in use
'*****************
'*****Symbols*****
'*****************
'****Variables****
symbol PassEnter_Temp = b0 'The digit currently being entered
symbol Pass_1 = b1 'The first digit of the password
symbol Pass_2 = b2 'The second digit of the password
symbol Pass_3 = b3 'The third digit of the password
symbol Pass_4 = b4 'The fourth digit of the password
symbol Serout_StarPos = b5 'The position that the star needs to be added at
symbol Serout_StarPos192 = b6 'The position that the star needs to be added at +192
symbol Pass_Fail = b7 'If the password entry is incorrect then set this to -1
symbol First_Run = b8 'Is a password setup?
'******Inputs*****
symbol Keypad_Row1 = pin0
symbol Keypad_Row2 = pin1
symbol Keypad_Row3 = pin2
symbol Keypad_Row4 = pin3
symbol PIR_Sensor = pin4
symbol Reed_Switch = pin5
'****Outputs****
symbol Keypad_Column1 = 0
symbol Keypad_Column2 = 1
symbol Keypad_Column3 = 2
symbol LCD_Display = 7
symbol Siren = 6
'******************
'****Procedures****
'******************
'*****Initiate*****
Alarm_Initiate:
'Tell the alarm it is the first time it has been ran
let First_Run = 1
'Set all the outputs to low
let pins = %00000000
'Pause the program to allow the LCD Driver and Display to initiate
pause 500
'Clear the LCD Display
gosub Serout_Clear
'Set the number of Password attempts remaining to 3
let Pass_Fail = 3
goto New_Pass
'*****Standby******
Alarm_Standby_Init:
'Clear the screen and add the message
let pins = %00000000
gosub Serout_Clear 'Clear the screen
gosub Serout_Standby 'Diplay the standby message
goto Alarm_Standby
Alarm_Standby:
low Keypad_Column2
low Keypad_Column3
'Check for *
high Keypad_Column1
if Keypad_Row4 = 1 then goto New_Pass
low Keypad_Column1
'Check for #
high Keypad_Column3
if Keypad_Row4 = 1 then goto Alarm_Active_Init
low Keypad_Column3
goto Alarm_Standby
'***Alarm Active***
Alarm_Active_Init:
'Request the password is entered
gosub Enter_Pass
if Pass_Fail = 0 then goto Alarm_Sound 'If the user mistypes the password 3 times sound the alarm
goto Alarm_Active
Alarm_Active:
goto Alarm_Active
Alarm_Sound:
goto Alarm_Sound
'***New Password***
New_Pass:
if First_Run = 0 then
'Request the exsisting password is entered
gosub Enter_Pass
if Pass_Fail = 0 then goto Alarm_Sound 'If the user mistypes the password 3 times sound the alarm
endif
'Clear the LCD Display and set the text to "New Password"
gosub Serout_Clear
gosub Serout_NewPass
'1st Digit
gosub Charactor_Scan 'Goto the charactor entry sub routine
let Pass_1 = PassEnter_Temp 'Set digit 1
let Serout_StarPos = 0
gosub Serout_Star
'2nd Digit
gosub Charactor_Scan 'Goto the charactor entry sub routine
let Serout_StarPos = 1
let Pass_2 = PassEnter_Temp 'Set digit 2
gosub Serout_Star
'3rd Digit
gosub Charactor_Scan 'Goto the charactor entry sub routine
let Serout_StarPos = 2
let Pass_3 = PassEnter_Temp 'Set digit 3
gosub Serout_Star
'4th Digit
gosub Charactor_Scan 'Goto the charactor entry sub routine
let Serout_StarPos = 3
let Pass_4 = PassEnter_Temp 'Set digit 4
gosub Serout_Star
let First_Run = 0
goto Alarm_Standby_Init
'******************
'**Sub-Procedures**
'******************
'**Enter Password**
Enter_Pass:
if Pass_Fail = 0 then
return 'If all three password attmepts have been used then return
endif
'Clear the LCD Display and set the text to "Enter Password"
gosub Serout_Clear
gosub Serout_EnterPass
'Digit 1
gosub Charactor_Scan 'Scan the keypad
if PassEnter_Temp <> Pass_1 then
let Pass_Fail = Pass_Fail - 1 'Remove a password attempt
goto Enter_Pass
endif
'Show the star on the LCD Display
let Serout_StarPos = 0
gosub Serout_Star
'Digit 2
gosub Charactor_Scan 'Scan the keypad
if PassEnter_Temp <> Pass_2 then
let Pass_Fail = Pass_Fail - 1 'Remove a password attempt
goto Enter_Pass
endif
'Show the star on the LCD Display
let Serout_StarPos = 1
gosub Serout_Star
'Digit 3
gosub Charactor_Scan 'Scan the keypad
if PassEnter_Temp <> Pass_3 then
let Pass_Fail = Pass_Fail - 1 'Remove a password attempt
goto Enter_Pass
endif
'Show the star on the LCD Display
let Serout_StarPos = 2
gosub Serout_Star
'Digit 4
gosub Charactor_Scan 'Scan the keypad
if PassEnter_Temp <> Pass_4 then
let Pass_Fail = Pass_Fail - 1 'Remove a password attempt
goto Enter_Pass
endif
'Show the star on the LCD Display
let Serout_StarPos = 3
gosub Serout_Star
let Pass_Fail = 3 'Set the pass attempts variable to 3
return
'***LCD Messages***
Serout_Clear:
serout LCD_Display,T2400,(254,1) 'Clear the LCD Display
pause 30 'Pause to allow the screen to clear
return
Serout_Standby:
serout LCD_Display,T2400,(254,128,"# - Alarm Arm") 'Set the top row text
pause 30 'Pause to allow the screen to set text
serout LCD_Display,T2400,(254,192,"* - Change Pass") 'Set the top row text
pause 30 'Pause to allow the screen to set text
return
Serout_EnterPass:
serout LCD_Display,T2400,(254,128,"Enter Password:") 'Set the top row text
pause 30 'Pause to allow the screen to set text
return
Serout_NewPass:
serout LCD_Display,T2400,(254,128,"New Password:") 'Set the top row text
pause 30 'Pause to allow the screen to set text
return
Serout_Star:
Serout_StarPos192 = 192 + Serout_StarPos
serout LCD_Display,T2400,(254,Serout_StarPos192,"*") 'Set the bottom row text
pause 1000 'Pause to allow the screen to set text
return
'**Charactor Scan**
Charactor_Scan:
'Check column 1
high Keypad_Column1
low Keypad_Column2
low Keypad_Column3
if Keypad_Row1=1 then
let PassEnter_Temp=1
return
endif
if Keypad_Row2=1 then
let PassEnter_Temp=4
return
endif
if Keypad_Row3=1 then
let PassEnter_Temp=7
return
endif
'Check column 2
low Keypad_Column1
high Keypad_Column2
low Keypad_Column3
if Keypad_Row1=1 then
let PassEnter_Temp=2
return
endif
if Keypad_Row2=1 then
let PassEnter_Temp=5
return
endif
if Keypad_Row3=1 then
let PassEnter_Temp=8
return
endif
if Keypad_Row4=1 then
let PassEnter_Temp=0
return
endif
'Check column 3
low Keypad_Column1
low Keypad_Column2
high Keypad_Column3
if Keypad_Row1=1 then
let PassEnter_Temp=3
return
endif
if Keypad_Row2=1 then
let PassEnter_Temp=6
return
endif
if Keypad_Row3=1 then
let PassEnter_Temp=9
return
endif
low Keypad_Column1
low Keypad_Column2
low Keypad_Column3
goto Charactor_Scan
Code:
'**Charactor Scan**
Charactor_Scan:
'Check column 1
high Keypad_Column1
low Keypad_Column2
low Keypad_Column3
if Keypad_Row1=1 then
let PassEnter_Temp=1
return
endif
if Keypad_Row2=1 then
let PassEnter_Temp=4
return
endif
if Keypad_Row3=1 then
let PassEnter_Temp=7
return
endif
'Check column 2
low Keypad_Column1
high Keypad_Column2
low Keypad_Column3
if Keypad_Row1=1 then
let PassEnter_Temp=2
return
endif
if Keypad_Row2=1 then
let PassEnter_Temp=5
return
endif
if Keypad_Row3=1 then
let PassEnter_Temp=8
return
endif
if Keypad_Row4=1 then
let PassEnter_Temp=0
return
endif
'Check column 3
low Keypad_Column1
low Keypad_Column2
high Keypad_Column3
if Keypad_Row1=1 then
let PassEnter_Temp=3
return
endif
if Keypad_Row2=1 then
let PassEnter_Temp=6
return
endif
if Keypad_Row3=1 then
let PassEnter_Temp=9
return
endif
low Keypad_Column1
low Keypad_Column2
low Keypad_Column3
goto Charactor_Scan
Any ideas, the whole thing test correctly in the programming editor (on the simulate mode) but not on a breadboard.