Shop OBEX P1 Docs P2 Docs Learn Events
Write to eeprom above address 255 and read it back — Parallax Forums

Write to eeprom above address 255 and read it back

ernimraternimrat Posts: 3
edited 2005-07-22 13:30 in BASIC Stamp
' {$STAMP BS2}
' {$PBASIC 2.5}


READING VAR Word
VAL VAR Word
EE_PTR VAR Word

EE_PTR = $000
READING = 0

FOR EE_PTR=0 TO $12C' write some readings to EEPROM
READING = READING+5
WRITE EE_PTR, READING
NEXT

FOR EE_PTR=0 TO $12C ' now dump the results to the PC
READ EE_PTR, VAL
DEBUG DEC4 VAL , " "
IF ((EE_PTR = 0) | ((EE_PTR+1) // 10 <>0)) THEN SKIP_CR
' else
DEBUG CR
SKIP_CR:
NEXT

END

confused.gif AND THE OUTPUT IS

0005 0010 0015 0020 0025 0030 0035 0040 0045 0050
0055 0060 0065 0070 0075 0080 0085 0090 0095 0100
0105 0110 0115 0120 0125 0130 0135 0140 0145 0150
0155 0160 0165 0170 0175 0180 0185 0190 0195 0200
0205 0210 0215 0220 0225 0230 0235 0240 0245 0250
0255
0004 0009 0014 0019 0024 0029 0034 0039 0044
0049 0054 0059 0064 0069 0074 0079 0084 0089 0094
0099 0104 0109 0114 0119 0124 0129 0134 0139 0144
............................... AND SO ON

even though i declared VAL & READING variables as WORD it only shows upto 255 and then restarts from 0

Isn't there some way out to to go beyond 255, my whole project depends on this.

Can someone help?

Comments

  • NewzedNewzed Posts: 2,503
    edited 2005-07-22 12:57
    You did not declare the variable reading as a word whren you wrote to EEPROM.· Change your WRITE line:

    WRITE EE_PTR, WORD READING



    and see what happens.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Do you have a Stamp Tester yet?
    http://hometown.aol.com/newzed/index.html

    ·
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-07-22 13:01
    You also need to increment your address pointer (since you are writing two bytes each time):

    · FOR eePntr = 0 TO $12C STEP 2
    ··· reading = reading + 5
    ··· WRITE eePntr, Word reading
    · NEXT


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • ernimraternimrat Posts: 3
    edited 2005-07-22 13:21
    Actually i want to read text from eeprom which was written at the start of the program. The text goes beyond eeprom address 255. So, when i read them back it is reading wrong characters
  • ernimraternimrat Posts: 3
    edited 2005-07-22 13:30
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    RS CON 4 ' Register Select (1 = char)
    E CON 5 ' LCD enable pin (1 = enabled)
    ' LCD control characters
    ClrLCD CON $01 ' clear the LCD
    CrsHm CON $02 ' move cursor to home position
    CrsLF CON $10 ' move cursor left
    CrsRT CON $14 ' move cursor right
    DispLf CON $18 ' shift displayed chars left
    DispRt CON $1C ' shift displayed chars right
    DDRam CON $80 ' Display Data RAM control
    Line1 CON $00 ' starting address of line 1
    Line2 CON $40 ' starting address of line 2
    NoOfChar VAR Nib
    ScreenV VAR Nib
    FuncV VAR Nib
    '
    [noparse][[/noparse] Variables ]---
    char VAR Byte ' character sent to LCD
    index VAR Word ' loop counter
    J VAR Word(1)
    K VAR Word(1)
    I VAR Byte
    EditV VAR Bit
    '
    [noparse][[/noparse]keypad vars & consts]
    btn VAR Byte
    number VAR Byte
    KeyEnter CON 10
    '
    [noparse][[/noparse] EEPROM Data ]---
    DATA @0 ," WOODMASTER (INDIA) "
    DATA @20 ,"Press ENTER to cont!"
    DATA @40 ,"M/c Auto-</Manual->" ' SELECTION IS AUTO
    DATA @60 ,"Program Mode- AUTO "
    DATA @80 ," RUN-< / EDIT-> "
    DATA @100," Program Number "
    DATA @120,"Running... "
    DATA @140,"Select Prog. Number "
    DATA @160,"Program Mode: MANUAL"
    DATA @180,"ON: 003 OFF: 003 "
    DATA @200,"Running... HTR: ON "
    DATA @220,"Running... HTR: OFF "
    DATA @240,"Select Prog. Number "
    DATA @260,"Up / Down 001 "
    DATA @280,"Prog. Number 001 "
    DATA @300,"Running... "
    '
    [noparse][[/noparse] Initialization ]---
    Init:
    DIRS = %00111111 ' set 0-5 as outputs
    OUTS = %00000000 ' clear the pins

    btn =0
    NoOfChar=0
    ScreenV=15
    FuncV=15
    EditV=0
    ' Initialize the LCD (Hitachi HD44780 controller)
    PAUSE 500 ' Wait for LCD init
    char=%00000011 ' Set 8-bit mode (1)
    GOSUB LCDcmd
    char=%00000011 ' Set 8-bit mode (2)
    GOSUB LCDcmd
    char=%00000011 ' Set 8-bit mode (3)
    GOSUB LCDcmd
    char=%00000010 ' Set 4-bit mode
    GOSUB LCDcmd
    char=%00101111 ' Set duty cycle 11xx = 5x11 matrix
    GOSUB LCDcmd ' 10xx = 5x8 matric
    char=%00000000 ' Display control mode
    GOSUB LCDcmd
    char=%00101000 ' 2-line mode
    GOSUB LCDcmd
    char=%00001100 ' Set display ON, cursor OFF, blink OFF
    GOSUB LCDcmd ' 11CB -> C=1 cursor on, B=1 blink on
    char=%00000000 ' Entry control mode
    GOSUB LCDcmd
    char=%00000110 ' Set cursor right, no display shift
    GOSUB LCDcmd ' 01IS -> I=1 cursor right, S=1 shift display
    char = ClrLCD ' Clear LCD
    GOSUB LCDcmd

    Start:

    J(0)=0
    J(1)=19
    DEBUG DEC j(0)," ", DEC j(1)," ",CR
    GOSUB GetChar
    DEBUG DEC j(0)," ", DEC j(1)," ",CR
    K(0)=200
    K(1)= 219
    DEBUG DEC K(0)," ", DEC K(1),CR
    GOSUB GetChar2
    DEBUG DEC K(0)," ", DEC K(1),CR
    END
    LCDcmd: LOW RS ' enter command mode
    LCDwr:
    OUTA = char.HIGHNIB
    PULSOUT E, 1 ' strobe the Enable line
    OUTA = char.LOWNIB
    PULSOUT E, 1
    HIGH RS ' return to character mode
    RETURN
    GetChar:
    char=Line1
    GOSUB LCDcmd
    FOR index = J(0) TO J(1)
    DEBUG DEC index, " ", DEC j(0)," ", DEC j(1),CR
    READ index, char ' get character from EEPROM
    GOSUB LCDwr ' write it
    NEXT
    RETURN

    GetChar2:
    char = DDRam + Line2 ' move to line 2
    GOSUB LCDcmd
    FOR index = K(0) TO K(1) STEP 1
    DEBUG DEC index, " ", DEC K(0)," ", DEC K(1),CR
    READ index, char ' get character from EEPROM
    GOSUB LCDwr ' write it
    NEXT
    RETURN

    This is my actual program. When i read them back the text it is reading wrong characters and lcd shows characters on wrong places
Sign In or Register to comment.