PDA

View Full Version : button ,eeprom,read



mike12
- 31st December 2005, 11:19
Hello I want to modify this routine of reading and writing of an external eeprom 24lc515 i2c to write 40 bytes, and to repeat this operation with each time the buffer contains the 40 bytes (MagMax idiot 40) which will be has to write in the eeprom. The reading of the eeprom and sends it data read towards on the port série.Pour a Série connection and to visualize with hyper final. How to make to activate the reading of the eeprom and the transmission of the data towards the port series, once the peak to program and place on the circuit? Does a pushbutton activate the reading and sends it on the port series? Pin SHORT PROP I am beginner and can you help me has to correct this source code if there are errors.

I thank you Merci Mike

I2C_OUT VAR BYTE[ ] '
GOSUB I2CTX
I2CTX: ' Transmit I2C Routine
GOSUB I2C_Stop ' Issue Stop Command
RETURN



'********************************** VAR ************************************************** **

'( MagMax con 40' Max Buffer Size )

addr VAR WORD ' Memory Address
data_array VAR BYTE '
MagMax VAR BYTE[40] ' Data array with location for checksum
i VAR BYTE ' Loop counter


'****************************** button ************************************************** ******

SO con 0 ' Define serial output pin
B con 5 ' Define Button input pin
N2400 con 4 ' Set serial mode
B0 var byte

B0 = 0 ' Zero Button Working Buffer
loop: Button B,1,10,5,B0,0,notp ' Check Button (Skip if Not Pressed)
Serout SO,N2400,["Press",13,10] ' Indicate Button Pressed
notp: Serout SO,N2400,[#B0,13,10] ' Show Working Variable
Pause 100 ' Visual Pause
Goto loop ' Foreve

'******************************* I2CWrite ************************************************** *****

For addr = 0 To 65535 Step 64 ' Store $00 to all locations (for testing)
I2CWrite sda,scl,$A0,addr,[STR MagMax\64] ' Send a 64-byte page
HSerout ["."] ' Indicate progress
Pause 10 ' Pause 10mS to let the write complete
Next addr

'********************************* I2CRead ************************************************** ***

' Spot-check the data on the terminal screen
i = 0 '
Hserout [10,13, 10,13, "checking", 10,13] '

For addr = 0 to 65535 Step 257 '? ' read every ? th 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

End