cipi-cips
Member level 4
- Joined
- Jun 30, 2008
- Messages
- 76
- Helped
- 2
- Reputation
- 4
- Reaction score
- 1
- Trophy points
- 1,288
- Activity points
- 1,867
Hello
Can someone help with my code, I am just trying to write something in the 24LC32 serial EEPROM with i2c protocol.
I have studied datasheat both for memory and PIC controller. I am using 18F4550.
Compiler is C18 from microchip.
Here is my little code:
and this does not work ( any Help ?
Can someone help with my code, I am just trying to write something in the 24LC32 serial EEPROM with i2c protocol.
I have studied datasheat both for memory and PIC controller. I am using 18F4550.
Compiler is C18 from microchip.
Here is my little code:
Code:
#include <pic18f4550.h>
#include <i2c.h>
#define OUT PORTDbits.RD7
void main (main)
{
TRISDbits.TRISD7 = 0;
OpenI2C(MASTER, SLEW_OFF);
SSPADD = 0x31; // determinate baud rate (20Mhz xtal, and 100Khz rate), with this formula I got ((Fos/4)/100Khz)-1.
StartI2C();
IdleI2C();
WriteI2C(0xA0); //this is control byte
IdleI2C();
WriteI2C(0x01); //write at this address
IdleI2C();
WriteI2C(0xFF); //write data 255
IdleI2C();
StopI2C();
StartI2C();
IdleI2C();
WriteI2C(0xA1); //this is control byte
IdleI2C();
number = Read2C(); //read
IdleI2C();
StopI2C();
if (number == 255)
{
OUT = 1;
}
else
{
OUT = 0;
}
while(1);
}
and this does not work ( any Help ?