Shop OBEX P1 Docs P2 Docs Learn Events
Problem with eeprom BS2 — Parallax Forums

Problem with eeprom BS2

robertoroberto Posts: 37
edited 2006-04-04 16:26 in BASIC Stamp
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

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-03-31 21:33
    Typos will get you every time -- you must spell WRITE correctly, and you need to supply the value to WRITE as well:

    WRITE eepromAddress, key

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • FORDFORD Posts: 221
    edited 2006-04-01 14:07
    Only had a quick look but, this may noy help your program either...


    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
  • Paul Sr.Paul Sr. Posts: 435
    edited 2006-04-02 22:26
    roberto said...
    someone pls

    You should attach the exact code you are using so someone can take a look (don't paste it into a message).
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-03 05:15
    That's really not enough information to help you.· Not much difference could mean anything.· What exactly is happening?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • SSteveSSteve Posts: 808
    edited 2006-04-03 18:06
    You forgot the word FOR at the beginning of the line.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows
  • SSteveSSteve Posts: 808
    edited 2006-04-03 18:33
    That would definitely keep the program from loading. If it still isn't working, send the program as an attachment instead of just pasting it into the message. (You need to click "Post Reply" to access the Attachment Manager--you can't do it from Quick Reply.)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-04-03 18:50
    roberto,

    · In your project2.bs2 there is no eepromAddress = 0 TO 50, no eeprom writing at all. (Is there?)
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-04-03 21:38
    You have --
    keyScan: 
    [color=red]for eepromAddress = 0 to 50[/color]
    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. 
    [color=red]write eepromAddress,[/color][color=red] key[/color]
    return ' Return to program.
    

    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

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-04-03 22:55
    · At present you are not incrementing the eepromAddress counter.
    · 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.
    ·
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-04-03 23:40
    roberto said...
    if its working properly should i see entries made in eeprom locations 0 to 50 when i run Memory map?
    No.· You can't READ the eeprom from/with the PBASIC IDE (if that is what you mean.)· You will have to READ those locations as part of your program.

    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.)
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-04-04 01:02
    PJ is correct. The "Memory Map" only shows you what the IDE is predicting it will download into the eeprom.

    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.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-04 16:26
    Part of your problem is that you have two threads on the same subject and people trying to help you are getting confused between the two threads as to what has been done and what you are getting.· I am locking this thread and all further posts/replies on this subject should be directed to the other thread.

    http://forums.parallax.com/showthread.php?p=579720

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
Sign In or Register to comment.