Password help
· I am trying to store 5 numbers and then poll the keypad for the numbers,· problem is it jumps to password incorrect at the first key press,· i tried and tried,· all i want is a simple password program that can be displayed on the lcd and the keypad enters it,
thanks for all the help so far
[noparse][[/noparse]allen, i know your looking at it]thanks
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[noparse][[/noparse] Declarations ]
'LCD
'Interface
tx················· PIN······· 0······ 'Transmit pin to LCD
Rx················· PIN······· 1······ 'Receive pin from LCD
Baud··············· CON······· 84····· 'Equals baud rate of 9.6k
Int················ CON······· 254···· 'place befor each instruction
'Commands
Auto_Wrap_On······· CON······· 67····· 'See LCD manual for more detail
Auto_Wrap_Off······ CON······· 68····· 'See LCD manual for more detail
Auto_Scroll_On····· CON······· 81····· 'See LCD manual for more detail
Auto_Scroll_Off···· CON······· 82····· 'See LCD manual for more detail
Cursor_pos········· CON······· 71····· 'Needs Column and row
Cur_home··········· CON······· 72····· 'See LCD manual for more detail
Under_Line_On······ CON······· 74····· 'See LCD manual for more detail
Under_Line_Off····· CON······· 75····· 'See LCD manual for more detail
Blinking_On········ CON······· 83····· 'See LCD manual for more detail
Blinking_Off······· CON······· 84····· 'See LCD manual for more detail
Cursor_Left········ CON······· 76····· 'See LCD manual for more detail
Cursor_Right······· CON······· 77····· 'See LCD manual for more detail
Clear_screen······· CON······· 88····· 'See LCD manual for more detail
Contrast··········· CON······· 80····· 'Needs level $00 to $FF
Backlight_On······· CON······· 66····· 'SET $00 = on, minute max $FF
Backlight_Off······ CON······· 70····· ''See LCD manual for more detail
GP_pin_off········· CON······· 86····· 'NEEds $01 to $06 for pin #
GP_pin_on·········· CON······· 87····· 'NEEds $01 to $06 for pin #
'Key pad
Auto_repeat_on····· CON······· 126···· '$00 = resend $01 = key up/down
Auto_repeat_off···· CON······· 96····· 'See LCD manual for more detail
Auto_Trans_On······ CON······· 65····· 'Sends key press data immediately
Auto_Trans_Off····· CON······· 79····· 'STORE 10 key presses until polled
Clear_buffer······· CON······· 69····· 'See LCD manual for more detail
Poll_keypad········ CON······· 38····· 'Polls LCD for last key press
Debounce_time······ CON······· 85····· 'Set in 6.554ms units default 52mS
'Bar graphs
Wide_vert_bar······ CON······· 118···· 'Initialize wide vertical bar
Naro_vert_bar······ CON······· 115···· 'Initialize narrow vertical bar
Draw_vert_bar······ CON······· 61····· 'See LCD manual for more detail
Horz_bar··········· CON······· 104···· 'Initialize horizontal bar
Draw_horz_bar······ CON······· 124···· 'See LCD for more detail
Cusstom_char······· CON······· 78····· 'See LCD for more detail
Large_dig·········· CON······· 110···· 'See LCD for more detail
Place_lrg_dig······ CON······· 35····· 'Column $01/$12 digit $00/$09
'variable declarations
index············· VAR······· Byte(5)
userentry········· VAR······ Byte(5)·· 'key storage variable
·temp············· VAR······· Byte(5)··· 'Working variable
Key················ VAR······· Byte(5)··· 'key storage variable
'data directives
Password··········· DATA··· "33722"
·'initialization routine
GOSUB pa_w
·GOSUB PR_W
PR_W:
· GOSUB cl_s
·· SEROUT Tx,Baud,[noparse][[/noparse]"IT WORKED "]
··· PAUSE 2000
·· END
·Convert:······························ 'Label
····· 'Table to convert variable
····· LOOKDOWN· temp,[noparse][[/noparse]66,67,68,69,71,72,73,74,76,77,78,79,81,82,83,84],temp
····· 'Table to convert variable
······· LOOKUP··· temp,[noparse][[/noparse]"D","#","0","*","C","9","8","7","B","6","5","4","A","3",
·············· "2","1"],temp
······· RETURN································ 'Jump to next line UNDER last gosub
Cl_S:
······· SEROUT Tx,Baud,[noparse][[/noparse]Int,Clear_screen]
······· RETURN
Pa_w:
········· GOSUB CL_S····· 'Clears screen
········· SEROUT Tx,Baud,[noparse][[/noparse]Int,Auto_trans_On]··· 'Turns on transmit for key pad·
'··············· Sets up text on LCD
········· SEROUT Tx,Baud,[noparse][[/noparse]"Enter Password" ]
········· GOSUB W_k
········· GOSUB pr_w
········· RETURN
W_k:
·········· DO
·········· SEROUT Tx,Baud,[noparse][[/noparse]Int,Auto_trans_Off]··· 'Saves ten numbers until polled·
········· SEROUT Tx,Baud,[noparse][[/noparse]Int,Poll_keypad]······ 'Request last key press from LCD
········· SERIN Rx,Baud,[noparse][[/noparse]temp]·················· 'Store key press in temp
········· IF temp = 0 THEN w_k········ 'If no key Press jump to label
·········· FOR index= 0 TO 4
·········· READ password + index, temp
·········· IF temp <> userentry(index) THEN EXIT
········· NEXT
········ IF index <> 5 THEN
········· GOSUB CL_S
········· SEROUT tx,baud,[noparse][[/noparse] "password incorrect" ]
········· PAUSE 1000
········· GOSUB Pa_w
········· ENDIF
········· LOOP UNTIL index=5
········· GOSUB cl_s
········· SEROUT tx,baud,[noparse][[/noparse] "accessed"]
······· RETURN
·
thanks for all the help so far
[noparse][[/noparse]allen, i know your looking at it]thanks
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[noparse][[/noparse] Declarations ]
'LCD
'Interface
tx················· PIN······· 0······ 'Transmit pin to LCD
Rx················· PIN······· 1······ 'Receive pin from LCD
Baud··············· CON······· 84····· 'Equals baud rate of 9.6k
Int················ CON······· 254···· 'place befor each instruction
'Commands
Auto_Wrap_On······· CON······· 67····· 'See LCD manual for more detail
Auto_Wrap_Off······ CON······· 68····· 'See LCD manual for more detail
Auto_Scroll_On····· CON······· 81····· 'See LCD manual for more detail
Auto_Scroll_Off···· CON······· 82····· 'See LCD manual for more detail
Cursor_pos········· CON······· 71····· 'Needs Column and row
Cur_home··········· CON······· 72····· 'See LCD manual for more detail
Under_Line_On······ CON······· 74····· 'See LCD manual for more detail
Under_Line_Off····· CON······· 75····· 'See LCD manual for more detail
Blinking_On········ CON······· 83····· 'See LCD manual for more detail
Blinking_Off······· CON······· 84····· 'See LCD manual for more detail
Cursor_Left········ CON······· 76····· 'See LCD manual for more detail
Cursor_Right······· CON······· 77····· 'See LCD manual for more detail
Clear_screen······· CON······· 88····· 'See LCD manual for more detail
Contrast··········· CON······· 80····· 'Needs level $00 to $FF
Backlight_On······· CON······· 66····· 'SET $00 = on, minute max $FF
Backlight_Off······ CON······· 70····· ''See LCD manual for more detail
GP_pin_off········· CON······· 86····· 'NEEds $01 to $06 for pin #
GP_pin_on·········· CON······· 87····· 'NEEds $01 to $06 for pin #
'Key pad
Auto_repeat_on····· CON······· 126···· '$00 = resend $01 = key up/down
Auto_repeat_off···· CON······· 96····· 'See LCD manual for more detail
Auto_Trans_On······ CON······· 65····· 'Sends key press data immediately
Auto_Trans_Off····· CON······· 79····· 'STORE 10 key presses until polled
Clear_buffer······· CON······· 69····· 'See LCD manual for more detail
Poll_keypad········ CON······· 38····· 'Polls LCD for last key press
Debounce_time······ CON······· 85····· 'Set in 6.554ms units default 52mS
'Bar graphs
Wide_vert_bar······ CON······· 118···· 'Initialize wide vertical bar
Naro_vert_bar······ CON······· 115···· 'Initialize narrow vertical bar
Draw_vert_bar······ CON······· 61····· 'See LCD manual for more detail
Horz_bar··········· CON······· 104···· 'Initialize horizontal bar
Draw_horz_bar······ CON······· 124···· 'See LCD for more detail
Cusstom_char······· CON······· 78····· 'See LCD for more detail
Large_dig·········· CON······· 110···· 'See LCD for more detail
Place_lrg_dig······ CON······· 35····· 'Column $01/$12 digit $00/$09
'variable declarations
index············· VAR······· Byte(5)
userentry········· VAR······ Byte(5)·· 'key storage variable
·temp············· VAR······· Byte(5)··· 'Working variable
Key················ VAR······· Byte(5)··· 'key storage variable
'data directives
Password··········· DATA··· "33722"
·'initialization routine
GOSUB pa_w
·GOSUB PR_W
PR_W:
· GOSUB cl_s
·· SEROUT Tx,Baud,[noparse][[/noparse]"IT WORKED "]
··· PAUSE 2000
·· END
·Convert:······························ 'Label
····· 'Table to convert variable
····· LOOKDOWN· temp,[noparse][[/noparse]66,67,68,69,71,72,73,74,76,77,78,79,81,82,83,84],temp
····· 'Table to convert variable
······· LOOKUP··· temp,[noparse][[/noparse]"D","#","0","*","C","9","8","7","B","6","5","4","A","3",
·············· "2","1"],temp
······· RETURN································ 'Jump to next line UNDER last gosub
Cl_S:
······· SEROUT Tx,Baud,[noparse][[/noparse]Int,Clear_screen]
······· RETURN
Pa_w:
········· GOSUB CL_S····· 'Clears screen
········· SEROUT Tx,Baud,[noparse][[/noparse]Int,Auto_trans_On]··· 'Turns on transmit for key pad·
'··············· Sets up text on LCD
········· SEROUT Tx,Baud,[noparse][[/noparse]"Enter Password" ]
········· GOSUB W_k
········· GOSUB pr_w
········· RETURN
W_k:
·········· DO
·········· SEROUT Tx,Baud,[noparse][[/noparse]Int,Auto_trans_Off]··· 'Saves ten numbers until polled·
········· SEROUT Tx,Baud,[noparse][[/noparse]Int,Poll_keypad]······ 'Request last key press from LCD
········· SERIN Rx,Baud,[noparse][[/noparse]temp]·················· 'Store key press in temp
········· IF temp = 0 THEN w_k········ 'If no key Press jump to label
·········· FOR index= 0 TO 4
·········· READ password + index, temp
·········· IF temp <> userentry(index) THEN EXIT
········· NEXT
········ IF index <> 5 THEN
········· GOSUB CL_S
········· SEROUT tx,baud,[noparse][[/noparse] "password incorrect" ]
········· PAUSE 1000
········· GOSUB Pa_w
········· ENDIF
········· LOOP UNTIL index=5
········· GOSUB cl_s
········· SEROUT tx,baud,[noparse][[/noparse] "accessed"]
······· RETURN
·
Comments
also once the autotrans_off is turned on[noparse][[/noparse]store 10 keypresses] the program polls the keypad,so only one key is pressed causing it to jump to password incorrect.
the index=0to4 was a feeble attempt to wait for 5 keypresses then poll the keypad, but its not set up right,
LOST>>>>>>>>>>>>>>>>>>>.
·· I thought maybe I had covered this with you before...It appears (to me, but maybe not everyone else) that you're using a Matrix Orbital LCD with Keypad interface, and a 4X4 Keypad?· An earier post from you made me think you were trying to use the DEBUG window and computer keyboard.
·· In any event if this is the case what matters now is the way the routine handles the input.· In a security system there are two factors to consider.· One is how to respond to repeated incorrect input.· In my Alarms Systems (used to build these in my business) we allow 3 incorrect passwords and then the alarm goes off.
·· The other thing you need to handle (and I don't think you are) but may not be important to you is that while you're dealing with keypresses nothing else can happen.· That is, an obvious attack on this system would be to start typing a password in and let the system hang waiting for the rest.· You must still check inputs during your loop, AND you must have a time-out counter.· What this does (in my case) is after so much time has elapsed with no input, the routine resets as if it were a bad password input.· This adds one to the "bad input" routine which is reset only when a "good" password has been entered.
·· If you could be more clear on exactly what is happening in this system and what you're using I could arrange to connect up the equipment and write a routine some time today.· It's been a while and I wouldn't mind doing this again.· Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
im using a bs2 with app mod, matrix orbital display 204-25 rev 1.23 with keypad, the routin will end up being a tracking system using ir,camera,and thermal, the password program is first which enters the main program which will allow these to be turned off or on and an option for bluetooth which i think i will attached to another board and network them together,
thanks so much,
·· So you don't need a timeout and such...I think I will write the routine that way anyway and you can grab the useful information from it.· I will list my kepad layout with the source and in the reply post.· By the way, for anyone reading my earlier post I forgot to mention the timeout counter has to be reset each time a key is pressed.· I just got home but I will see if I can get this done tonight...If not, tomorrow morning.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
·· Been out most of today, but as promised here is a simple PASSWORD routine using the LK-204 and a keypad connected.· My keypad layout is documented in the code.· Note that this is merely of·conversion of the EDE1144 program I posted before to input a password.· Not much has been changed.· I added a few comments.· This concept is taken from my commercial alarm system application, but re-worked, since my codes also scan the sensors while in the loop.· Also, my routines accept multiple passwords for multiple people and activate/deactivate zones based on access, so this is a highly simplified conversion, but I hope it helps.· If you (or anyone) has any questions, feel free to ask, I know this is a rush job.·
P.S. - I'm attaching the EDE1144/Parallax LCD version for comparison.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Chris,
you make it look so simple, I will go over these and try them, they look really great, I would have liked to have said i did it, but im learning, at these are written in a self explanatory way, Your a great help chris, thanks so much, i cant wait to finish this project..
Charles Cline
Integrated Security Services
·· I'd like to say that this is self-explanatory, but I somehow doubt it is at many levels...I didn't fully document the code, since it is a conversion, but I will answer any questions on it here in this thread.· Basically what I would recommend doing for something with a complex flow like this, is to draw up a flow-chart.· That way you can more easily see what is happening and work it into functional code.
·· This is a "far-from-finished" routine, however, once I have re-written it to work the way I think it should I will post fully commented code with a flow-chart so people can see how it flows/works.· Until then this code works, but doesn't take into considerationa·things which my original code did.
·· For starters, before entering the password routine the buffer on the LK-204 should be cleared.· I am not.· The effect is that if you presss keys before downloading the program, once it runs it will get those old keystrokes.· Also, the order of events in printing the * and handling the function keys is not the way it should be.· Again, it works, but I am not trapping properly for maximum key input.· I am in the buffer, but if I remember, if you keep pressing keys it will keep printing *.· Anyway, enjoy what is there.· Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
i had problems on my password program,
what is the logical steps[noparse][[/noparse]sentence] to get numer from keypad,store it,convert it, then compare,
im trying to see the flow,
thanks
p.s. your program worked flawlessly unless you push b then it stops,
charles cline
·· That is correct...That is intentional.· If you look in the comments for the code, all of the "special" keys simply stop the code, because I did not implement any functions for them.· Perhaps I should just make them all do the same thing, but then it's not clear how to trap just those keys.
·· Logical steps...Well, this code is a bit more complicated than that, but basically when you're in your password routine you read the keyboard buffer on the LK-204.· This is done using:
SEROUT LCD_TX, Baud, [noparse][[/noparse]254, 38]····· ' Get Key From Buffer
SERIN LCD_RX, Baud, [noparse][[/noparse]inKey]········ ' Return Key
This requests a key from the keyboard buffer and then receives the response.· If the response is 0, no key was in the buffer, so we loop until we get one.· All the while we're updating a timeout counter, so if we're just sitting at the password prompt eventually it resets.· We keep requesting those keys too.
Once a key is received, this code checks to see if the key is outside the range of valid numeric keys... If not it will add the key to the array.· If the key was outside the range then it is a letter key or * or #.· At this point it is checked to see which key and that routine is handled.
Remember, these key values are being translated by a LOOKUP table, since the values returned by the LK-204 almost never match the actualy keypad values.· So you can set these to whatever you want.
Anyway, pressing the A button (ARM, in my case) terminates key entry and compares the array to the DATA statement which contains the password.· The routine adds a zero at termination to exactly match the password in the DATA statement, making a comparison easy.
In my commercial application the remote keypad and LCD do not have any password information.· They transmit the password to the main controller (which is hidden) for comparison and then receive the updated status from that (whether the password was accepted and which zones are disabled).· I hope this helps.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Can i change
· ELSEIF outKey = 66 THEN
········· STOP························· ' These Functions Are Not Defined Here
······· ELSEIF outKey = 67 THEN
········· STOP························· ' And Simply Stop The Code
······· ELSEIF outKey = 68 THEN
········· STOP
······· ELSEIF outKey = 42 THEN
········· STOP
······· ELSEIF outKey = 35 THEN
········· STOP
······· ENDIF
to elseif outkey = 66 then goto Main_p
Back to the begining of password program ?
·
·· If you're not going to use any of those keys, just remove (or comment out) those entires so there's no confusion as to the flow of the program.· Remember, you're nested in a little ways on IF...THEN segments.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com