大神上午帮忙编程谢谢格式(主板倒计时状态信号按键)「微机原理倒计时显示装置设计」

大神上午帮忙编程谢谢格式(主板倒计时状态信号按键)

sbit PIN_RXD = P3^0; //接收引脚定义sbit PIN_TXD = P3^1; //发送引脚定义// 4.3反馈信号输入与控制输出P0为控制输出 P1 P2 P 3.3接LED状态灯 3.6拉低 3.7测试按键 辅助运行 3.5拉低打开led传感器 按测试按键恢复正常//21/2=11.5 1 23 45 67 89 1011 1213 1415 1617 1819 2021 11根线是信号输入//sbit led1 = P0; //sbit sjm=P0^7; //升降门0打开接继电器控制低电位sbit csd=P0^6; //传送带0开启接继电器控制低电位sbit cgq=P0^5; //传感器1 0开启接继电器控制5v电源给led激光发射端sbit zbkg = P0^4; //主板开关接0开启接继电器控制12v给主板断电sbit cgq2 = P0^3; //传感器2 0开启接继电器控制5v电源给led激光接收端//sbit sjmg = P1^3; //升降门高截止点//sbit sjmd = P1^4;//升降门低截止点sbit fk1 = P1^5;//反馈信号1//23 53sbit fk2 = P1^6; //反馈信号2//24 54//sbit zbjc = P1^7;//主板检测sbit zbjc = P3^2;//主板检测sbit zbxs=P3^3;//主板状态显示 1秒左右闪烁主板状态良好 有LED指示灯`sbit lcc = P3^5;//led传感器测试按键 触发拉低 接电磁继电器控制led激光5v输出sbit leds36 = P3^6;//开机拉低方便按键测试sbit csaj = P3^7;//测试辅助运行按键10秒sbit cs11s = P2^0;//1和9和17//传送带第一位 sbit cs12s = P2^1;//2和10和18sbit cs13s = P2^2;//3和11和19sbit cs14s = P2^3;//4和12和20sbit cs15s = P2^4;//5和13和21sbit cs16s = P2^5;//6和14和22sbit cs17s = P2^6;//7和15和23sbit cs18s = P2^7;//8和16和24sbit cs01s = P0^0;//正常拉低 当进行检测时候拉高sbit cs02s = P0^1;//正常拉低 当进行检测时候拉高sbit cs03s = P0^2;//正常拉低 当进行检测时候拉高bit RxdEnd = 0; //接收结束标志bit RxdOrTxd = 0; //制定当前状态接收还是发送bit TxdEnd = 0; // 发送结束标志unsigned char RxdBuf = 0;//接收缓冲器unsigned char TxdBuf = 0;//发送缓冲器 unsigned char RxdBufd = 0; //显示板流水灯缓冲器void ConfigUART(unsigned int baud);void StartRXD();void StartTXD(unsigned char dat);void anjian(); void anjiand();void anjian1();void jiankongzhuban();void delay02s(void);unsigned int i =0;unsigned char j = 0;unsigned int cnt =0; unsigned char d = 0; unsigned int secc = 0;unsigned int sec = 0; //倒计时时间 //常数型unsigned long see = 0; //判断状态停留unsigned long sss = 0;unsigned long ess = 0; //主通道倒计时函数void main(){EA = 1;//开总中断ConfigUART(9600);//配置波特率9600P0=P1=P2=P3=0xff;//led0=0;//cs01s=cs02s=cs03s=0; //RxdBufd=0xff;secc=200;sec=200;see=45; //主板重启45预防重启sss=45; //主板重启45预防重启ess=0;//主通道倒计时sec=3; //启动倒计时16秒cgq=0; //传感器csd=0; //传送带sjm=0; //升降门while(1){//while(PIN_RXD); //等待接受引脚出现低电平,计起始位//StartRXD(); //启动接收//while(!RxdEnd); //等待接收完成StartTXD(RxdBuf);//+1 接收数据在发送回去while(!TxdEnd);//等待发送完成anjian(); //anjian扫描anjian1();jiankongzhuban();secc--;if(secc==0) //大概换算成秒 好控制{see--;sss--;ess--;sec--;secc=70;}}}//串口配置函数,baud-通信波特率void ConfigUART(unsigned int baud){TMOD &= 0xF0; //清零T0的控制位TMOD |= 0x02; //配置T0为模式2TH0 = 256 - (11059200/12)/baud; //计算T0重载值} //启动串行接收void StartTXD(unsigned char dat){TxdBuf = dat;TL0 = TH0;ET0 = 1;TR0 = 1;PIN_TXD = 0;TxdEnd = 0;RxdOrTxd = 1;}void InterruptTimer0() interrupt 1{static unsigned char cnt = 0;if(RxdOrTxd){cnt++;if(cnt <= 8){PIN_TXD = TxdBuf & 0x01;TxdBuf >>= 1;}else if(cnt == 9){ PIN_TXD = 1;}else{cnt = 0;TR0 = 0;TxdEnd = 1;}}else{if(cnt == 0){if(!PIN_RXD){RxdBuf = 0;cnt++;}else{TR0 = 0;}}else if(cnt <= 8){RxdBuf >>= 1; if(PIN_RXD){RxdBuf |= 0x80;}cnt++;}else{cnt = 0;TR0 = 0;if(PIN_RXD){RxdEnd = 1;}}}}void anjiand(){static unsigned char d = 30; //显示板 流水灯 管理switch(d) { case 30: RxdBufd=0xff;delay02s(); d++; break;case 31: RxdBufd=0x21;delay02s(); d++; break;case 32: RxdBufd=0x21;delay02s(); d++; break;case 33: RxdBufd=0x20;delay02s(); d++; break;case 34: RxdBufd=0x51;delay02s(); d++; break;case 35: RxdBufd=0x19;delay02s(); d++; break;case 36: RxdBufd=0x50;delay02s(); d++; break;case 37: RxdBufd=0x18;delay02s(); d++; break;case 38: RxdBufd=0x49;delay02s(); d++; break;case 39: RxdBufd=0x17;delay02s(); d++; break;case 40: RxdBufd=0x48;delay02s(); d++; break;case 41: RxdBufd=0x16;delay02s(); d++; break;case 42: RxdBufd=0x47;delay02s(); d++; break;case 43: RxdBufd=0x15;delay02s(); d++; break;case 44: RxdBufd=0x46;delay02s(); d++; break;case 45: RxdBufd=0x14;delay02s(); d++; break;case 46: RxdBufd=0x45;delay02s(); d++; break;case 47: RxdBufd=0x13;delay02s(); d++; break;case 48: RxdBufd=0x44;delay02s(); d++; break;case 49: RxdBufd=0x12;delay02s(); d++; break;case 50: RxdBufd=0x43;delay02s(); d++; break;case 51: RxdBufd=0x11;delay02s(); d++; break;case 52: RxdBufd=0x42;delay02s(); d++; break;case 53: RxdBufd=0x10;delay02s(); d++; break;case 54: RxdBufd=0x41;delay02s(); d++; break;case 55: RxdBufd=0x09;delay02s(); d++; break;case 56: RxdBufd=0x40;delay02s(); d++; break;case 57: RxdBufd=0x08;delay02s(); d++; break; case 58: RxdBufd=0x39;delay02s(); d++; break;case 59: RxdBufd=0x07;delay02s(); d++; break;case 60: RxdBufd=0x38;delay02s(); d++; break;case 61: RxdBufd=0x06;delay02s(); d++; break;case 62: RxdBufd=0x37;delay02s(); d++; break;case 63: RxdBufd=0x05;delay02s(); d++; break;case 64: RxdBufd=0x36;delay02s(); d++; break;case 65: RxdBufd=0x04;delay02s(); d++; break;case 66: RxdBufd=0x35;delay02s(); d++; break;case 67: RxdBufd=0x03;delay02s(); d++; break;case 68: RxdBufd=0x34;delay02s(); d++; break;case 69: RxdBufd=0x02;delay02s(); d++; break;case 70: RxdBufd=0x33;delay02s(); d++; break;case 71: RxdBufd=0x01;delay02s(); d++; break;case 72: RxdBufd=0x32;delay02s(); d++; break;case 73: RxdBufd=0x01;delay02s(); d++; break;case 74: RxdBufd=0x02;delay02s(); d++; break;case 75: RxdBufd=0x03;delay02s(); d++; break;case 76: RxdBufd=0x04;delay02s(); d++; break;case 77: RxdBufd=0x05;delay02s(); d++; break;case 78: RxdBufd=0x06;delay02s(); d++; break;case 79: RxdBufd=0x07;delay02s(); d++; break;case 80: RxdBufd=0x08;delay02s(); d++; break;case 81: RxdBufd=0x09;delay02s(); d++; break;case 82: RxdBufd=0x10;delay02s(); d++; break;case 83: RxdBufd=0x11;delay02s(); d++; break;case 84: RxdBufd=0x12;delay02s(); d++; break;case 85: RxdBufd=0x13;delay02s(); d++; break; case 86: RxdBufd=0x14;delay02s(); d++; break;case 87: RxdBufd=0x15;delay02s(); d++; break;case 88: RxdBufd=0x16;delay02s(); d++; break;case 89: RxdBufd=0x17;delay02s(); d++; break;case 90: RxdBufd=0x18;delay02s(); d++; break;case 91: RxdBufd=0x19;delay02s(); d++; break;case 92: RxdBufd=0x20;delay02s(); d++; break;case 93: RxdBufd=0x21;delay02s(); d++; break;case 94: RxdBufd=0x31;delay02s(); d++; break;case 95: RxdBufd=0x32;delay02s(); d++; break;case 96: RxdBufd=0x33;delay02s(); d++; break;case 97: RxdBufd=0x34;delay02s(); d++; break;case 98: RxdBufd=0x35;delay02s(); d++; break;case 99: RxdBufd=0x36;delay02s(); d++; break;case 100: RxdBufd=0x37;delay02s(); d++; break; case 101: RxdBufd=0x38;delay02s(); d++; break;case 102: RxdBufd=0x39;delay02s(); d++; break;case 103: RxdBufd=0x40;delay02s(); d++; break;case 104: RxdBufd=0x41;delay02s(); d++; break;case 105: RxdBufd=0x42;delay02s(); d++; break;case 106: RxdBufd=0x43;delay02s(); d++; break;case 107: RxdBufd=0x44;delay02s(); d++; break;case 108: RxdBufd=0x45;delay02s(); d++; break;case 109: RxdBufd=0x46;delay02s(); d++; break;case 110: RxdBufd=0x47;delay02s(); d++; break;case 111: RxdBufd=0x48;delay02s(); d++; break;case 112: RxdBufd=0x49;delay02s(); d++; break;case 113: RxdBufd=0x50;delay02s(); d++; break;case 114: RxdBufd=0x51;delay02s(); d=31; break;default:break;}}//按键扫描 扫描完键的状态 然后发送出去void anjian(){static unsigned char j = 1; //动态按键扫描switch(j){case 1: cs01s=1;if(cs11s==0) { RxdBuf=0x01;delay02s(); }if(cs11s==1) { RxdBuf=0x31;delay02s(); }j++; break;case 2: cs01s=1;if(cs12s==0) { RxdBuf=0x02;delay02s(); }if(cs12s==1) { RxdBuf=0x32;delay02s(); }j++; break;case 3: cs01s=1;if(cs13s==0) { RxdBuf=0x03;delay02s(); }if(cs13s==1) { RxdBuf=0x33;delay02s(); }j++; break; //4case 4: cs01s=1;if(cs14s==0) { RxdBuf=0x04;delay02s(); }if(cs14s==1) { RxdBuf=0x34;delay02s(); } j++; break;case 5: cs01s=1;if(cs15s==0) { RxdBuf=0x05;delay02s(); }if(cs15s==1) { RxdBuf=0x35;delay02s(); }j++; break;case 6: cs01s=1;if(cs16s==0) { RxdBuf=0x06;delay02s(); }if(cs16s==1) { RxdBuf=0x36;delay02s(); }j++; break;case 7: cs01s=1;if(cs17s==0) { RxdBuf=0x07;delay02s(); }if(cs17s==1) { RxdBuf=0x37;delay02s(); }j++; break;case 8: cs01s=1;if(cs18s==0) { RxdBuf=0x08;delay02s(); cs01s=0; }if(cs18s==1) { RxdBuf=0x38;delay02s(); cs01s=0; }j++; break;case 9: cs02s=1;if(cs11s==0) { RxdBuf=0x09;delay02s(); }if(cs11s==1) { RxdBuf=0x39;delay02s(); }j++; break;case 10: cs02s=1;if(cs12s==0) { RxdBuf=0x10;delay02s(); }if(cs12s==1) { RxdBuf=0x40;delay02s(); }j++; break;case 11: cs02s=1;if(cs13s==0) { RxdBuf=0x11;delay02s(); }if(cs13s==1) { RxdBuf=0x41;delay02s(); }j++; break; //4case 12: cs02s=1;if(cs14s==0) { RxdBuf=0x12;delay02s(); }if(cs14s==1) { RxdBuf=0x42;delay02s(); } j++; break;case 13: cs02s=1;if(cs15s==0) { RxdBuf=0x13;delay02s(); }if(cs15s==1) { RxdBuf=0x43;delay02s(); }j++; break;case 14: cs02s=1;if(cs16s==0) { RxdBuf=0x14;delay02s(); }if(cs16s==1) { RxdBuf=0x44;delay02s(); }j++; break;case 15: cs02s=1;if(cs17s==0) { RxdBuf=0x15;delay02s(); }if(cs17s==1) { RxdBuf=0x45;delay02s(); }j++; break;case 16: cs02s=1;if(cs18s==0) { RxdBuf=0x16;delay02s(); cs02s=0; }if(cs18s==1) { RxdBuf=0x46;delay02s(); cs02s=0; }j++; break;case 17: cs03s=1;if(cs11s==0) { RxdBuf=0x17;delay02s(); }if(cs11s==1) { RxdBuf=0x47;delay02s(); }j++; break;case 18: cs03s=1;if(cs12s==0) { RxdBuf=0x18;delay02s(); }if(cs12s==1) { RxdBuf=0x48;delay02s(); }j++; break;case 19: cs03s=1;if(cs13s==0) { RxdBuf=0x19;delay02s(); }if(cs13s==1) { RxdBuf=0x49;delay02s(); }j++; break; //4case 20: cs03s=1;if(cs14s==0) { RxdBuf=0x20;delay02s(); }if(cs14s==1) { RxdBuf=0x50;delay02s(); } j++; break;case 21: cs03s=1;if(cs15s==0) { RxdBuf=0x21;delay02s(); cs03s=0; }if(cs15s==1) { RxdBuf=0x51;delay02s(); cs03s=0; }j++; break;case 22: if(zbjc==0) { RxdBuf=0x22;delay02s(); }if(zbjc==1) { RxdBuf=0x52;delay02s(); }j++; break;case 23: if(fk1==0) { RxdBuf=0x23;delay02s(); }if(fk1==1) { RxdBuf=0x53;delay02s(); }j++; break;case 24:if(fk2==0) { RxdBuf=0x24;delay02s(); }if(fk1==1) { RxdBuf=0x54;delay02s(); }j++; break; case 25: if(csd==0) { RxdBuf=0x25;delay02s(); j=1;}if(csd==1) { RxdBuf=0x55;delay02s(); j++; } break;case 26: if(csd==0) { RxdBuf=0xff; j=1; }if(csd==1) { RxdBuf=RxdBufd; anjiand(); delay02s(); j=22; } break;default:break;}}void anjian1(){leds36=0;if(csaj==0) //测试按键{if(csaj==0){if(csaj==0){sec=16; //启动倒计时16秒cgq=0; //传感器csd=0; //传送带sjm=0; //升降门} } }if(lcc==0){ cgq=0; sec=16; }if(fk1==0) //第A货道信号检测与执行 这当是1 不遮挡是0{if(fk1==0){if(fk2==0){if(fk2==0){cgq = 0;//传感器开关 通5v sec=46;csd=0;//传送带输出}}} }if(scd==0){if(sec==45) { cgq2=0; }if(sec==15){ cgq2=0; }if(sec==2){ cgq2=0; }}if(sec==0){ cgq=csd=cgq2=sjm=1; }} void jiankongzhuban() {//zhuban(); //监控主板运行状态//检测主板状态信号 sz2 信号输出lz2 信号到0 lz3 10秒重启电源 see=40;循环if(zbkg==1){if(zbjc==0) //判断主板状态灯信号是低电平see=10秒倒计时{ zbxs=0; // while(!sz2) //等待按键弹起.....影响单片机速度see=50; }if(zbjc==1) //判断主板状态灯信号是高电平scc=10秒倒计时{zbxs=1;sss=50; //10}}if(see==0) //主板状态灯信号一直为高电平 不影响低电平倒计时{zbkg=0;//给主板断电 3.3 see=45;}if(sss==0) //主板状态灯信号一直为高电平 不影响低电平倒计时{zbkg=0;//给主板断电 3.3 sss=45;}if(sss==0) //主板状态灯信号一直是低电平 不影响高电平倒计时{zbkg=0; //给主板断电 3.3sss=45;}if(see==40) zbkg=1;if(sss==40) zbkg=1; //断电15秒给主板上电 }void delay02s(void) //延时0.2 秒子程序{unsigned char d,f,g;for(d=5;d>0;d--)for(f=5;f>0;f--)for(g=248;g>0;g--);}

联系我们

在线咨询:点击这里给我发消息