PIC16F877 and EEPROM FM24C16A
Hello everybody,
I do not know if it is a hardware problem or software
I need help on solving an I2C problem
I am new to Pics as i am new to Pic Basic Pro (5 days only)
I got from rentron the flash-lab77 kit with pic basic pro and the rest.
I tryed first the the simple example in the sample and did not work. B1 and B2 returned 0 all the time.
DEFINE LOADER_USED 1 ' Always include this when using the boot-loader
DEFINE OSC 20 ' And this too since your board runs at 20MHz
Include "modedefs.bas" ' Include serial modes
SO VAR PORTB.1 ' Define serial output pin
DPIN var PORTC.0 ' I2C data pin
CPIN var PORTC.1 ' I2C clock pin
BA0 var byte
BA1 var byte
BA2 var byte
For BA0 = 0 To 15 ' Loop 16 times
I2CWRITE DPIN,CPIN,$A0,BA0,[BA0] ' Write each location's address to itself
Pause 10 ' Delay 10ms after each write
Next BA0
loop: For BA0 = 0 To 15 step 2 ' Loop 8 times
I2CREAD DPIN,CPIN,$A0,BA0,[BA1,BA2] ' Read 2 locations in a row
Serout SO,16468 ,[#BA1," ",#BA2," "] ' Print 2 locations
Next BA0
Serout SO,16468,[10] ' Print linefeed
Goto loop
My problems are two , related to the i2c commands, if i can get it first working:
1) First one is that i would like to write on the eeprom some decimal
numbers of 4 digits each. Let say A=1234 and B=5678
I would like with one i2cwrite command to put this data in the eeprom.
The next step is to retrieve this data as decimal numbers too , so i can display it on an serial LCD ( i have figured out the display part and it works).
I wrote this, but does not work
a var word
b var word
a=1234
b=5678
I2CWRITE PORTC.0,PORTC.1,$a0,0,[A,B]
I2Cread PORTC.0,PORTC.1,$a0,0,[A,B]
It will read only one byte from the word.
2) My second problem is to write some ASCII text on the eeprom and be able to read it back . lets say i want to write
"this is text one on eeprom" , then, i would like to be able to read it back so i can display it on the lcd.
I would appreciate if any of you can help me, and a small piece of code as an example it will be a jackpot.
Just keep in mind that i am a complete newbee and what it is obvious for you it might be a mistery for me.
Thank you very much for reading my postl and i hope to hear soon from you
Ion George
Pic16F877 and Eeprom 24LC256 and 24LC16B
Hello, i am facing the same problem when i try to store data to the Eeprom. i only get back 0 when i read from the Eeprom. I had done the pull up resistor for Sda and Scl but the result still the same. The data that i try to store is from 0-255.
DEFINE OSC 20 ' 20MHz crystal
DEFINE HSER_RCSTA 90h ' enable serial port and
DEFINE HSER_TXSTA 24h ' enable transmit register
DEFINE HSER_BAUD 19200 ' 19200 baud rate
DEFINE HSER_SPBRG 64 ' 19200 baud rate
DEFINE HSER_CLROERR 1 ' automatically close
DEFINE I2C_SLOW 1
'************************************************* *******************
'Declaration of I/O pins and Variables
'************************************************* *******************
scl VAR PORTC.3 ' I2C clock pin
sda VAR PORTC.4 ' I2C data pin
w VAR WORD
a VAR BYTE
counter VAR BYTE
char VAR BYTE ' Storage for serial character
char2 VAR BYTE ' Storage for serial character
char3 VAR BYTE
add VAR BYTE
value VAR BYTE[80]
value2 VAR BYTE[80]
'************************************************* *******************
a = 0
counter = 0
add = 1block1 CON %10100000
store3: HSerin [STR value\60]
Low PORTA.5
char = value[a]
LCDOut $fe, 1
LCDOut #char
I2CWrite PORTC.4,PORTC.3,$a1,add,[char]
Pause 40
IF a == 60 Then
GoTo baca
Else
a = a + 1
add = add + 1
GoTo store3
EndIF
'Pause 10000
High PORTB.1
add = 1
baca: LCDOut "Read cycle"
Pause 3000
I2CRead PORTC.4,PORTC.3,$a0,add,[char2]
Pause 3000
LCDOut $fe, 1
LCDOut #char
Pause 2000
IF a == 60 Then
GoTo dump
Else
a = a + 1
add = add + 1
GoTo baca
EndIF
Above is part of my program that i had wrote. I can't find out what is the problem. Can some one help me to correct it?