找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 767|回复: 2
收起左侧

这种程序错误应该怎么改啊

[复制链接]
ID:1027558 发表于 2022-5-20 12:05 | 显示全部楼层 |阅读模式
本帖最后由 3458227407 于 2022-5-20 12:49 编辑

;-------------------------------------------------
#include<reg52.h>
#define ui unsigned int
#define uc unsigned char
sbit SET=P3^1;
sbit DEC=P3^2;
sbit ADD=P3^3;
sbit BEEP=P3^6;
sbit ALAM=P1^2;
sbit DQ =P3^7;
sbit SCL=P1^6;
sbit SDA=P1^7;
sbit DIAN=P0^5;
bit bdata shanshuo_st;
bit bdata beep_st;
uc x=0;
ui bai,shi,ge;
uc set_st=0;
char shangxian,xiaxian;
//uc code
LEDData[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xff};
uc code
LEDData[]={0x5F,0x44,0x9D,0xD5,0xC6,0xD3,0xDB,0x47,0xDF,0xD7,0xCF,0xDA,0
x9B,0xDC,0x9B,0x8B};
//==============================================================
==============================
//====================================DS18B20===================
==============================
//==============================================================
==============================
void Delay_DS18B20(int num)
{
while(num--) ;
}
void delay()
{ ;; }
void start()  
{
SDA=1;
delay();
SCL=1;
delay();
SDA=0
delay()
}
void stop()
{
SDA=0;
delay();
SCL=1;
delay();
SDA=1
delay()
}
void respons()
{
uc i;
SCL=1;
delay();
while((SDA==1)&&(i<250))i++;
SCL=0;
delay();
}
void init24c04()
{
SDA=1;
delay();
SCL=1;
delay();
}
void write_byte(uc date)
{
uc i,temp;
temp=date;
for(i=0;i<8;i++)
{
temp=temp<<1;
SCL=0;
delay();
SDA=CY;
delay();
SCL=1;
delay();
}
SCL=0;
delay();
SDA=1;
delay();
}
uc read_byte()
{
uc i,k;
SCL=0;
delay();
SDA=1;
delay();
for(i=0;i<8;i++)
{
SCL=1;
delay();
k=(k<<1)|SDA;
SCL=0;
delay();
}
return k;
}
void write_add(uc address,uc date)
{
start();
write_byte(0xa0);
respons();
write_byte(address);
respons();
write_byte(date);
respons();
stop();
}
uc read_add(uc address)
{
uc date;
start();
write_byte(0xa0);
respons();
write_byte(address);
respons();
start();
write_byte(0xa1);
respons();
date=read_byte();
stop();
return date;
}
void Init_DS18B20(void)
{
uc w=0;
DQ = 1;
Delay_DS18B20(8);
DQ = 0;
Delay_DS18B20(78);
DQ = 1;
Delay_DS18B20(14);
w = DQ;  
Delay_DS18B20(20);
}
unsigned char ReadOneChar(void)
{
uc i=0;
uc dat = 0;
for (i=8;i>0;i--)
{
DQ = 0;
dat>>=1;
DQ = 1;
if(DQ)
dat|=0x80;
Delay_DS18B20(4);
}
return(dat);
}
void WriteOneChar(uc dat)
{
uc i=0;
for (i=8; i>0; i--)
{
DQ = 0;
DQ = dat&0x01;
Delay_DS18B20(5);
DQ = 1;
dat>>=1;
}
}
ui ReadTemperature(void)
{
ui b=0;
ui t=0;
ui a=0;
float tt=0;
Init_DS18B20();
WriteOneChar(0xCC);
WriteOneChar(0x44);
Init_DS18B20();
WriteOneChar(0xCC);
WriteOneChar(0xBE);
a=ReadOneChar();
b=ReadOneChar();
t=b;
t<<=8;
t=t|a;
tt=t*0.0625;
t=tt*10+0.5;
return(t);
}
void Delay(ui num)
{
while( --num );
}
void InitTimer(void)
{
TMOD=0x01;
TH0=0x3c;
TL0=0xb0;
}
void check_wendu(void)
{
ui f;
f=ReadTemperature()-5;  
if(f<0)f=0;
if(f>999)f=999;
bai=f/100;
shi=(f%100)/10;
ge=(f%100)%10;
}
void Disp_init(void)
{
P0 = ~0x80;
P2 = 0x7F;
Delay(200);
P2 = 0xDF;
Delay(200);
P2 = 0xF7;
Delay(200);
P2 = 0xFD;
Delay(200);
P2 = 0xFF;
}
void Disp_Temperature(void)
{
P0 = ~0x98;
P2 = 0x7F;
Delay(400);
P2 = 0xff;
P0=~LEDData[ge];
P2 = 0xDF;
Delay(400);
P2 = 0xff;
P0 =~LEDData[shi];
DIAN = 0;
P2 = 0xF7;
Delay(400);
P2 = 0xff;
P0 =~LEDData[bai];
P2 = 0xFD;
Delay(400);
P2 = 0xff;
}
void Disp_alarm(uc baojing)
{
P0 =~0x98;
P2 = 0x7F; //01111111
Delay(200);
P2 = 0xff;
P0 =~LEDData[baojing%10];
P2 = 0xDF; //1101
Delay(200);
P2 = 0xff;
P0 =~LEDData[baojing/10];
P2 = 0xF7; //11110111
Delay(200);
P2 = 0xff;
if(set_st==1)P0 =~0xCE;
else if(set_st==2)P0 =~0x1A;
P2 = 0xFD;
Delay(200);
P2 = 0xff;
}
void Alarm()
{
if(x>=10){beep_st=~beep_st;x=0;}
if((((bai*10+shi)>=shangxian)||((bai*10+shi)<xiaxian))&&beep_st==1)
{
BEEP=0;
ALAM=0;
}
else if((((bai*10+shi)>=shangxian)||((bai*10+shi)<xiaxian))&&beep_st==0)
{
BEEP=1;
ALAM=1;
}
else if(((bai*10+shi)<shangxian)&&((bai*10+shi)>=xiaxian))
{
BEEP=1;
ALAM=1;
}
}
void main(void)
{
ui z;
InitTimer();  
EA=1;
TR0=1;
ET0=1;
check_wendu();
check_wendu();
shangxian=read_add(10);
xiaxian=read_add(20);
for(z=0;z<300;z++)
{
Disp_init();
}
while(1)
{
if(SET==0)
{
Delay(2000);
do{}
while(SET==0);
set_st++;x=0;shanshuo_st=1;
if(set_st>2)set_st=0;
}
if(set_st==0)
{
check_wendu();
Disp_Temperature();
Alarm();
}
else if(set_st==1)
{
BEEP=1;  
ALAM=1;
if(x>=10){shanshuo_st=~shanshuo_st;x=0;}
if(shanshuo_st) {Disp_alarm(shangxian);}
if(ADD==0)
{
do{Disp_alarm(shangxian);}
while(ADD==0);
shangxian++;
if(shangxian>99)shangxian=99;
write_add(10,shangxian);
}
else if(DEC==0)
{
do{Disp_alarm(shangxian);}
while(DEC==0);
shangxian--;
if(shangxian<xiaxian) shangxian=xiaxian;
write_add(10,shangxian);
}
}
else if(set_st==2)
{
BEEP=1;
ALAM=1;
if(x>=10){shanshuo_st=~shanshuo_st;x=0;}
if(shanshuo_st) {Disp_alarm(xiaxian);}
if(ADD==0)
{
do{Disp_alarm(xiaxian);}
while(ADD==0);
xiaxian++;
if(xiaxian>shangxian) xiaxian=shangxian;
write_add(20,xiaxian);
}
else if(DEC==0)
{
do{Disp_alarm(xiaxian);}
while(DEC==0);
xiaxian--;
if(xiaxian<0) xiaxian=0;
write_add(20,xiaxian);
}
}
}
}
void timer0(void) interrupt 1
{
TH0=0x3c;
TL0=0xb0;
x++;
}
程序(60): error C141: syntax error near '<', expected ')'
程序(60): error C129: missing ';' before '++'

回复

使用道具 举报

ID:883242 发表于 2022-5-20 15:04 | 显示全部楼层
少了个分号。
回复

使用道具 举报

ID:94031 发表于 2022-5-20 17:06 | 显示全部楼层
主要是换行,缺分号,复制程序还有换行问题,索性发工程给你,自己对照找错误。 测试.rar (37.27 KB, 下载次数: 2)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表