| ??? 10/07/08 17:37 Read: times |
#158910 - The code Responding to: ???'s previous message |
Hi,
These are the codes. I changed these files only. I am making another board with mcu and e2prom only. I'm going to try to communicate with e2prom. // Global Var
static unsigned char status;
static unsigned char i2cVetor[30];
unsigned int IndexRx;
unsigned int IndexTx;
// callback.c
/***********************************************************************
MODULE: I2C Callback
VERSION: 1.03
CONTAINS: Routines for controlling the I2C Peripheral on the Philips
P89LPC952
COPYRIGHT: Embedded Systems Academy, Inc. - www.esacademy.com
LICENSE: May be freely used in commercial and non-commercial code
without royalties provided this copyright notice remains
in this file and unaltered
WARNING: IF THIS FILE IS REGENERATED BY CODE ARCHITECT ANY CHANGES
MADE WILL BE LOST. WHERE POSSIBLE USE ONLY CODE ARCHITECT
TO CHANGE THE CONTENTS OF THIS FILE
GENERATED: On "Sep 26 2008" at "22:08:21" by Code Architect 2.12
***********************************************************************/
#include "i2c.h"
#include "i2c_callback.h"
// MASTER CALLBACK FUNCTIONS
/***********************************************************************
DESC: gets the next byte to be transmitted when operating as
a master
RETURNS: byte to transmit (byte a ser transmitido)
************************************************************************/
unsigned char i2c_master_getbyte(unsigned int bytenum) // number of the byte in this transfer // (0 = first byte)
{
// insert code here
return i2cVetor[bytenum];
} // i2c_master_getbyte
/***********************************************************************
DESC: processes the bytes received when operating as a master
RETURNS: Nothing
************************************************************************/
void i2c_master_receivedbyte(unsigned int rbytenum, unsigned char value) // number of the byte in this transfer // (0 = first byte) // value of byte received
{
// insert code here
i2cVetor[rbytenum]=value;
} // i2c_master_receivedbyte
/***********************************************************************
DESC: determines if a byte will be the last one to be
transmitted when operating as a master
called before i2c_master_getbyte for each byte
RETURNS: return 1 if the byte will be the last one to transmit
return 0 if the byte will not be the last one to transmit
************************************************************************/
unsigned char i2c_master_islasttxbyte(unsigned int tbytenum) // number of the byte in this transfer // (0 = first byte)
{
// insert code here
if(tbytenum==(IndexTx-1))
return(1);
else
return(0);
} // i2c_master_islasttxbyte
/***********************************************************************
DESC: determines if a byte will be the last one to be
received when operating as a master
called before i2c_master_receivedbyte for each byte
RETURNS: return 1 if the byte will be the last one to receive
return 0 if the byte will not be the last one to receive
************************************************************************/
unsigned char i2c_master_islastrxbyte(unsigned int rlbytenum) // number of the byte in this transfer // (0 = first byte)
{
// insert code here
if(rlbytenum==(IndexRx-1))
return(1);
else
return(0);
} // i2c_master_islastrxbyte
/***********************************************************************
DESC: called when an I2C transfer is finished
mi2cstatus may be read to determine if the transfer was
successful (I2C_OK) or failed (I2C_ERROR)
RETURNS: Nothing
************************************************************************/
void i2c_transfer_finished(void)
{
// insert code here
IndexTx=0;
IndexRx=0;
uart_transmit(mi2cstatus);
} // i2c_transfer_finished
// main.c
#define AT24C256 0xA0
#define TRUE 1
#define FALSE 0
#include "P89LPC95x.h"
#include "variaveis.c"
#include "uart.c"
#include "i2c_callback.c"
#include "i2c.c"
void main(void)
{
unsigned int index;
uart_init();
i2c_init(AT24C256, 0);
EA=1;
IndexRx=30;
/* i2c_transmit(0x00);
while (i2c_getstatus() & I2C_BUSY);
if (i2c_getstatus() == I2C_OK)
i2c_transmit(0x30);
while (i2c_getstatus() & I2C_BUSY);
if (i2c_getstatus() == I2C_OK)*/
i2c_receive(AT24C256);
while(1);
}
Thanks |



