EEPROM_2.BAS, Use of PersistentPoke and PersistentPeek


' Program EEPROM_2.BAS
'
' Performs the same function as EEPROM_1.BAS except this routine uses 
' the PersistentPoke command to write to EEPROM and PersistentPeek to
' read from EEPROM.
'
' Note that the MemAddress command is used to determine the address of the
' variable.  Each of the four bytes of the Single are then written or read 
' from EEPROM using the PersistentPoke or PersistentPeek commands.
'
' In this routine, there really is no advantage to using the 
' PersistentPeek and Poke commands over the PutEEPROM and GetEEPROM 
' approach used in EEPROM_1.BAS.  It was written to illustrate the 
' Persistent and MemAddress commands in simple example.
'
' Compile with SerialPort.Bas
'
' Copyright, Peter H. Anderson, Baltimore, Sept, 99


Sub Main()

   Dim EEPROM_Ptr as Integer
   Dim RAM_Ptr as Integer
   Dim Dat as Byte
   Dim N as Integer
   Dim M as Integer
   Dim T_F as Single

   Call OpenSerialPort(2, 9600) 		

   ' Generate some values and write them to EEPROM
   
   EEPROM_Ptr = &H700

   For N = 0 TO 50
      T_F = 60.0 + 20.0 * CSng(N)/50.0  ' generate some temperature vals
      RAM_Ptr = MemAddress(T_F)		' fetch the address of variable T_F
      FOR M = 0 TO 3
         Dat = RAMPeek(RAM_Ptr+M)	' fetch the byte from RAM
         Call PersistentPoke(Dat, EPROM_Ptr+M)	' and write it to EEPROM
      Next 
      EEPROM_Ptr = EEPROM_Ptr + 4
'     Call PutS(T_F)	' for debugging
'     Call NewLine()
   Next

   ' Now dump the data

   EEPROM_Ptr = &H0700

   For N = 0 TO 50
      RAM_Ptr = MemAddress(T_F)		' fetch the RAM address of T_F
      FOR M= 0 TO 3         
         Dat = PersistentPeek(EEPROM_Ptr + M)	' read a byte from EEPROM
         Call RAMpoke(Dat, RAM_Ptr + M)		' and write it to RAM
      Next
      EEPROM_Ptr = EEPROM_Ptr + 4
      Call PutS(T_F)
      Call NewLine()
   Next
     
End Sub