为什么把void write_add(uchar,uchar)的子涵数调用到中断函数里会有警告,请大神们跟小弟讲解讲解。感恩,感恩
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit wei=P2^0;
sbit duan=P3^7;
sbit scl=P1^5;
sbit sda=P3^6;
uchar temp,aa,ge,shi,bai;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void delay(uint);//延时函数
void init();//初始化函数
void xianshi();//数码管显示函数
void delay1();
uchar read_byte();//读字节
void write_byte(uchar);//写数据
void respond();//应答信号
void stop();//停止信号
void start();//起始信号
void write_add(uchar,uchar);
uchar read_add(uchar);
void main()
{
init();
delay(5);
write_add(1,3);
while(1);
{
if(aa==20)
{
aa=0;
temp++;
bai=temp/100;
shi=temp%100/10;
ge=temp%10;
}
xianshi();
}
}
void delay(uint z)//1ms延时
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void init()
{
scl=1;
delay(5);
sda=1;
delay(5);
read_add(1);
TMOD=0x01;
TH0=(65536-46080)/256;
TL0=(65536-46080)%256;
EA=1;
ET0=1;
TR0=1;
aa=0;
}
void
time0() interrupt 1
{
TH0=(65536-46080)/256;
TL0=(65536-46080)%256;
aa++;
}
void xianshi()
{
bai=temp/100;
shi=temp%100/10;
ge=temp%10;
duan=1;
P0=table[bai];
duan=0;
P0=0xff;
wei=1;
P0=0xfb;
wei=0;
delay(5);
duan=1;
P0=table[shi];
duan=0;
P0=0xff;
wei=1;
P0=0xfd;
wei=0;
delay(5);
duan=1;
P0=table[ge];
duan=0;
P0=0xff;
wei=1;
P0=0xfe;
wei=0;
delay(5);
}
void start()//起始信号
{
scl=1;
delay1();
sda=1;
delay1();
sda=0;
delay1();
}
void stop()//停止信号
{
scl=1;
delay1();
sda=0;
delay1();
sda=1;
delay1();
}
void respond()//应答信号
{
uchar i;
scl=1;
delay1();
while((sda==1)&&(i<250))
i++;
scl=0;
delay1();
}
void write_byte(uchar date)//写数据
{
uchar temp1,i;
temp1=date;
for(i=0;i<8;i++)
{
scl=0;
temp1=temp1<<1;
delay1();
sda=CY;
delay1();
scl=1;
delay1();
}
sda=1;
delay1();
}
uchar read_byte()//读字节
{
uchar i,j,k;
for(i=0;i<8;i++)
{
scl=0;
delay1();
if(sda==1)
j=1;
else
j=0;
k=(k<<1)|j;
delay1();
scl=1;
delay1();
}
sda=1;
delay1();
return k;
}
void write_add(uchar address,uchar date)
{
start();
write_byte(0xa0);
respond();
write_byte(address);
respond();
write_byte(date);
respond();
stop();
}
uchar read_add(uchar address)
{
uchar date;
start();
write_byte(0xa0);
respond();
write_byte(address);
respond();
start();
write_byte(0xa1);
respond();
date=read_byte();
stop();
return date;
}
void delay1()
{;;}
一周热门 更多>