单片机问题 急,高手指点指点
时间:10-02
整理:3721RD
点击:
错误提示: HDM.C(107): error C174: return-expression on void-function
错误的代码段:void read_byte(uchar date){
uchar i,k;
scl=0;
delay();
sda=1;
delay();
for(i=0;i<8;i--)
{
scl=1;
delay();
k=(k<<1)|sda;
scl=0;
delay();
}
delay();
return(k);
}
全部代码段:#include<reg52.h>#define uint unsigned int
#define uchar unsigned char
bit write=0;
sbit sda=P2^0;
sbit scl=P2^1;
sbit dula=P2^6;
sbit wela=P2^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f,
0x77,0x7c,0x39,0x5e,0x79,
0x71};
void delay()
{;;}
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void start() //启动信号
{
sda=1;
delay();
scl=1;
delay();
scl=0;
delay();
}
void stop()
{
sda=0;
delay();
scl=1;
delay();
sda=1;
delay();
}
void respons() //应答信号
{
uchar i;
scl=1;
delay();
while(sda=1&&(i<250))
i++;
scl=0;
delay();
}
void init()
{
sda=1;
delay();
scl=1;
delay();
}
void write_byte(uchar date)
{
uchar i,temp;
temp=date;
for(i=0;i<8;i--)
{
temp=temp<<1;
scl=0;
delay();
sda=CY;
delay();
scl=1;
}
scl=0;
delay();
sda=1;
delay();
}
void read_byte(uchar date)
{
uchar i,k;
scl=0;
delay();
sda=1;
delay();
for(i=0;i<8;i--)
{
scl=1;
delay();
k=(k<<1)|sda;
scl=0;
delay();
}
delay();
return(k);
}
void write_add(uchar address,uchar date)
{
start();
write_byte(0xa0);
respons();
write_byte(address);
respons();
write_byte(date);
respons();
stop();
}
uchar read_add(uchar address)
{
uchar date;
start();
write_byte(0xa0);
respons();
write_byte(address);
respons();
start();
write_byte(0xa1);
respons();
date=read_byte();
stop();
return date;
}
void display(uchar bai_c,uchar sh_c)
{
dula=1;
P0=table[bai_c];
dula=0;
P0=0xff;
wela=1;
P0=0x7e;
wela=0;
delayms(5);
dula=1;
P0=table[sh_c];
dula=0;
P0=0xff;
wela=1;
P0=0x7d;
wela=0;
delayms(5);
}
void main()
{
init();
sec=read_add(2);
if(sec>100)
{
sec=0;
}
TMOD=0x01;
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{
display(sec/10;sec%10);
if(write=1) //判断计时器是否计时到一秒
{
write=0;
write_add(2,sec); //在24c02的地址中写入数据sec
}
}
}
void to() interrupt 1
{
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
tcnt++;
if(tcnt>=20)
{
tcnt=0;
sec++;
write=1;
if(sec==100) //定时100,从零开始
{
sec=0;
}
}
} 用的是天祥tx-1c板,找了好久也不晓得问题答案,百度上说把void改成uchar 但还是不行
错误的代码段:void read_byte(uchar date){
uchar i,k;
scl=0;
delay();
sda=1;
delay();
for(i=0;i<8;i--)
{
scl=1;
delay();
k=(k<<1)|sda;
scl=0;
delay();
}
delay();
return(k);
}
全部代码段:#include<reg52.h>#define uint unsigned int
#define uchar unsigned char
bit write=0;
sbit sda=P2^0;
sbit scl=P2^1;
sbit dula=P2^6;
sbit wela=P2^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f,
0x77,0x7c,0x39,0x5e,0x79,
0x71};
void delay()
{;;}
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void start() //启动信号
{
sda=1;
delay();
scl=1;
delay();
scl=0;
delay();
}
void stop()
{
sda=0;
delay();
scl=1;
delay();
sda=1;
delay();
}
void respons() //应答信号
{
uchar i;
scl=1;
delay();
while(sda=1&&(i<250))
i++;
scl=0;
delay();
}
void init()
{
sda=1;
delay();
scl=1;
delay();
}
void write_byte(uchar date)
{
uchar i,temp;
temp=date;
for(i=0;i<8;i--)
{
temp=temp<<1;
scl=0;
delay();
sda=CY;
delay();
scl=1;
}
scl=0;
delay();
sda=1;
delay();
}
void read_byte(uchar date)
{
uchar i,k;
scl=0;
delay();
sda=1;
delay();
for(i=0;i<8;i--)
{
scl=1;
delay();
k=(k<<1)|sda;
scl=0;
delay();
}
delay();
return(k);
}
void write_add(uchar address,uchar date)
{
start();
write_byte(0xa0);
respons();
write_byte(address);
respons();
write_byte(date);
respons();
stop();
}
uchar read_add(uchar address)
{
uchar date;
start();
write_byte(0xa0);
respons();
write_byte(address);
respons();
start();
write_byte(0xa1);
respons();
date=read_byte();
stop();
return date;
}
void display(uchar bai_c,uchar sh_c)
{
dula=1;
P0=table[bai_c];
dula=0;
P0=0xff;
wela=1;
P0=0x7e;
wela=0;
delayms(5);
dula=1;
P0=table[sh_c];
dula=0;
P0=0xff;
wela=1;
P0=0x7d;
wela=0;
delayms(5);
}
void main()
{
init();
sec=read_add(2);
if(sec>100)
{
sec=0;
}
TMOD=0x01;
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{
display(sec/10;sec%10);
if(write=1) //判断计时器是否计时到一秒
{
write=0;
write_add(2,sec); //在24c02的地址中写入数据sec
}
}
}
void to() interrupt 1
{
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
tcnt++;
if(tcnt>=20)
{
tcnt=0;
sec++;
write=1;
if(sec==100) //定时100,从零开始
{
sec=0;
}
}
} 用的是天祥tx-1c板,找了好久也不晓得问题答案,百度上说把void改成uchar 但还是不行
void read_byte(uchar date),这个函数的最末尾有return,但是你的函数式无返回值类型,处理方式有两种,一是把return去掉,第二种就是把void改为uchar
把void改为uchar
恩。谢谢了呢。真心感谢
谢谢了,我懂了呢
有返回值的函数写错喽
恩,懂了谢谢了呢