/********************************AT89C52???3??D??************************/ #include<reg52.h> //??o????????treg52.h #define uchar unsigned char //?T???o???????D???????????????auchar #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; //????????????????3???? TL2=0xb0; TR2=1; while(!TF2); //2?????????y?????????3? TF2=0; //???????????????? ,???????????¨??3?????????TF2????? while(!qidong); //?Y??????? } } /********************************???????o????************************/ void delayms(uint i) { uchar x; while(i--) for(x=0;x<110;x++); } /*******************************?????????DD??????************************/ void biaozhunfangshi() //???????????????DD { jinshui=0; //???????a delay(4); //??????? jinshui=1; //????1???? xidi=0; //????????a TR1=1; XDshanshuo=1; //???????????????1??????????? delay(20); //??????? xidi=1; //????????a TR1=0; XDshanshuo=1; //1??????????????,??????????? zz=0; //?y??a???a fz=0; //?????a???a paishui=0; BJshanshuo=1; //???????a delay(2); //??????? paishui=1; //1???????? jinshui=0; //???a???? delay(4); //??????? jinshui=1; BJshanshuo=0; //1???????? piaoxi=0; //???a?????? TR1=1; PXshanshuo=1; //???a??????????1?????????? delay(20); //??????? piaoxi=1; //1?????????? TR1=0; PXshanshuo=0; //1??????????????1.?????????? zz=0; //???a?y??a fz=0; //???a?????a paishui=0; BJshanshuo=1; //???a???? delay(2); //??????? paishui=1; //1???????? jinshui=0; //???a???? delay(4); //??????? jinshui=1; BJshanshuo=0; //1???????? piaoxi=0; //???a?????? TR1=1; PXshanshuo=1; //???a??????????1 delay(20); //??????? piaoxi=1; //1?????????? TR1=0; PXshanshuo=0; //1??????????????1 zz=0; //???a?y??a fz=0; //???a?????a paishui=0; BJshanshuo=1; //???a???? delay(2); //??????? paishui=1; //1???????? tuoshui=0; TSshanshuo=1; //???a????? delay(2); //??????? tuoshui=1; TSshanshuo=0; //1????????? biaozhun=1; //1??????????? } /****************************?-????DD??????************************/ void jingjifangshi()//?-???????? { jinshui=0; //???a???? delay (4); //??????? jinshui=1; //1???????? xidi=0; //???a????? TR1=1; //???a??????????1 XDshanshuo=1; //???a??????????? delay(30); //??????? xidi=1; //1????????? TR1=0; XDshanshuo=0; //1??????????????1 zz=0; //???a?y??a fz=0; //1?????????a paishui=0; //???a???? delay(2); //??????? paishui=1; //1???????? jinshui=0; //???a???? delay(4); //??????? jinshui=1; //1???????? piaoxi=0; //???a?????? TR1=1; PXshanshuo=1; //???a??????????1 delay(20); //??????? piaoxi=1; //1?????????? TR1=0; PXshanshuo=0; //1??????????????1 zz=0; //?y??a fz=0;//?????a paishui=0; //???a???? delay(2); //??????? paishui=1; //1???????? tuoshui=0; TSshanshuo=1; //???a????? delay(2); //??????? tuoshui=1; TSshanshuo=0; //1????????? jingji=1; //1???????? } /***************************************************************/ void dandufangshi() //???????????? { jinshui=0; //???a???? delay(4); //??????? jinshui=1; //1???????? xidi=0; XDshanshuo=1; //???a????? TR1=1; //???a??????????1 delay(30); //??????? xidi=1; //1????????? TR1=0; XDshanshuo=0; //1??????????????1 zz=0; //?y??a fz=0; //?????a dandu=1; } /*******************************??????DD??????************************/ void paishuifangshi() //?????????? { paishui=0; //???a???? delay(2); //??????? paishui=1; //1???????? tuoshui=0; TSshanshuo=1; //???a????? delay(2); //??????? tuoshui=1; TSshanshuo=1; //???a????? paishuiled=1; } /*******************************??????D??3??D??************************/ void QiangRuoQieHuan() //??????D??????3??D?? { switch(qr) { case 1:{qiangxi=0;ruoxi=1;}break; //????? case 2:{qiangxi=1;ruoxi=0;}break; //?????? case 3:{qr=1;}break; //????? }delayms(1); } /*******************************???o????y************************/ void main() { EA=1; //???a?D?????????D???? EX0=1; //???a??a2??D??0???D???? IT0=1; //????????a2??D???a????????????顤???? EX1=1; //??a2??D??1?D?? IT1=1; //????????????????顤???? TMOD=0x11; //1????????????????y TH0=(65536-50000)/256; //???????3???? TL0=(65536-50000)%256; //???????3???? ET0=1; //T0?D?????D???? TR0=1; //??????????????? TH1=(65536-50000)/256; //???????3???? TL0=(65536-50000)%256; //???????3???? ET0=1; //T0?D?????D???? TR0=1; //??????????????? TH1=(65536-50000)/256; //???????3???? TL0=(65536-50000)%256; //???????3???? ET1=1; //T1?D?????D???? T2CON=0x01; //??????????21??????????1 num=1; qr=1; //1????????? qidong=0; //???a????? while(1) { QiangRuoQieHuan(); //??????D??????3??D?? switch(num) //3??D??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) //3??D?????????D?? { case 1:{biaozhunfangshi();}break; //????????????? case 2:{jingjifangshi();}break; //?-???????? case 3:{dandufangshi();}break; // ???????????? case 4:{paishuifangshi();}break; //?????????? }delayms(1); return; } } } } /*******************************?D??*********************************/ void int0() interrupt 0 //??DD/?Y???? { qidong++; //????? if(qidong==2) //???1?????????a {qidong=0;TR1=0;zz=0;fz=0;} //????????a } void int1() interrupt 2 { //???a1? EA=0; //1?????D?????????D???? TR0=0; //1??????????????0 TR0=1; //???????????????1 zz=0; //???a?y??a fz=0; //???a?????a TR2=0; //1??????????????2 TF2=0; } //????????????????,???????????¨??3?????????TF2????? void time0() interrupt 1 //???????????D??0?D??????D??o?1 { TH0=(65536-50000)/256; //???????3???? TL0=(65536-50000)%256; //???????3???? tt++; if(QR_key==0) //??????D???a1? { delayms(5); //??????? if(QR_key==0) //???1???????a1????????? { qr+=1; //????? } while(!QR_key); } if(CX_key==0) //3??D????????? { delayms(5); //??????? if(CX_key==0) //???1??????3??D????? {num++; if(num==5)num=1; } while(!CX_key); } /*******************************???a1?************************/ if(GKG_key==0) //???a1? { { while(!GKG_key) {TR1=0;zz=0;fz=0;} //???a??????????1 ?y??a??顤???a???a TR1=1; //???a??????????1 } if(tt==14) //LED 0.7s ?????? { tt=0; { if(XDshanshuo==1) //???1??????????? {xidi=!xidi;} //2?????? if(PXshanshuo==1) //???1??????????? {piaoxi=!piaoxi;} //2??????? if(TSshanshuo==1) //???1??????????? {tuoshui=!tuoshui;} //2?????? } } } } void time1() interrupt 3 //???????????D??1?D??????D??o?3 { TH1=(65536-50000)/256; //???3???? TL1=(65536-50000)%256; //???3???? if(tt1==0) //???????y??a { zz=0; fz=1; } if(tt1==120) //6??o?????????????1 { zz=1; //???????????1 fz=1; } tt1++; //?????????D? if(tt1==200) //4??o?????????????a { zz=1; //?????a fz=0; } if(tt1==320) //6??o?????????????1 { zz=1; //??????2???a fz=1; } if(tt1==400) //4??o?????????y??a { tt1=0; //???????y??a } } 老铁,程序最好看懂呢 |
hantu 发表于 2019-4-22 14:22 从229行开始重新排版了一下,现在应该没有乱码了 |
hantu 发表于 2019-4-22 14:22 /*******************************中断*********************************/ void int0() interrupt 0 //运行/暂停 { qidong++; //启动 if(qidong==2) //如果启动打开 {qidong=0;TR1=0;zz=0;fz=0;} //启动打开 } void int1() 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; //电机正转 } } |
代码第254行尾少分号 自第239起的代码段有问题。因为排版极乱没有规范缩进,大大增加排错难度。 |
错太多了 第96、98行,TSshanshuo错写成TSshansuo了 第229行的中断服务程序少了开始跟结束的花括号,而且与第223的函数重名 还有两个定时器中断的服务程序写得也太繁琐了 |
HC6800-ES-V2.0 发表于 2019-4-22 08:50 程序放下面楼了,越改错越多不知道为啥 |
aimripeky 发表于 2019-4-22 10:25 定义了的,头文件接下来就定义了 |
|
变量重叠 |
你的变量定义类型了吗 比如 int char。。。 |
发程序吧,想帮你都没办法。 只看你的图片,好像外部中断1的服务函数没有{},有头文件没? |