STORE Examples

BS2p icon BS2pe icon BS2px icon

Syntax: STORE

 

 

 

NOTE: This is written for the BS2p and will also run on the BS2pe and BS2px. Modify the $STAMP directive (as required) before downloading to the BS2pe or BS2px.

' STORE0.BSP
' This program demonstrates the STORE command and how it affects the READ
' and WRITE commands.  This program "STORE0.BSP" is intended to be down-
' loaded into program slot 0.  It is meant to work with STORE1.BSP and
' STORE2.BSP.  Each program is very similar (they display the current
' Program Slot and READ/WRITE Slot numbers and the values contained in the
' first five EEPROM locations.  Each program slot will have different data
' due to different DATA commands in each of the programs downloaded.

' {$STAMP BS2p, STORE1.BSP, STORE2.BSP}
' {$PBASIC 2.5}

#IF ($STAMP < BS2P) #THEN
  #ERROR "This program requires BS2p, BS2pe, or BS2px"
#ENDIF

idx             VAR     Word            ' index
value           VAR     Byte

LocalData       DATA    @0, 1, 2, 3, 4, 5


Main:
  GOSUB Show_Slot_Info                          ' show slot info/data
  PAUSE 2000
  STORE 1                                       ' point READ/WRITE to Slot 1
  GOSUB Show_Slot_Info
  PAUSE 2000
  RUN 1                                         ' run program in Slot 1
  END

Show_Slot_Info:
  GET 127, value
  DEBUG CR, "Pgm Slot: ", DEC value.NIB0,
        CR, "R/W Slot: ", DEC value.NIB1,
        CR, CR

  FOR idx = 0 TO 4
    READ idx, value
    DEBUG "Location: ", DEC idx, TAB,
          "Value: ", DEC3 value, CR
  NEXT
  RETURN

' STORE1.BSP

' {$STAMP BS2p}
' {$PBASIC 2.5}

idx             VAR     Word                    ' index
value           VAR     Byte

LocalData       DATA    @0, 6, 7, 8, 9, 10


Main:
  GOSUB Show_Slot_Info                          ' show slot info/data
  PAUSE 2000
  STORE 0                                       ' point READ/WRITE to Slot 0
  GOSUB Show_Slot_Info
  PAUSE 2000
  RUN 2                                         ' run program in Slot 2
  END

Show_Slot_Info:
  GET 127, value
  DEBUG CR, "Pgm Slot: ", DEC value.NIB0,
        CR, "R/W Slot: ", DEC value.NIB1,
        CR, CR

  FOR idx = 0 TO 4
    READ idx, value
    DEBUG "Location: ", DEC idx, TAB,
          "Value: ", DEC3 value, CR
  NEXT
  RETURN

' STORE2.BSP

' {$STAMP BS2p}
' {$PBASIC 2.5}

idx             VAR     Word                    ' index
value           VAR     Byte

LocalData       DATA    @0, 11, 12, 13, 14, 15


Main:
  GOSUB Show_Slot_Info                          ' show slot info/data
  PAUSE 2000
  STORE 0                                       ' point READ/WRITE to Slot 0
  GOSUB Show_Slot_Info
  END

Show_Slot_Info:
  GET 127, value
  DEBUG CR, "Pgm Slot: ", DEC value.NIB0,
        CR, "R/W Slot: ", DEC value.NIB1,
        CR, CR

  FOR idx = 0 TO 4
    READ idx, value
    DEBUG "Location: ", DEC idx, TAB,
          "Value: ", DEC3 value, CR
  NEXT
  RETURN

 

The next program, STOREALL.BSP, is not related to the previous three programs. STOREALL.BSP demonstrates the use of the STORE command to treat contiguous program slots as one block of memory (14 kBytes for the BS2p and BS2px, 30 kBytes for the BS2pe). This illustrates one of the most powerful uses of the STORE command.

NOTE: This is written for the BS2p and will also run on the BS2pe and BS2px. Modify the $STAMP directive (as required) before downloading to the BS2pe or BS2px.

' STOREALL.BSP
' This program demonstrates the STORE command and how it can be used to
' "flatten" the EEPROM space for applications requiring a lot of storage.
' This program writes to EEPROM locations within program slots 1 through 7
' on the BS2p and BS2px, and 1 through 15 on the BS2pe, thus, has access
' to 14- or 30-kBytes of space.

' {$STAMP BS2p}
' {$PBASIC 2.5}

#SELECT $STAMP
  #CASE BS2, BS2E, BS2SX
    #ERROR "This program requires BS2p, BS2pe, or BS2px"
  #CASE BS2P, BS2PX
    HiSlot      CON     7
  #CASE BS2PE
    HiSlot      CON     15
#ENDSELECT

LoSlot          CON     1                       ' first slot for "flat" EE
MemSize         CON     HiSlot - LoSlot + 1 * 2048

eeAddr          VAR     Word                    ' address pointer
value           VAR     Word                    ' cell value
slot            VAR     Byte                    ' current R/W slot


Main:
  DEBUG "Flat Memory", CR,
        "---------------------", CR,
        "First Slot..... ", DEC LoSlot, CR,
        "Last Slot...... ", DEC HiSlot, CR,
        "Flat EE Size... ", DEC MemSize, CR, CR

  PAUSE 2000
  DEBUG "Writing to flat Memory...", CR
  PAUSE 1000
  FOR eeAddr = 0 TO (MemSize - 1) STEP 128      ' step through "flat" EE
    value = eeAddr * 2                          ' generate value
    GOSUB Write_Word                            ' write it
    GET 127, slot                               ' get R/W slot
    DEBUG "--> Location: ", DEC5 eeAddr, "   ",     ' show "flat" address
          "Value: ", DEC5 value, "   ",         ' show value
          "(", DEC slot.NIB1, ")", CR           ' show slot
  NEXT
  DEBUG CR

  DEBUG "Reading from flat Memory...", CR
  PAUSE 1000
  FOR eeAddr = 0 TO (MemSize - 1) STEP 128
    GOSUB Read_Word                             ' read value from EE
    GET 127, slot                               ' get W/R slot
    DEBUG "<-- Location: ", DEC5 eeAddr, "   ",
          "Value: ", DEC5 value, "   ",
          "(", DEC slot.NIB1, ")  "
     IF (value <> (2 * eeAddr)) THEN            ' verify location
      DEBUG "- Error"
    ENDIF
    DEBUG CR
  NEXT
  END

Write_Word:
  STORE (eeAddr >> 11) + LoSlot                 ' set slot
  WRITE eeAddr, Word value                      ' write value
  RETURN

Read_Word:
  STORE (eeAddr >> 11) + LoSlot                 ' set slot
  READ eeAddr, Word value                       ' read value
  RETURN

Go to PBASIC Language home page

Open Getting Started with Stamps in Class

Open Connection Troubleshooting

BASIC Stamp Help Version 2.5.4

Copyright © Parallax Inc.

8/21/2013