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
Bookmarks