#picaxe 18X
symbol write.debounce=1000 'Debounce when writing to EEPROM
symbol switch.debounce=100 'Debounce when accepting input from a switch
symbol display.debounce=10 'Debounce when communicating with AXE033
init.LCD: 'Save prewritten messages on AXE033 EEPROM
pause 500
serout 1,N2400,(253,3,"Enter Password: ")
pause write.debounce
serout 1,N2400,(253,1,"T C LL ")
pause write.debounce
serout 1,N2400,(253,2,"Timer= s ")
pause write.debounce
serout 1,N2400,(253,4," INCORRECT ")
pause write.debounce
serout 1,N2400,(253,5," PASSWORD ")
pause write.debounce
serout 1,N2400,(254,1)
pause display.debounce
security:
b0=0 'Initialize variables
b1=0
b2=0
b3=197
b4=0
serout 1,N2400,(253,3) 'Display "Enter Password: " on the LCD
pause display.debounce
for b2=1 to 4 'Initialize the password entry loop
security.underscore:
b3=b3+1
serout 1,N2400,(254,b3,"_") 'Display an entry prompt "_" accounting for LCD cursor position
b3=b3-1
bit5=0 'Reset bit5 (bit 5 adjusts "_" position)
security.entry: 'Entry of password
do
if input6=1 then 'If backspace pressed delete last character
gosub security.back
endif
readadc 2,b1 'Check password input switches
loop while b1<20 'Loop until there is an input
security.selectcase:
select case b2 'Compares input against the correct input, bit marked if input is correct
case 1
if b1>60 AND b1<80 then 'Range provided for relability
bit0=1
endif
case 2
if b1>80 AND b1<100 then
bit1=1
endif
case 3
if b1>100 AND b1<120 then
bit2=1
endif
case 4
if b1>120 AND b1<140 then
bit3=1
endif
endselect
pause switch.debounce
b3=b3+1 'Move the cursor forward by one
serout 1,N2400,(254,b3,"X") 'Display "X" at current cursor position to mark entered character
pause display.debounce
next b2 'End password entry process
do 'Loop waiting for password confirmation using enter
if input6=1 then 'If backspace is pressed mark bit5 to adjust cursor position
bit5=1 'and go back to the password entry phase, from which the user
goto security.entry 'will go straight to the backspace function, as backspace is
endif 'still down
loop while input7=0 'Exit loop when enter is pressed, confirming the password to be checked
if b0=%00001111 then 'Check password against a constant, if all 4 bits were marked password is correct
setint %00000010,%00000010
serout 1,N2400,(254,1) 'Clear the LCD of old now irrelevant text
pause display.debounce
serout 1,N2400,(253,1) 'Display "T C LL " on line one of the LCD
pause display.debounce
serout 1,N2400,(253,2) 'Display "Timer= s " on line two of the LCD
pause display.debounce
goto main
else 'If password is incorrect
high 0 'turn on a red LED
serout 1,N2400,(253,4) 'and display " INCORRECT " on line one of the LCD
pause display.debounce
serout 1,N2400,(253,5) 'with " PASSWORD " on the second line of the LCD
wait 5 'Display this message and keep the red LED on for 5 sec
serout 1,N2400,(254,1) 'After 5 sec clear the LCD
low 0 'and turn the red LED off
goto security 'Reset the character entry process
endif
security.back: 'The backspace password entry character deletion function
if b2>=2 then 'If we are not already at position 1 of the LCD
pause switch.debounce
serout 1,N2400,(254,b3," ") 'Delete everything after the cursor
b3=b3-1 'Move cursor and password entry variables back to accustom
b2=b2-1 'for the character deletion
else
return
endif
if bit5=1 then
goto security.underscore
else
b3=b3+1
serout 1,N2400,(254,b3,"_")
b3=b3-1
goto security.entry
endif
main:
if pin2=1 then
w6=0
endif
readtemp 1,b1
if b1<10 then
serout 1,N2400,(254,131,"00",#b1)
else if b1<100 then
serout 1,N2400,(254,131,"0",#b1)
else
serout 1,N2400,(254,131,#b1)
endif
pause display.debounce
readadc 1,b2
b2=b2*100/255
if b2<10 then
serout 1,N2400,(254,137,"00",#b2)
else if b2<100 then
serout 1,N2400,(254,137,"0",#b2)
else
serout 1,N2400,(254,137,#b2)
endif
pause display.debounce
goto main
interrupt:
inc w6
if w6<10 then
serout 1,N2400,(254,198,"00",#w6)
else if w6<100 then
serout 1,N2400,(254,198,"0",#w6)
else
serout 1,N2400,(254,198,#w6)
endif
pause display.debounce
setint %00000010,%00000010
return