Checking for Empty value?
eagletalontim
Posts: 1,399
I am trying to figure out how to properly check a variable to see if it is "empty". This function is for reading the EEPROM and if the values received are "empty", load default values. Please note that some values will equal 0
Here is what I have so far :
Here is what I have so far :
CON menuItems = 11 VAR BYTE Stored[255] PUB Main | iloop, EValue repeat iloop from 0 to menuItems Step 1 EValue := ReadEEPROM(iloop) ' HERE is where I need to check if EEPROM was loaded Stored[iloop] := EValue if NOT_LOADED == 1 Load_Defaults PUB saveval(value, address) | startTime if i2c.WritePage(i2c#BootPin, i2c#EEPROM, $8000 + (address * 32), @value, 32) abort ' an error occured during the write startTime := cnt ' prepare to check for a timeout repeat while i2c.WriteWait(i2c#BootPin, i2c#EEPROM, @value) if cnt - startTime > clkfreq / 10 abort ' waited more than a 1/10 second for the write to finish return PUB ReadEEPROM(address) | tmp tmp := i2c.ReadLong(i2c#BootPin, i2c#EEPROM, $8000 + (address * 32)) return tmp
Comments
I think his quote meant to infer that the values would be 8 bits or less....
(At least to me it does....)
You might need to have your values stored in two different locations in the EEPROM, and if those locations don't match then basically the original spot is empty.
Or have the secondary locations store a set value to indicate if it the original location has been updated from the "default" value.
Or have all locations word sized (16 bits) with the first byte storing a fixed set value (say $FF) and then the next value the true value.