IIC总线的都可以用,注意要是用在AT24C系列的EEPROM 是要添加一定的延时程序~
比较简洁的程序:
#define uchar unsigned char
#define uint unsigned int
#define IIC_READ 0XA1 //定义读指令
#define IIC_WRITE 0XA0 //定义写指令
#define NOP _nop_()
//===============================
sbit SDA=P2^7; //THE SDA BIT IS PORT 2 BIT 7//
sbit SCL=P2^6; //THE SCL BIT IS PORT 2 BIT 6
sbit WP=P2^5;
sbit test=P1^0;
//===============================
//define a bit_operation byte to use in shift operation
//use this mode can achieve high operation speed uchar bdata bbyte;
//定义位操作用数组,采用此方法可提高位操作速度
sbit a0=bbyte^0;
sbit a1=bbyte^1;
sbit a2=bbyte^2;
sbit a3=bbyte^3;
sbit a4=bbyte^4;
sbit a5=bbyte^5;
sbit a6=bbyte^6;
sbit a7=bbyte^7;
//========================================
bit IFACK; //record the SDA state to confirn if ACK has happened
bit NO_ACK; //no ack flagbit BUS_FAULT; //bus fault flag
//========================