How do I write then read 000000 to the eprom?
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.
' -----[ I/O Definitions ]------------------------------------------------- Clock PIN 0 ' shift clock (74HC165.2) SerData PIN 1 ' serial data (74HC165.7) Load PIN 2 ' input load (74HC165.1) ' -----[ Constants ]------------------------------------------------------- DelayTime CON 20 ' -----[ Variables ]------------------------------------------------------- idx VAR Byte switches VAR Byte ' switch data ' -----[ Initialization ]-------------------------------------------------- Reset: HIGH Load ' make output and high DEBUG CLS, "Switches 12345678", CR, "-------- --------", CR, "Status ........", CR ' -----[ Program Code ]---------------------------------------------------- Main: DO GOSUB Get_165 ' get switch inputs DEBUG CRSRXY, 10, 2, BIN8 switches ' display current status PAUSE DelayTime ' pad the loop a bit WRITE 400, switches PAUSE DelayTime 'pad the write command FOR switches = 0 TO 0 PAUSE 10 NEXT LOOP ' -----[ Subroutines ]----------------------------------------------------- Get_165: PULSOUT Load, 5 ' load switch inputs SHIFTIN SerData, Clock, MSBPRE, [switches] ' shift them in RETURN
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?
stored_sw_val VAR Byte read_sw_vals VAR Byte stored_sw_val = %00000000 'stored state of switches read_sw_vals = %10101011 'simulated read sw values Monitor_sw: IF stored_sw_val = read_sw_vals THEN Monitor_sw ' if different fall through and compare bits ' Now interegate each bit to find the switch that changed and do something ' See Aliases and modifiers in Basic Stamp manual IF stored_sw_val.BIT0 <> read_sw_vals.BIT0 THEN 'do something DEBUG ? read_sw_vals.BIT0 ENDIF IF stored_sw_val.BIT1 <> read_sw_vals.BIT1 THEN 'do something DEBUG ? read_sw_vals.BIT1 ENDIF IF stored_sw_val.BIT2 <> read_sw_vals.BIT2 THEN 'do something DEBUG ? read_sw_vals.BIT2 ENDIF IF stored_sw_val.BIT3 <> read_sw_vals.BIT3 THEN 'do something DEBUG ? read_sw_vals.BIT3 ENDIF IF stored_sw_val.BIT4 <> read_sw_vals.BIT4 THEN 'do something DEBUG ? read_sw_vals.BIT4 ENDIF IF stored_sw_val.BIT5 <> read_sw_vals.BIT5 THEN 'do something DEBUG ? read_sw_vals.BIT5 ENDIF IF stored_sw_val.BIT6 <> read_sw_vals.BIT6 THEN 'do something DEBUG ? read_sw_vals.BIT6 ENDIF IF stored_sw_val.BIT7 <> read_sw_vals.BIT7 THEN 'do something DEBUG ? read_sw_vals.BIT7 ENDIF stored_sw_val = read_sw_vals ' Since the stored and read sw values are different ' replace stored switch value with read value
Debug Output: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.