get trouble
ion
Posts: 101
Hello ,
I have trouble reading 2 words from the scratchpad ram with get.
I declared two variable words V1 and V2
I managed to put on the scratchpad from 0 to 8 eight digits as follow:
0 1 2 3 4 5 6 7··· location on the scratchpad ram
1 2 3 4 5 6 7 8··· numbers at that location. I know they are there as i can see them·with debug when i enter them one by one.
I need to read now the V1 as =1234 and v2=5678
I used GET 0,Word V1 and
········ GET 5,Word V2,
but what i get is V1=0513 and V2=1541
What·am I doing wrong ?
Please help.
Thanks
Ion
I have trouble reading 2 words from the scratchpad ram with get.
I declared two variable words V1 and V2
I managed to put on the scratchpad from 0 to 8 eight digits as follow:
0 1 2 3 4 5 6 7··· location on the scratchpad ram
1 2 3 4 5 6 7 8··· numbers at that location. I know they are there as i can see them·with debug when i enter them one by one.
I need to read now the V1 as =1234 and v2=5678
I used GET 0,Word V1 and
········ GET 5,Word V2,
but what i get is V1=0513 and V2=1541
What·am I doing wrong ?
Please help.
Thanks
Ion
Comments
Posting the entire segment of code would probably be real helpful.
Regards,
Bruce Bates
Here is the code:
KEYIN········ ·· VAR···· Byte
CURSOR········ VAR···· Byte
RESULT········ VAR···· Nib
v1················ VAR··· ·Word
v2················ VAR···· Word
CURSOR=0
INPUT_DATA:
SERIN 14\2, 84,[noparse][[/noparse]keyin]
IF KEYIN < $3A THEN RESULT= keyin-$30
PUT cursor,result
DEBUG DEC cursor," ",DEC result,CR
CURSOR=CURSOR+1
IF (CURSOR) = 8 THEN VERIFY
GOTO INPUT_DATA
VERIFY:
GET 0, Word v1
GET 3, Word v2
DEBUG DEC v1," ",DEC v2,CR
And here is the Debug window display
0 1
1 2
2 3
3 4
4 5
5 6
6 7
7 8
513 1541
Thanks for looking into my problem
Ion
SP_to_Val:
· mult = 1000
· value = 0
· FOR idx = 0 TO 3
··· READ (target + idx), temp
··· value = value + (temp * mult)
··· mult = mult / 10
· NEXT
· RETURN
Note that this routine is a bit limited: it expects your values to be in four-digit chunks. I think it would be easier to modifiy the input routine. I don't know the keypad you're working with, but I think you could do something like this:
Get_Number:
· value = 0
· DO
··· SERIN 14\2, 84, [noparse][[/noparse]keyIn]
··· IF (keyIn < $3A) THEN
····· value = value * 10 + (keyIn - $30)
··· ENDIF
··LOOP UNTIL (keyIn = XX)
· RETURN
This will take a key, convert it from ASCII to a digit if valid, then add it to the value. Note that the value is shifted left one digit (x 10) for each new valid digit. A robust routine would also allow a backspace key (simply divide the current value by 10 if backspace hit). The routine will accept digits until some terminater key (XX) is pressed.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
It does works as expected. I will practice more with the rest of the code to see how it will interact and if i·have an other question I will postit.
Thank again
ion
It works like a charm ( the second solution- is the one which i choose for testing)
I can check my keyboard input against a stored password on an externall EEprom, and do what i want if password is wrong or good.
Here is the test code:
MASTLO········ VAR···· Word
MASTHI········ VAR···· Word
cursor········ VAR···· Byte
value········· VAR···· Word
keyin········· VAR···· Word
I2CIN 0,$A1, 1616,[noparse][[/noparse]DEC4 MASTHI,DEC4 MASTLO ]·· ' stored value is 1234 and 5678
Get_Number:
cursor=1
first:
· value = 0
· DO
··· SERIN 14\2, 84, [noparse][[/noparse]keyIn]
··· IF (keyIn < $3A) THEN
····· value = value * 10 + (keyIn - $30)
··· ENDIF
··· DEBUG DEC value,CR
··· cursor=cursor+1
· IF cursor=5 THEN check1
· IF cursor=9 THEN check2
· LOOP
GOTO get_number
check1:· IF (value=MASTHI) THEN first
········ DEBUG "Try again. Wrong password",CR
GOTO get_number
check2:· IF (value=MASTlo) THEN
··········· GOTO fin
········ ENDIF
······ DEBUG "Try again. Wrong password",CR
······ GOTO get_number
fin:
DEBUG "Password OK",CR
GOTO get_number
Thanks again
Ion
Main:
· FOR pw = 0 TO 1
··· LOOKUP pw, [noparse][[/noparse]MastHi, MastLo], testVal
····DO
····· GOSUB Get_Num
····· IF (value <> testVal) THEN
····· · DEBUG "Wrong password -- try again"
····· ELSE
······· EXIT·· ' terminate DO-LOOP
····· ENDIF
··· LOOP
· NEXT
Fin:
· DEBUG "Password okay"
· END
Get_Num:
· value = 0
· idx = 0
· DO
··· SERIN 14\2, 84, [noparse][[/noparse]keyIn]
··· IF (keyIn < $3A) THEN
····· value = value * 10 + (keyIn - $30)
····· idx = idx + 1
··· ENDIF
··LOOP UNTIL (idx = 4)
· RETURN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
Post Edited (Jon Williams) : 8/10/2004 3:58:53 PM GMT