Shop OBEX P1 Docs P2 Docs Learn Events
data storing — Parallax Forums

data storing

GiuseppeGiuseppe Posts: 51
edited 2009-06-21 22:36 in BASIC Stamp
I though I had this down but it just seems no0t to be working. I am trying to store a "pass code" using either the write or data commands.






write 0, 1
write 1, 1
write 2, 1
write 3, 1

FOR idx = 0 TO 3
          READ idx, char
          DEBUG DEC char(idx)
        NEXT



wouldn't this spit out 1111? it spat out a 1000 instead. am i missing something obvious?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-06-21 21:24
    Yes. Your loop reads one byte at a time from the EEPROM, but your DEBUG statement assumes that "char" is an array of bytes. Try just "DEBUG DEC char"
  • GiuseppeGiuseppe Posts: 51
    edited 2009-06-21 22:04
    sweet that solves that problem. though, now i am trying to work out some of my bugs in my program i just started on today. its an lcd display with key pad control for eight separate buttons. I am able to SERIN these values from the lcd but when I try to compare my written EEPROM data from the 4 digit buffer I created, it comes out as "pass word invalid". Here is the code if anybody wants to help me troubleshoot it. It is an lcd from web4robot.com.

    rxlcd                 PIN       3
          txlcd                 PIN       0
          int                   PIN       2
    
          lcdbaud         CON     84
    
            prefix          CON     $FE
            lcdclear        CON     $14
            lcdlighton      CON     $0A
            lcdlightoff     CON     $0B
            lcdpos          CON     $0C
            lcdhome         CON     $0D
            lcdread         CON     $1B
            lcdmode         CON     $1C
    
            code            VAR     Byte(4)
            counter         VAR     Byte
            idx             VAR     Byte
            char            VAR     Byte
    
            WRITE 0, 1
            WRITE 1, 1                 ' passcode is 1111
            WRITE 2, 1 
            WRITE 3, 1
    
            SEROUT rxlcd, lcdbaud, [noparse][[/noparse]prefix, lcdmode, 1]   ' sets to eight button mode
            GOSUB Lcd_Clear                                        ' clear lcd
            GOSUB Lcd_Home                                       ' sets cursor to home
    
            FOR idx = 0 TO 3
              READ idx, char                        ' just reads the written passord from EEPROM
              DEBUG DEC char
            NEXT
    
            Main:
    
            counter = 0                                 ' set counter to zero
    
            DEBUG "Please enter pass", CR     ' entry statement
    
            'DO                                           ' something i was trying, ignore
    
            polling:                                       ' polling address
    
            BRANCH int, [noparse][[/noparse]Keypad, polling]      ' see if int pin is high or low, high = keep waiting, low = get one byte of data from button press
            PAUSE 200
    
            Keypad:             'keypad address 
            PAUSE 200                               
              SEROUT rxlcd, lcdbaud, [noparse][[/noparse]prefix, lcdread]   ' reads one byte from keypad buffer
              SERIN txlcd, lcdbaud, [noparse][[/noparse]code(counter)]       ' "catches" that one byte from buffer
              DEBUG DEC code(counter)                      ' tells you what was "captured"
              counter = counter + 1                            ' counter increments by one to help indicate button presses in buffer
              PAUSE 1000
            'LOOP UNTIL (counter = 4)
    
            IF (counter = 4) THEN        ' when 4 button presses occur, 4 bytes have been buffered
              GOTO compare
            ELSEIF (counter < 4) THEN  ' if less than 4 bytes are buffered, wait for another button press (for int to go low @ polling)
              GOTO polling
            ENDIF
    
            compare:
            FOR idx = 0 TO 3
              READ (idx), char                     ' reads idx value and stores it temporarily in char
              IF (char <> code(idx)) THEN   ' if that location does not match recently buffered code, its wrong
                 GOTO wrong
              ENDIF
            NEXT
    
            right:
            DEBUG CR, "come on in!", CR    ' passcode valid
            GOTO Main
    
            wrong:
            DEBUG CR, "wrong pass, try again", CR  ' passcode invlaid
            GOTO Main
    
    
  • GiuseppeGiuseppe Posts: 51
    edited 2009-06-21 22:36
    just found out my problem. . . . . i was looking in an older version of the file and overlooked a digit. RESOLVED!
Sign In or Register to comment.