Problem with eeprom BS2
roberto
Posts: 37
FROM WHAT I LEARNED IN BASIC STAMP MANUEL AND AFTER GETTING THE HARDWARE WORKING USING THIS KEYPAD SCAN.
I RAN INTO TROUBLE WHEN I WANTED TO STORE THE DATA FROM THE KEYTROKE TO THE EEPROM FOR SOME REASON IT WONT EVEN LET RUN THE PROGRAM AFTER I ENTERED TO EEPROM INSTRUCTIONS. CAN SOMEONE HELP PLS i aint going anywhere with this i think
db var bit ' Debounce bit for use by keyScan.
press var bit ' Flag to indicate keypress.
key var nib ' Key number 0-15.
row var nib ' Counter used in scanning keys.
cols var INB ' Input states of pins P4-P7.
eepromAddress var Byte
again:
gosub keyScan
if press = 0 then again
debug "key pressed = ", hex key,cr
press = 0
goto again
keyScan:
for eepromAddress = 0 to 50
for row = 0 to 3 ' Scan rows one at a time.
low row ' Output a 0 on current row.
key = ~cols ' Get the inverted state of column bits.
key = NCD key ' Convert to bit # + 1 with NCD.
if key <> 0 then push ' No high on cols? No key pressed.
input row ' Disconnect output on row.
next ' Try the next row.
db = 0 ' Reset the debounce bit.
write·eepromAddress, key
return ' Return to program.
push:
if db = 1 then done ' Already responded to this press, so done.
db = 1: press = 1 ' Set debounce and keypress flags.
key = (key-1)+(row*4) ' Add column (0-3) to row x 4 (0,4,8,12).
lookup key,[noparse][[/noparse]1,2,3,10,4,5,6,11,7,8,9,12,14,0,15,13],key
done:
input row ' Disconnect output on row.
Post Edited (roberto) : 4/3/2006 6:12:53 PM GMT
I RAN INTO TROUBLE WHEN I WANTED TO STORE THE DATA FROM THE KEYTROKE TO THE EEPROM FOR SOME REASON IT WONT EVEN LET RUN THE PROGRAM AFTER I ENTERED TO EEPROM INSTRUCTIONS. CAN SOMEONE HELP PLS i aint going anywhere with this i think
db var bit ' Debounce bit for use by keyScan.
press var bit ' Flag to indicate keypress.
key var nib ' Key number 0-15.
row var nib ' Counter used in scanning keys.
cols var INB ' Input states of pins P4-P7.
eepromAddress var Byte
again:
gosub keyScan
if press = 0 then again
debug "key pressed = ", hex key,cr
press = 0
goto again
keyScan:
for eepromAddress = 0 to 50
for row = 0 to 3 ' Scan rows one at a time.
low row ' Output a 0 on current row.
key = ~cols ' Get the inverted state of column bits.
key = NCD key ' Convert to bit # + 1 with NCD.
if key <> 0 then push ' No high on cols? No key pressed.
input row ' Disconnect output on row.
next ' Try the next row.
db = 0 ' Reset the debounce bit.
write·eepromAddress, key
return ' Return to program.
push:
if db = 1 then done ' Already responded to this press, so done.
db = 1: press = 1 ' Set debounce and keypress flags.
key = (key-1)+(row*4) ' Add column (0-3) to row x 4 (0,4,8,12).
lookup key,[noparse][[/noparse]1,2,3,10,4,5,6,11,7,8,9,12,14,0,15,13],key
done:
input row ' Disconnect output on row.
Post Edited (roberto) : 4/3/2006 6:12:53 PM GMT
Comments
WRITE eepromAddress, key
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
You have a gosub to 'keyscan'.
When it gets to keyscan, and··· 'if key <> 0 then push'
then it goes to the push routine.
When it gets to the push routine, there is no 'return' there to return it to the line after gosub.
Cheers,
Chris - West OZ
You should attach the exact code you are using so someone can take a look (don't paste it into a message).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
· In your project2.bs2 there is no eepromAddress = 0 TO 50, no eeprom writing at all. (Is there?)
Given -- for eepromAddress = 0 to 50.· There is no NEXT for this in your subroutine, so it will not increment.· [noparse][[/noparse]There is a NEXT for "row".]· You should start with eepromAddress = 0 and increment eepromAddress with each pass/keypress (until eepromAddress = 50)
IF (eepromAddress < 51) THEN eepromAddress = eepromAddress + 1
· As I see it, you should start with a eepromAddress VAR Byte and make it = 0, then each time a key is pressed you (need to) increment eepromAddress.· That could be a subroutine all its own or part of another -- that is up to you.
· Right now, eepromAddress starts at 0 (where you have: for eepromAddress = 0 to 50) and then it·goes nowhere.··To get it to increment, as part of a FOR...NEXT expression, at some time there has to be a NEXT -- but you are not NEXTing it anywhere.
· Agree or Disagree?
· "Nesting" NEXTs can get tricky and·that is why I suggest/suggested incrementing the VARiable in my previous Reply.
·
For something simple try having it WRITE for·5 keypresses, instead of 50.· Once you have your·5 then READ those locations (it is the same deal as WRITing.)
You can easily write a short subroutine to loop through your eeprom code, and send it out the serial port. You'll have to load that along with the rest of your program -- if you try to load it 'after the fact', the programming cycle will erase your eeprom.
http://forums.parallax.com/showthread.php?p=579720
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com