标题:
有没有大佬看一下这个程序怎么改,编译时候的错误如图
[打印本页]
作者:
长情久暮
时间:
2019-4-21 00:47
标题:
有没有大佬看一下这个程序怎么改,编译时候的错误如图
QQ截图20190421004520.png
(7.82 KB, 下载次数: 25)
下载附件
2019-4-21 00:45 上传
********************************AT89C52源程序************************
#include<reg52.h> //包含头文件reg52.h
#define uchar unsigned char //无符号字符形变量定义为uchar
#define uint unsigned int
sbit biaozhun= P1^0; //定义端口
sbit jingji = P1^1;
sbit dandu = P1^2;
sbit paishuiled= P1^3;
sbit qiangxi = P1^4;
sbit ruoxi = P1^5;
sbit xidi = P1^6;
sbit piaoxi = P1^7;
sbit tuoshui = P2^0;
sbit jinshui = P2^2;
sbit paishui = P2^3;
sbit zz = P2^4;
sbit fz = P2^5;
sbit baojing = P2^1;
********************************键盘接口************************
sbit CX_key = P3^0;
sbit QR_key = P3^1;
sbit SW_key = P3^6;
sbit GKG_key = P3^7;
********************************全局变量定义************************
uchar tt,num,qr,qidong;
uint tt1=0;
bit XDshanshuo;
bit PXshanshuo;
bit TSshanshuo;
bit BJshanshuo;
******************************** 延时一秒************************
void delay(uint i)
{
uchar x;//,a,b,c
while(i--)
T2CON=0X01
for(x=0;x<20;x++) //定时器定时5秒
{
TH2=0x3c; //设置定时器初值
TL2=0xb0;
TR2=1;
while(!TF2); //查询计数是否溢出
TF2=0 //定时时间到,将定时器溢出标志位TF2清零
while(!qidong); //暂停语句
}
}
******************************** 延时毫秒************************
void delayms(uint i)
{
uchar x;
while(i--)
for(x=0;x<110;x++);
}
*******************************标准运行方式************************
void biaozhunfangshi() //标准方式运行
{
jinshui=0; //进水打开
delay(4); //延时
jinshui=1; //进水关闭
xidi=0; //洗涤打开
TR1=1; XDshanshuo=1; //启动定时器1洗涤闪烁
delay(20); //延时
xidi=1; //洗涤打开
TR1=0; 1 XDshanshuo=0; //关掉定时器,洗涤闪烁
zz=0; //正转打开
fz=0; //反转打开
paishui=0; BJshanshuo=1; //排水打开
delay(2); //延时
paishui=1; //关掉排水
jinshui=0; //打开进水
delay(4); //延时
jinshui=1; BJshanshuo=0; //关掉进水
piaoxi=0; //打开漂洗
TR1=1; PXshanshuo=1; //打开定时器1漂洗闪烁
delay(20); //延时
piaoxi=1; //关掉漂洗
TR1=0; PXshanshuo=0; //关掉定时器1.漂洗闪烁
zz=0; //打开正转
fz=0; //打开反转
paishui=0; BJshanshuo=1; //打开排水
delay(2); //延时
paishui=1; //关掉排水
jinshui=0; //打开进水
delay(4); //延时
jinshui=1; BJshanshuo=0; //关掉进水
piaoxi=0; //打开漂洗
TR1=1; PXshanshuo=1; //打开定时器1
delay(20); //延时
piaoxi=1; //关掉漂洗
TR1=0; PXshanshuo=0; //关掉定时器1
zz=0; //打开正转
fz=0; //打开反转
paishui=0; BJshanshuo=1; //打开排水
delay(2); //延时
paishui=1; //关掉排水
tuoshui=0; Tsshansuo=1; //打开脱水
delay(2); //延时
tuoshui=1; Tsshansuo=0; //关掉脱水
biaozhun=1; //关掉标准
}
****************************经济运行方式************************
void jingjifangshi() //经济方式
jinshui=0; //打开进水
delay (4); //延时
jinshui=1; //关掉进水
xidi=0; //打开洗涤
TR1=1; //打开定时器1
XDshanshuo=1; //打开洗涤闪烁
delay(30); //延时
xidi=1; //关掉洗涤
TR1=0; XDshanshuo=0; //关掉定时器1
zz=0; //打开正转
fz=0; //关掉反转
paishui=0; //打开排水
delay(2); //延时
paishui=1; //关掉排水
jinshui=0; //打开进水
delay(4); //延时
jinshui=1; //关掉进水
piaoxi=0; //打开漂洗
TR1=1; PXshanshuo=1; //打开定时器1
delay(20); //延时
piaoxi=1; //关掉漂洗
TR1=0; PXshanshuo=0; //关掉定时器1
zz=0; //正转
fz=0;//反转
paishui=0; //打开排水
delay(2); //延时
paishui=1; //关掉排水
tuoshui=0; TSshanshuo=1; //打开脱水
delay(2); //延时
tuoshui=1; TSshanshuo=0; //关掉脱水
jingji=1; //关闭进水
}
******************************单独运行方式************************
void dandufangshi() //单独方式
{
jinshui=0; //打开进水
delay(4); //延时
jinshui=1; //关掉进水
xidi=0; XDshanshuo=1; //打开洗涤
TR1=1; //打开定时器1
delay(30); //延时
xidi=1; //关掉洗涤
TR1=0; XDshanshuo=0; //关掉定时器1
zz=0; //正转
fz=0; //反转
dandu=1;
}
*******************************排水运行方式************************
void paishuifangshi() //排水方式
{
paishui=0; //打开排水
delay(2); //延时
paishui=1; //关掉排水
tuoshui=0; TSshanshuo=1; //打开脱水
delay(2); //延时
tuoshui=1; TSshanshuo=1; //打开脱水
paishuiled=1;
}
*******************************强弱切换程序************************
void QiangRuoQieHuan(); //强弱切换子程序
switch(qr)
case 1:{qiangxi=0;ruoxi=1;}break; //强洗
case 2:{qiangxi=1;ruoxi=0;}break; //弱洗
case 3:{qr=1;}break; //强弱
}delayms(1);
}
*******************************主函数************************
void main()
EA=1 //打开中断总允许位
EX0=1; //打开外部中断0允许位
IT0=1; //设置外部中断为下降沿触发方式
EX1=1; //外部中断1中断
IT1=1; //设置边沿触发方式
TMOD=0x11; //工作在方式三
TH0=(65536-50000)/256; //设定初值
TL0=(65536-50000)%256; //设定初值
ET0=1; //T0中断允许位
TR0=1; //启动定时器
TH1=(65536-50000)/256; //设定初值
TL0=(65536-50000)%256; //设定初值
ET0=1; //T0中断允许位
TR0=1; //启动定时器
TH1=(65536-50000)/256; //设定初值
TL0=(65536-50000)%256; //设定初值
ET1=1; //T1中断允许位
T2CON=0x01; //定时器2工作方式1
num=1;
qr=1; //关闭强弱
qidong=0; //打开启动
while(1)
{
QiangRuoQieHuan(); //强弱切换子程序
switch(num) //程序LED指示
{
case 1:{biaozhun=0;jingji=1;dandu=1;paishuiled=1;}break; //标准
case 2:{biaozhun=1;jingji=0;dandu=1;paishuiled=1;}break; //经济
case 3:{biaozhun=1;jingji=1;dandu=0;paishuiled=1;}break; //单独
case 4:{biaozhun=1;jingji=1;dandu=1;paishuiled=0;}break; //排水
}delayms(1);
if(qidong==1)
{
while(1)
{
switch(num) //程序方式切换
{
case 1:{biaozhunfangshi();}break; //标准方式
case 2:{jingjifangshi();}break; //经济方式
case 3:{dandufangshi();}break; // 单独方式
case 4:{paishuifangshi();}break; //排水方式
}delayms(1); return;
}
}
}
}
*******************************中断 *********************************
void int0() interrupt 0 //运行/暂停
{
qidong++; //启动
if(qidong==2) //如果启动打开
{qidong=0;TR1=0;zz=0;fz=0;} //启动打开
}
void int0() interrupt 2 //盖开关
EA=0; //关闭中断总允许位
TR0=0; //关闭定时器0
TR0=1; //启动定时器1
zz=0; //打开正转
fz=0; //打开反转
TR2=0; //关闭定时器2
TF2=0; //定时时间到,将定时器溢出标志位TF2清零
void time0() interrupt 1 //定时器中断0中断类型号1
{
TH0=(65536-50000)/256; //设定初值
TL0=(65536-50000)%256; //设定初值
tt++;
if(QR_key==0) //强弱切换开关
{
delayms(5); //延时
if(QR_key==0) //如果强弱开关键按下
{
qr++; //强弱
}while(!QR_key);
}
if(CX_key==0) //程序选择键
{
delayms(5) //延时
if(CX_key==0) //如果按下程序键
{num++;
if(num==5)num=1;
}
while(!CX_key);
}
*******************************盖开关************************
if(GKG_key==0) //盖开关
{
while(!GKG_key)
{TR1=0;zz=0;fz=0;} //关闭定时器1 正转、反转打开
TR1=1; //打开定时器1
}
if(tt==14) //LED 0.7s 闪烁
{
tt=0;
{
if(XDshanshuo==1) //如果是高电平
{xidi=!xidi;} //不洗涤
if(PXshanshuo==1) //如果是高电平
{piaoxi=!piaoxi;} //不漂洗
if(TSshanshuo==1) //如果是高电平
{tuoshui=!tuoshui;} //不脱水
}
}
}
void time1() interrupt 3 //定时器中断1中断类型号3
{
TH1=(65536-50000)/256; //定初值
TL1=(65536-50000)%256; //定初值
if(tt1==0) //电机正传
{
zz=0;
fz=1;
}
if(tt1==120) //6秒后电机停止
{
zz=1; //电机停止
fz=1;
}
tt1++; //电机继续
if(tt1==200) //4秒后电机反转
{
zz=1; //反转
fz=0;
}
if(tt1==320) //6秒后电机停止
{
zz=1;/ //电机不转
fz=1;
}
if(tt1==400) //4秒后电机正传
{
tt1=0; //电机正转
}
复制代码
作者:
wc86110
时间:
2019-4-21 02:14
删除 NO.1 再编译
作者:
qxdqx
时间:
2019-4-21 08:20
带*的地方在前面加//,有的地方没加大括号,标点符号一定在英文输入的时候加,否则容易出错.
作者:
HC6800-ES-V2.0
时间:
2019-4-21 08:32
错误类型是发现非法字符,第一行。
这样问题就清楚了:注释不是你这样写的,
要么这样写://注释,这种写法一般只管一行
要么这样写:/*注释*/,这种写法也以管很多行,只要在/*和*/之间的,都是注释,不论有多少行
作者:
喜乐
时间:
2019-4-23 13:30
好了吗
作者:
研A02
时间:
2019-4-23 16:34
你的花括号{}丢了好几个,
作者:
wushiye54
时间:
2019-4-24 20:09
建议好好看书再写代码:(1)注释错误;
(2)函数声明缺少分号;
(3)主函数居然没有“{}”花括号;
(4)排版太乱了
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1