PDA

View Full Version : eeprom 40 bytes



mike12
- 2nd January 2006, 14:28
Hello the program cleans the data in the eeprom, but it filled all the eeprom. The values which I want to write are a temporary file of 40 bytes, Which are to be written. I join an example of Merci writing


'********************Initialize USART*******************************************
DEFINE HSER_RCSTA 90h ' Set receive register to receiver enabled
DEFINE HSER_TXSTA 24h ' Set transmit register to transmitter enable
DEFINE HSER_BAUD 9600 ' Set baud rate

data_array VAR BYTE
addr VAR WORD
i VAR BYTE ' Loop counter

DEFINE I2C_SLOW 1
DEFINE I2C_SCLOUT 1
SCL var PORTA.0 ' Clock pin
SDA var PORTA.1 ' Data pin
'********************** RAM Assignments and Variables **************************
CounterA var byte ' General purpose Variable
CounterB var byte ' General purpose Variable
CounterC var byte ' General purpose Variable
CounterD var byte ' General purpose Variable
'*********************** Data **************************************************
MagData var byte [40] ' Data Array
'***********************Program Constants***************************************
MagMax con 40 ' Max Buffer Size
'**************************Save byte to main buffer and increment pointer*******
MagData(CounterB)=CounterD ' Good or Bad, Save the data byte to buffer
CounterC=CounterC^CounterD ' Add received byte for LRC Check at end
CounterB=CounterB+1 ' Increment to next byte in Data buffer
'**************************Spot-check the data on the terminal screen **********
For addr = 0 To 65535 Step 64 ' Store $00 to all locations (for testing)
I2CWrite sda,scl,$A0,addr,[STR MAGDATA\40] ' Send a 64-byte page
HSerout ["."] ' Indicate progress
Pause 10 ' Pause 10mS to let the write complete
Next addr
i = 0 ' Spot-check the data on the terminal screen
Hserout [10,13, 10,13, "checking", 10,13]
For addr = 0 to 65535 Step 257 ' read every 257th address
i = i + 1
I2CRead sda, scl, $A0, addr, [data_array[0]] ' Read a single byte from memory
Hserout [HEX2 data_array[0], " "] ' To terminal with hex value
If (i & $0007) = 0 Then ' Break it into organized lines
Hserout [10,13] ' 8 locations to a line
Endif
Next addr ' Go get the next test
Pause 1000
Goto ReadReadyLoop
'************************** End*********************************************** *
End