How do I write then read 000000 to the eprom?
sir_hacksalot
Posts: 15
Im using a 74HC165 to read the state of switches (things doing stuff). Id like to do some different "stuff" with that data as it changes states.
I figure that I could write the state of the switches read by the 74HC165 to the eeprom and read it later in the code to do "stuff" as it changes.
Ill be updating the eeprom every 10 ms. Ill hit the 100,000 writes real quick there so that will be a problem in the future i think.
as a side note: how do write and read to different locations so as to extend the life of my eeprom.
Question. How do I write 8 digits to eeprom? I can write up to 255 but I need to write 00000000 or any variation of those ones and zeros (bianary 0s and 1s to show open closed switches)\
Should I convert the 8 bit data to hex or asci and save that? If so how the heck to I do that?
Should I use a look down / up table to analyze the conditions of the 1s and 0s? that would be 256 total variations. Lots of ram for that.
Heres my code. simple. needs some help.
I figure that I could write the state of the switches read by the 74HC165 to the eeprom and read it later in the code to do "stuff" as it changes.
Ill be updating the eeprom every 10 ms. Ill hit the 100,000 writes real quick there so that will be a problem in the future i think.
as a side note: how do write and read to different locations so as to extend the life of my eeprom.
Question. How do I write 8 digits to eeprom? I can write up to 255 but I need to write 00000000 or any variation of those ones and zeros (bianary 0s and 1s to show open closed switches)\
Should I convert the 8 bit data to hex or asci and save that? If so how the heck to I do that?
Should I use a look down / up table to analyze the conditions of the 1s and 0s? that would be 256 total variations. Lots of ram for that.
Heres my code. simple. needs some help.
idx VAR Word ' loop control switches VAR Word ' value(s)WHAT? MemLocation CON 5248 'somewhere on the eeprom Memdata CON 255 ' needs to be 8 bits Write_EE: DEBUG CLS ' clear screen WRITE MemLocation,Memdata ' single byte Read_EE: FOR idx = MemLocation TO MemLocation ' show raw bytes in EE READ idx, switches DEBUG "mem location data: ",DEC idx, " : ", DEC switches NEXT END
Comments
Also, are the switches changing every 10ms? If not you can always have it save them whenever they're updated only, extending the time before a write failure. Even then I would probably implement a save-on-power-loss feature or use battery backed RAM or FRAM if I need saves at that rate.
Im still a little confused.
Im using this code to get the data from the shift register.
This code outputs the 8 digits showing the states of the switches.
I need to store that data every time it changes in the eeprom so i can read the changing state and add actions to the program.
Id like to write it only as it changes as suggested by Chris, I have no Idea how to do that (yet).
Is this var "switches" of "00001000" 8 seperate digits of which there can be 256 variation or is a single byte when written to the EEprom?
I only get 4 bits back when I use the "word" function in my read write program. Do I need 8 bits for the zeros and ones?
read_sw_vals.BIT0 = 1
read_sw_vals.BIT1 = 1
read_sw_vals.BIT3 = 1
read_sw_vals.BIT5 = 1
read_sw_vals.BIT7 = 1
Yes it's long but it saves repeated eeprom write cycles.
Agreed. I have often added a DS1302 to a project just for the battery backed SRAM. I have had more than a few projects that required constant updating of a variable (or more) that needed to survive loss of power.