cheehow
Joined: 15 Sep 2010 Posts: 28
|
|
Posted: Thu Sep 23, 2010 1:29 am |
|
|
I have modified my master code ...... please help me to check whether my master code have any problem or not ??
++++++++++++++++++++++++
cheehow:
No double posts !
Your other post:
http://www.ccsinfo.com/forum/viewtopic.php?t=43620
-- Forum Moderator
++++++++++++++++++++++++
master code :
Code:
#include "C:\Users\Tan Chee How\Desktop\testing I2C\master.h"
#define Device_SDA PIN_C3
#define Device_SCL PIN_C4
#USE I2C (MASTER, SDA=Device_SDA, SCL=Device_SCL)
#USE fast_io(C)
#USE standard_io(B)
#USE fast_io(D)
int x;
BYTE Data;
void main()
{
SET_TRIS_C(0X00);
SET_TRIS_D(0XFF);
OUTPUT_B(0X00);
WHILE(TRUE)
{
for(x=0x00; x<0x0A; x++)
{
i2c_start();
i2c_write(0xA0);
i2c_write(x);
i2c_write(0X0A-x);
i2c_stop();
delay_ms(100);
i2c_start();
i2c_write(0xA1);
Data=i2c_read(0);
i2c_stop();
delay_ms(100);
}
if(INPUT(PIN_D1))
OUTPUT_HIGH(PIN_B6);
delay_ms(500);
OUTPUT_LOW(PIN_B6);
delay_ms(500);
OUTPUT_HIGH(PIN_B7);
delay_ms(500);
OUTPUT_LOW(PIN_B7);
}
}
The slave code is taken from the ccs c compiler example one (EX_SLAVE.C) and modified a little bit.
Code:
#include "C:\Users\Tan Chee How\Desktop\testing I2C\slave.h"
#define Device_SDA PIN_C3
#define Device_SCL PIN_C4
#use i2c (slave, SDA= Device_SDA, SCL=Device_SCL,address=0xA0, FORCE_HW)
#INT_SSP
BYTE address, buffer[0x10];
void ssp_interupt ()
{
BYTE incoming, state;
state = i2c_isr_state();
if(state < 0x80)
{
incoming = i2c_read();
if(state == 1)
address = incoming;
if(state == 2)
buffer[address] = incoming;
}
if(state == 0x80)
{
i2c_write(buffer[address]);
}
}
void main ()
{
SET_TRIS_C(0XFF);
SET_TRIS_B(0X00);
SET_TRIS_D(0X00);
OUTPUT_B(0X00);
enable_interrupts(GLOBAL);
enable_interrupts(INT_SSP);
while (TRUE) {}
}
Please help me to check whether I have any problem for my code or not ... thxs for checking =) |
|