EEPROM_1.BAS, Use of PutEEPROM and GetEEPROM


' Program EEPROM_1.BAS
'
' 50 temperature values in the range of 60.0 to 80.0 degrees 
' are generated using a for loop.  Each is written to EEPROM beginning
' at EEPROM address 0x0700.
'
' The values are then fetched from EEPROM and displayed.
'
' Illustrates the use of PutEEPROM and GetEEPROM commands.  Note that a 
' float uses four bytes.
'
' Illustrates how to generate a number of equally spaced points using a
' for loop.  Note the use of CSng to convert integer N to a single.
'
' When equipped with a 256K (32K by 8) EEPROM, addresses range from 
' &H0000 to &H7fff.  Unlike the Parallax Basic Stamp, the program occupies
' addresses starting at &H000.  Thus, it is important that the EEPROM which
' is used for storing data begins at an address higher than the highest
' address used by the program.
'
' Although in this routine the values of temperature are "dummied", the
' routine does illustrate the ease of implementing a data logger.
'
' Compile with SerialPort.Bas
'
' Copyright, Peter H. Anderson, Baltimore, Sept, 99


Sub Main()

   Dim EEPROM_Ptr as Long
   Dim T_F as Single
   Dim N as Integer

   Call OpenSerialPort(2, 9600) 		

   ' generate some values and write them to EEPROM
   
   EEPROM_Ptr = &H0700

   For N = 0 TO 50
      T_F = 60.0 + 20.0 * CSng(N)/50.0  ' generate some temperature vals
      Call PutEEPROM(EEPROM_Ptr, T_F, 4)	' 4 bytes for each single
      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
      Call GetEEPROM(EEPROM_Ptr, T_F, 4)
      EEPROM_Ptr = EEPROM_Ptr + 4
      Call PutS(T_F)
      Call NewLine()
   Next
     
End Sub