
c语言高手请进, 我的代码有个错误,谁能帮我改 25
#include<reg52.h>#defineucharunsignedchar#defineuintunsignedintsbitwei=P2^6;//定义数码管的位...
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit wei=P2^6;//定义数码管的位和段
sbit duan=P2^7;
sbit ds=P3^7;//定义温度传感器信号线
uint temp;//定义整型温度数据
float f_temp;//定义浮点温度数据
uint warn_11=270;//定义温度下限值
uint warn_12=250;//同上
uint warn_h1=300;//定义上限
uint warn_h2=320;//同上
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,
0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};//定义带小数点和不带小数点的0-9编码
void delay(uint x)//延时函数
{
uint i,j;
for(i=100;i>0;i--)
for(j=x;j>0;j--);
}
void ds18B()//传感器复位
{
uint ii;
ds=0;
ii=110;
while(ii>0)
ii--;
ds=1;
ii=5;
while(ii>0)
ii--;
}
bit tread()//读温度1位
{
uint ii=0;
bit shuju;
ds=0;ii++;
ds=1;ii++;ii++;
shuju=ds;
ii=8;
while(ii>0)
ii--;
return shuju;
}
uchar tread1()//读一个字节
{
uchar ii,jj,shuju=0;
for(ii=1;ii<=8;ii++)
{
jj=tread();
shuju=(jj<<7)|(shuju>>1);
}
return shuju;
}
void twrite(uchar shuju)//向传感器写一个字节数据
{
uint ii;
uchar jj;
bit tb;
for(jj=1;jj<=8;jj++)
{
tb=shuju&0x01;
shuju=shuju>>1;
if(tb)
{
ds=0;
ii++;ii++;
ds=1;
ii=8;
while(ii>0)
ii--;
}
else
{
ds=0;
ii=8;
while(ii>0)
ii--;
ds=1;
ii++;ii++;
}
}
}
void tchange()//获取温度并转
{
ds18B();
delay(1);
twrite(0xcc);
twrite(0x44);
}
uint get()//读寄存器中存储的数据
{
uchar a,b;
ds18B();
delay(1);
twrite(0xcc);
twrite(0xbe);
a=tread1();
b=tread1();
temp=b;
temp<<=8;
temp=temp|a;
f_temp=temp*0.0625;//温度在寄存器中为12位,分辨率为0.0625度
temp=f_temp*10+0.5;//小数点后取一位并四舍五入
f_temp=f_temp+0.05;
return temp;
}
void display(uchar k,uchar shuju)//显示,k为第几个数码管,shuju为显示的数字
{
uchar ii;
duan=0;
P0=table[shuju];
duan=1;
duan=0;
wei=0;
ii=0xff;
ii=ii&(~((0x01)<<k));
P0=ii;
wei=1;
wei=0;
delay(1);
}
void display_temp(uint da)
{
uchar ii;
ii=da/100;
display(0,ii);
ii=da%100/10;
display(1,ii+10);
ii=da%100%10;
display(2,ii);
}
void ck()//串口初始化
{
TMOD=0x20;
PCON=0x00;
SCON=0x50;
TH1=0xfd;
TL1=0xfd;
TR1=1;
}
void ckf(char *p)//串口发送数据
{
while(*p)
{
SBUF=*p++;
while(!TI);
TI=0;
}
}
void main()
{
uchar jy[4],i;
duan=0;
wei=0;
ck();
while(1)
{
tchange();
for(i=10;i>0;i--)
display_temp(get());
sprintf(jy,"%f",f_temp);
for(i=10;i>0;i--)
display_temp(get());
ckf(jy);
for(i=10;i>0;i--)
display_temp(get());
}
}
第172出错,提示错误为,
ZH.C(172): warning C206: 'sprintf': missing function-prototype
ZH.C(172): error C267: 'sprintf': requires ANSI-style prototype
第172行即倒数第八行 是用Keil uVision3编译的要生成HEX文件 展开
#define uchar unsigned char
#define uint unsigned int
sbit wei=P2^6;//定义数码管的位和段
sbit duan=P2^7;
sbit ds=P3^7;//定义温度传感器信号线
uint temp;//定义整型温度数据
float f_temp;//定义浮点温度数据
uint warn_11=270;//定义温度下限值
uint warn_12=250;//同上
uint warn_h1=300;//定义上限
uint warn_h2=320;//同上
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,
0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};//定义带小数点和不带小数点的0-9编码
void delay(uint x)//延时函数
{
uint i,j;
for(i=100;i>0;i--)
for(j=x;j>0;j--);
}
void ds18B()//传感器复位
{
uint ii;
ds=0;
ii=110;
while(ii>0)
ii--;
ds=1;
ii=5;
while(ii>0)
ii--;
}
bit tread()//读温度1位
{
uint ii=0;
bit shuju;
ds=0;ii++;
ds=1;ii++;ii++;
shuju=ds;
ii=8;
while(ii>0)
ii--;
return shuju;
}
uchar tread1()//读一个字节
{
uchar ii,jj,shuju=0;
for(ii=1;ii<=8;ii++)
{
jj=tread();
shuju=(jj<<7)|(shuju>>1);
}
return shuju;
}
void twrite(uchar shuju)//向传感器写一个字节数据
{
uint ii;
uchar jj;
bit tb;
for(jj=1;jj<=8;jj++)
{
tb=shuju&0x01;
shuju=shuju>>1;
if(tb)
{
ds=0;
ii++;ii++;
ds=1;
ii=8;
while(ii>0)
ii--;
}
else
{
ds=0;
ii=8;
while(ii>0)
ii--;
ds=1;
ii++;ii++;
}
}
}
void tchange()//获取温度并转
{
ds18B();
delay(1);
twrite(0xcc);
twrite(0x44);
}
uint get()//读寄存器中存储的数据
{
uchar a,b;
ds18B();
delay(1);
twrite(0xcc);
twrite(0xbe);
a=tread1();
b=tread1();
temp=b;
temp<<=8;
temp=temp|a;
f_temp=temp*0.0625;//温度在寄存器中为12位,分辨率为0.0625度
temp=f_temp*10+0.5;//小数点后取一位并四舍五入
f_temp=f_temp+0.05;
return temp;
}
void display(uchar k,uchar shuju)//显示,k为第几个数码管,shuju为显示的数字
{
uchar ii;
duan=0;
P0=table[shuju];
duan=1;
duan=0;
wei=0;
ii=0xff;
ii=ii&(~((0x01)<<k));
P0=ii;
wei=1;
wei=0;
delay(1);
}
void display_temp(uint da)
{
uchar ii;
ii=da/100;
display(0,ii);
ii=da%100/10;
display(1,ii+10);
ii=da%100%10;
display(2,ii);
}
void ck()//串口初始化
{
TMOD=0x20;
PCON=0x00;
SCON=0x50;
TH1=0xfd;
TL1=0xfd;
TR1=1;
}
void ckf(char *p)//串口发送数据
{
while(*p)
{
SBUF=*p++;
while(!TI);
TI=0;
}
}
void main()
{
uchar jy[4],i;
duan=0;
wei=0;
ck();
while(1)
{
tchange();
for(i=10;i>0;i--)
display_temp(get());
sprintf(jy,"%f",f_temp);
for(i=10;i>0;i--)
display_temp(get());
ckf(jy);
for(i=10;i>0;i--)
display_temp(get());
}
}
第172出错,提示错误为,
ZH.C(172): warning C206: 'sprintf': missing function-prototype
ZH.C(172): error C267: 'sprintf': requires ANSI-style prototype
第172行即倒数第八行 是用Keil uVision3编译的要生成HEX文件 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询