Good day
I'm using a PIC16F877 with a 24LC512 EEPROM.
All I do is write from 0 to 23 to the EEPROM and Read it back and then send it through RS232 to the PC.
Here is my PB Code
<hr>
<pre>
Include "modedefs.bas"
DEFINE OSC 4 ' Set the Xtal frequency to 20mHz
DEFINE LOADER_USED 1 ' bootloader
DEFINE HSER_RCSTA 90h ' enable serial port,
' enable continuous receive
define HSER_TXSTA 24h ' enable transmit,
' BRGH=1
define HSER_SPBRG 103 ' set baudrate to 2400
DEFINE HSER_CLOERR 1 ' automatic clear overrun error
RCIF VAR PIR1.5 ' Receive interrupt flag (1=full , 0=empty)
TXIF VAR PIR1.4 ' Transmit interrupt flag (1=empty, 0=full)
SerialData var byte
SWITCHPIN VAR PORTD.1
SCL var PORTC.3 ' Clock pin
SDA var PORTC.4 ' Data pin
B0 var word ' Address
B1 var byte ' Data 1
B2 var byte ' Data 1
i var word
Main:
'TRISC = %10000000 ' PORTC.7 is the RX input, PORTC.6 is the TX output
TRISC.7 = 1
TRISC.6 = 0
pause 10 'safe start-up delay
high SWITCHPIN
ADCON1 = 7 ' Set PORTA and PORTE to digital
for i = 0 to 23
B2 = i
I2CWRITE SDA,SCL,$A0,i,[B2] ' Write each location
Pause 10 ' Delay 10ms after each write
hserout ["Write=",#B2,"|"]
next i
loop:
for i = 0 to 23
I2CREAD SDA,SCL,$A0,i,[B1] ' Read 2 locations in a row
hserout ["Read=",#B1,"|"]
next i
End
</pre>
<hr>
Somehow the last item "23" is red back from the EEPROM as "2"
Here is that data I received back from the Pic?
<hr>
Write=0|Write=1|Write=2|Write=3|Write=4|Write=5|Wr ite=6|Write=7|Write=8|Write=9|Write=10|Write=11|Wr ite=12|Write=13|Write=14|Write=15|Write=16|Write=1 7|Write=18|Write=19|Write=20|Write=21|Write=22|Wri te=23|Read=0|Read=1|Read=2|Read=3|Read=4|Read=5|Re ad=6|Read=7|Read=8|Read=9|Read=10|Read=11|Read=12| Read=13|Read=14|Read=15|Read=16|Read=17|Read=18|Re ad=19|Read=20|Read=21|Read=22|Read=2
<hr>
Bookmarks