CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

I2C difference 4.014 -->4.032-->

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jaska



Joined: 30 Aug 2008
Posts: 1

View user's profile Send private message

I2C difference 4.014 -->4.032-->
PostPosted: Sat Aug 30, 2008 3:22 am     Reply with quote

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);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Aug 30, 2008 12:02 pm     Reply with quote

Post a test program that calls these functions. See the example code
below. The program below has the following output:
Quote:

Start
FF FF
55 AA

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);
}   
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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