/**************************************************
功能描述:
PC端发送3个数据 n0,n1,n2.
n0=0,写,将n1写入n2地址中
n0=1,读,读出n1地址中的数据,n2不起作用,但必须有
收到一个字节后,将其地址值显示在数码管第1、2位上,数值显示在第5、6位上
读出一个字节后,将其地址值显示在数码管第1、2位上,读出的值显示在第5、6位上
;**************************************************/
#define uchar unsigned char
#define uint unsigned int
#define Slaw 0x0a; //写命令字
#define Slar 0xa1; //读命令字
#include ""
#include ""
sbit Scl=P2^1; //串行时钟
sbit Sda=P2^0; //串行数据
bit Rec; //接收到数据的标志
uchar RecBuf[3]; //接收缓冲区
#define Hidden 0x10; //消隐字符在字形码表中的位置
sbit we=P2^7;
sbit du=P2^6;
uchar code dispbit[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
uchar code disptab[]={0x3f,0x6,0x5b,0x4f,0x66,
0x6d,0x7d,0x27,0x7f,0x6f,0x77,0x7c,0x39,0x5e,
0x79,0x71,0x0};
uchar DispBuf[6];
uchar code TH0Val=(65535-3000)/256;
uchar code TL0Val=(65535-3000)%256;
uchar code th1=0xfd;
uchar code tl1=0xfd;
//以下是中断程序,用于显示
void timer0() interrupt 1
{
static uchar count;
uchar tmp;
P0|=0x3f;
we=1;
tmp=dispbit[count];
P0&=tmp;
we=0;
du=1;
tmp=DispBuf[count];
tmp=disptab[tmp];
P0=tmp;
du=0;
count++;
if(count==6)
count=0;
TH0=TH0Val;
TL0=TL0Val;
}
/*发送起始条件*/
void Start(void) /*起始条件*/
{
Sda=1;
Scl=1;
_nop_ ();
_nop_ ();
_nop_ ();
_nop_ ();
Sda=0;
_nop_ ();
_nop_ ();
_nop_ ();
_nop_ ();
}
void Stop(void) /*停止条件*/
{
Sda=0;
Scl=1;
_nop_ ();
_
at24c02应用程序 来自淘豆网m.daumloan.com转载请标明出处.