Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

ccs c writing to EEPROM example

Status
Not open for further replies.

mcjames

Newbie level 1
Joined
Sep 24, 2008
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,286
ext_eeprom_ready

Hi new here, was wondering if anyone could help me out:

I am using an example file by ccs for the driver. This is it:

Code:
#ifndef EEPROM_SDA
#define EEPROM_SDA  PIN_C4
#define EEPROM_SCL  PIN_C3

#endif


#use i2c(master, sda=EEPROM_SDA, scl=EEPROM_SCL)

#define EEPROM_ADDRESS long int
#define EEPROM_SIZE    2048
//This is line 52
void init_ext_eeprom() {
   output_float(EEPROM_SCL);
   output_float(EEPROM_SDA);
}

BOOLEAN ext_eeprom_ready() {
   int1 ack;
   i2c_start();            // If the write command is acknowledged,
   ack = i2c_write(0xa0);  // then the device is ready.
   i2c_stop();
   return !ack;
}

void write_ext_eeprom(long int address, BYTE data) {
   while(!ext_eeprom_ready());
   i2c_start();
   i2c_write((0xa0|(BYTE)(address>>7))&0xfe);
   i2c_write(address);
   i2c_write(data);
   i2c_stop();
}


BYTE read_ext_eeprom(long int address) {
   BYTE data;

   while(!ext_eeprom_ready());
   i2c_start();
   i2c_write((0xa0|(BYTE)(address>>7))&0xfe);
   i2c_write(address);
   i2c_start();
   i2c_write((0xa0|(BYTE)(address>>7))|1);
   data=i2c_read(0);
   i2c_stop();
   return(data);
}

Basically I have to change PIN_C4 and PIN_C3 to numbers mentioned in the header... once I've done that, I only get one error (as opposed to 4).

The error is

Code:
*** Error 128 "C:\Documents and Settings\James\My Documents\EngsclLP\WORK\PIC\Projects\EXTEEPROM\2416.C" Line 52(1,9): A #DEVICE required before this line
      1 Errors,  0 Warnings.


If anyone has any suggestions about how to fix this I would be grateful.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top