johnmobley
New Member
I would like some help writing to EEPROM. Datalogging is new to me and I have never worked with EEPROM before. When I looked at the code it seemed pretty simple. It would take a data "byte" stored in a symbol labeled info (b4) and through the sub-procedures read/write to EEPROM.
As I began writing my program I began to run into a problem that is now becoming important. One of the things I want to record are temperature values. To work with temperature I had to use data "word" because a byte was too small. To use the word I also created a symbol called info2 (w1). All of the EEPROM read/write sub-procedures are only looking for the info symbol (which is a "byte" value). How can I resolve these conflicts so that I can also read/write the temperature values to EEPROM? If more information is neccesary to help me, please let me know. Below is the basic code that I am using:
symbol EE_D_I = pin0 'EEPROM data pin (input 0)
symbol EE_D_O = 0 'EEPROM data pin (output 0)
symbol EE_CLK = 1 'EEPROM clock pin (output 1)
symbol EE_CS = 2 'EEPROM chip select pin (output 2)
symbol info = b4 'Data byte for heater status
symbol i = b5 'Scratchpad counter
symbol ShifReg = w3 'Scratchpad shift register
symbol address = b8 'EEPROM address
symbol page = b9 'EEPROM page
symbol clocks = b11 'Scratchpad clock counter
symbol info2 = w1 'Data word for temperature
for address = 0 to 59
readadc 1, info
If info = 255 Then
goto heaton
Else
goto heatoff
endif
CONTINUE:
readadc10 2, info2 'This reads the temperature of the heater box.
let page = 1
gosub eewrite
let info2 = info2 * 100 - 50508 / 43
serout 7, T2400, (254, 192, "Temp. = ", #info2, " ", %11011111, "F")
for b0 = 1 to 2 '1 x 60 second delay
pause 60000
next b0
next address
end
heaton:
serout 7, T2400, (254, 128, "Heaters are: ON ") 'This reads the state of the heater circuit.
let page = 0
gosub eewrite
goto CONTINUE
heatoff:
serout 7, T2400, (254, 128, "Heaters are: OFF") 'This reads the state of the heater circuit.
let page = 0
gosub eewrite
goto CONTINUE
' ***Below are the standard sub-procedures to read/write to EEPROM.
' ***There will be a comment above each procedure to designate it’s purpose.
' This sub-procedure writes a byte to the EEPROM
' ‘Data’ is written to ‘address’ on ‘page’
eewrite:
gosub eenabl 'Enable.
let ShifReg = $A00 'Get the write opcode.
let ShifReg = ShifReg | w4 'OR in the address bits.
let clocks = 12 'Send 12 bits to EEPROM.
high EE_CS 'Select EEPROM.
gosub eeout 'Send the opcode/address.
let ShifReg = info * 16 'Move bit 7 to bit 11.
let clocks = 8 'Eight data bits.
gosub eeout 'Send the data.
low EE_CS 'Deselect EEPROM.
gosub edisbl 'Write Protect.
return
' This sub-procedure reads a byte from the EEPROM.
' ‘Data’ is read from ‘address’ on ‘page’
eeread:
let ShifReg = $C00 'Get the read opcode.
let ShifReg = ShifReg | w4 'OR in the address bits.
let clocks = 12 'Send 12 bits to the EEPROM.
high EE_CS 'Chip select on.
gosub eeout 'Send the opcode/address.
gosub eein 'Receive the byte.
low EE_CS 'Deselect the EEPROM.
return
' Here are the internal sub-procedures that are called for by the eewrite and eeread subprocedures.
eenabl:
let ShifReg = $980 'Get the write-enable opcode.
high EE_CS 'Chip select on.
let clocks = 12 'Send 12 bits to EEPROM.
gosub eeout 'Send the opcode.
low EE_CS 'Deselect the EEPROM.
return
edisbl:
let ShifReg = $800 'Get the write-disable opcode.
high EE_CS 'Chip select on.
let clocks = 12 'Send 12 bits to EEPROM.
gosub eeout 'Send the opcode.
low EE_CS 'Deselect the EEPROM.
return
eein:
let info = 0 'Clear the data byte.
for i = 1 to 8 'Prepare to get 8 bits.
let info = info * 2 'Shift EEdata to the left
high EE_CLK 'Data valid on rising edge.
let info = info + EE_D_I 'Move data to 1st of variable.
low EE_CLK 'End of clock pulse.
next I 'Get another bit.
return
eeout:
for i = 1 to clocks 'Number of bits to shift out.
let EE_D_I = ShifReg / $800 'Get bit 12 of ShifReg.
pulsout EE_CLK, 10 'Output a brief clock pulse.
let ShifReg = ShifReg * 2 'Shift register to the left.
next i 'Send another bit.
return
As I began writing my program I began to run into a problem that is now becoming important. One of the things I want to record are temperature values. To work with temperature I had to use data "word" because a byte was too small. To use the word I also created a symbol called info2 (w1). All of the EEPROM read/write sub-procedures are only looking for the info symbol (which is a "byte" value). How can I resolve these conflicts so that I can also read/write the temperature values to EEPROM? If more information is neccesary to help me, please let me know. Below is the basic code that I am using:
symbol EE_D_I = pin0 'EEPROM data pin (input 0)
symbol EE_D_O = 0 'EEPROM data pin (output 0)
symbol EE_CLK = 1 'EEPROM clock pin (output 1)
symbol EE_CS = 2 'EEPROM chip select pin (output 2)
symbol info = b4 'Data byte for heater status
symbol i = b5 'Scratchpad counter
symbol ShifReg = w3 'Scratchpad shift register
symbol address = b8 'EEPROM address
symbol page = b9 'EEPROM page
symbol clocks = b11 'Scratchpad clock counter
symbol info2 = w1 'Data word for temperature
for address = 0 to 59
readadc 1, info
If info = 255 Then
goto heaton
Else
goto heatoff
endif
CONTINUE:
readadc10 2, info2 'This reads the temperature of the heater box.
let page = 1
gosub eewrite
let info2 = info2 * 100 - 50508 / 43
serout 7, T2400, (254, 192, "Temp. = ", #info2, " ", %11011111, "F")
for b0 = 1 to 2 '1 x 60 second delay
pause 60000
next b0
next address
end
heaton:
serout 7, T2400, (254, 128, "Heaters are: ON ") 'This reads the state of the heater circuit.
let page = 0
gosub eewrite
goto CONTINUE
heatoff:
serout 7, T2400, (254, 128, "Heaters are: OFF") 'This reads the state of the heater circuit.
let page = 0
gosub eewrite
goto CONTINUE
' ***Below are the standard sub-procedures to read/write to EEPROM.
' ***There will be a comment above each procedure to designate it’s purpose.
' This sub-procedure writes a byte to the EEPROM
' ‘Data’ is written to ‘address’ on ‘page’
eewrite:
gosub eenabl 'Enable.
let ShifReg = $A00 'Get the write opcode.
let ShifReg = ShifReg | w4 'OR in the address bits.
let clocks = 12 'Send 12 bits to EEPROM.
high EE_CS 'Select EEPROM.
gosub eeout 'Send the opcode/address.
let ShifReg = info * 16 'Move bit 7 to bit 11.
let clocks = 8 'Eight data bits.
gosub eeout 'Send the data.
low EE_CS 'Deselect EEPROM.
gosub edisbl 'Write Protect.
return
' This sub-procedure reads a byte from the EEPROM.
' ‘Data’ is read from ‘address’ on ‘page’
eeread:
let ShifReg = $C00 'Get the read opcode.
let ShifReg = ShifReg | w4 'OR in the address bits.
let clocks = 12 'Send 12 bits to the EEPROM.
high EE_CS 'Chip select on.
gosub eeout 'Send the opcode/address.
gosub eein 'Receive the byte.
low EE_CS 'Deselect the EEPROM.
return
' Here are the internal sub-procedures that are called for by the eewrite and eeread subprocedures.
eenabl:
let ShifReg = $980 'Get the write-enable opcode.
high EE_CS 'Chip select on.
let clocks = 12 'Send 12 bits to EEPROM.
gosub eeout 'Send the opcode.
low EE_CS 'Deselect the EEPROM.
return
edisbl:
let ShifReg = $800 'Get the write-disable opcode.
high EE_CS 'Chip select on.
let clocks = 12 'Send 12 bits to EEPROM.
gosub eeout 'Send the opcode.
low EE_CS 'Deselect the EEPROM.
return
eein:
let info = 0 'Clear the data byte.
for i = 1 to 8 'Prepare to get 8 bits.
let info = info * 2 'Shift EEdata to the left
high EE_CLK 'Data valid on rising edge.
let info = info + EE_D_I 'Move data to 1st of variable.
low EE_CLK 'End of clock pulse.
next I 'Get another bit.
return
eeout:
for i = 1 to clocks 'Number of bits to shift out.
let EE_D_I = ShifReg / $800 'Get bit 12 of ShifReg.
pulsout EE_CLK, 10 'Output a brief clock pulse.
let ShifReg = ShifReg * 2 'Shift register to the left.
next i 'Send another bit.
return