代码:
通过IIC总线写入24C04模块
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define AddWr24c04 0xa0
#define AddRd24c04 0xa1
#define delay4us(){_nop_();_nop_();_nop_();_nop_();_nop_();};
sbit SDA=P1^1;
sbit SCL=P1^0;
bit ack;
uchar tab[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void STARTI2C()
{
SDA=1;
_nop_();
SCL=1;
delay4us();
SDA=0;
delay4us();
SCL=0;
_nop_();
_nop_();
}
void STOPI2C()
{
SDA=0;
_nop_();
SCL=1;
delay4us();
SDA=1;
delay4us();
}
uchar rcvbyte()
{
uchar retc,BitCnt;
retc=0;
SDA=1;
for(BitCnt=0;BitCnt<8;BitCnt++)
{
_nop_();
SCL=0;
delay4us();
SCL=1;
_nop_();
_nop_();
retc=retc<<1;
if(SDA==1)
retc=retc+1;
_nop_();
_nop_();
}
SCL=0;
_nop_();
_nop_();
return(retc);
}
void sendbyte(uchar c)
{
unsigned ch