You are on page 1of 2

How write word variables into eeprom

http://www.mikroe.com/forum/viewtopic.php?t=21692

'-------------------------------------------------------------------------
-----
'-------- Unit EepromVariable --- version: 2009-09-16 for
Mikrobasic-----------
'-------------------------------------------------------------------------
-----
'
'INTERFACE:

'procedure EEPromWriteVariable(Dat as ^byte, Number, EEpromAddress as


byte)
'procedure EEPromReadVariable(Dat as ^byte, Number, EEpromAddress as byte)

'These procedures/functions do write and read the content


'of any type of variable to/from Eeprom.
'
' The procedures/functions need following parameters:
' - the address of the variable
' - the size of the variable (8–bit=1, 16-bit=2, 32-bit=4)
' - the first (lowest) address in Eeprom to write to or read from'
' Take care of the mapping of the variables in Eeprom so that they do not
overlap!

'CALLING THE ROUTINES:

'EePromWriteVariable(@Variable, sizeof(Variable), EePromAddress)


  
'EePromReadVariable(@Variable, sizeof(Variable), EePromAddress)
  
'IMPLEMENTATION:

'sub procedure EePromWriteVariable(dim Dat as ^byte, dim Number,


EEpromAddress as byte)
'dim I as byte
'  for I = 0 to Number -1
'   EEProm_Write(EEPromAddress, Dat^)'  // write the "I"th byte
'   Delay_ms(25)
'   Inc(Dat)
'   Inc(EEpromAddress)
'  next I
'end sub
'sub procedure EePromReadVariable(dim Dat as ^byte, dim Number,
EEpromAddress as byte)
' dim I as byte
'   for I = 0 to Number -1
'    Dat^ = EEProm_Read(EEPromAddress)'  // read the "I"th byte
'    Delay_ms(25)
'    Inc(Dat)
'    Inc(EEpromAddress)
'   next I
'end sub

'EXAMPLE:

'dim CurrentValue as  word


'dim StoredValue as word

'CurrentValue = 1023
'EePromWriteVariable(@CurrentValue, 2, 10)
'Delay_us(500)

'EePromReadVariable(@StoredValue, 2, 10)
'Delay_us(500)
'WordToStr(StoredValue, Text)
'Lcd_Out(1, 1, Text)

'So in LCD display you view "1023"

'-------------------------------------------------------------------------
------

You might also like