![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
jaska
Joined: 30 Aug 2008 Posts: 1
|
I2C difference 4.014 -->4.032--> |
Posted: Sat Aug 30, 2008 3:22 am |
|
|
I have code, working very well in 4.014.
After updating dont work.
What is changed?
I use PIC18F458.
I have already programmed memory, program cant read anything from
memory.... Maybe dont write too...
Jaska
Code: | #ifndef EEPROM_SDA
#define EEPROM_SDA PIN_B1
#define EEPROM_SCL PIN_B0
#endif
#use i2c(master, sda=EEPROM_SDA, scl=EEPROM_SCL)
#define EEPROM_ADDRESS LONG int
#define EEPROM_SIZE 65535
void init_ext_eeprom()
{
output_float(EEPROM_SCL);
output_float(EEPROM_SDA);
}
void write_ext_eeprom(long int address, BYTE data)
{
short int status;
i2c_start ();
i2c_write (0xa0);
i2c_write (address>>8);
i2c_write (address);
i2c_write (data);
i2c_stop ();
i2c_start ();
status = i2c_write (0xa0);
WHILE (status == 1)
{
i2c_start ();
status = i2c_write (0xa0);
}
}
BYTE read_ext_eeprom(long int address)
{
BYTE data;
i2c_start ();
i2c_write (0xa0);
i2c_write (address>>8);
i2c_write (address);
i2c_start ();
i2c_write (0xa1);
data = i2c_read (0);
i2c_stop ();
return (data);
} |
|
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Aug 30, 2008 12:02 pm |
|
|
Post a test program that calls these functions. See the example code
below. The program below has the following output:
Code: | #include <18F452.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#define EEPROM_SDA PIN_B1
#define EEPROM_SCL PIN_B0
#include <24256.c>
//=====================================
void main()
{
printf("Start\n\r");
init_ext_eeprom();
// Erase the first two bytes/
write_ext_eeprom(0, 0xFF);
write_ext_eeprom(1, 0xFF);
// Read them. They should be 0xFF.
printf("%X ", read_ext_eeprom(0));
printf("%X", read_ext_eeprom(1));
printf("\n\r");
// Write 0x55 and 0xAA to the first two bytes.
write_ext_eeprom(0, 0x55);
write_ext_eeprom(1, 0xAA);
// Read and display the first two bytes.
printf("%X ", read_ext_eeprom(0));
printf("%X", read_ext_eeprom(1));
printf("\n\r");
while(1);
} |
|
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|