您好,欢迎访问三七文档
当前位置:首页 > 建筑/环境 > 电气安装工程 > 液体点滴速度监控装置设计的程序
#includeAT89X51.H#defineDB0_DB7P0#definebusy0x80#defineSCANPORTP1sbitE=P2^2;sbitRW=P2^1;sbitRS=P2^0;//11101111,11011111,10111111,01111111unsignedcharuca_LineScan[4]={0xEF,0xDF,0xBF,0x7F};//列线扫描电压分为第1,2,3,4根列线unsignedcharkey_ctt[4]={0};unsignedcharspeed_bcd[4]={0};unsignedcharspeed_sc[2];unsignedcharyy=0,temp;unsignedintspeed_ck[4]={0};unsignedintdi_xx[2]={0};unsignedintct=0,ttb=0,xx=0,tt3=0,speedct=0,speed=0,speedcd=10,cott=0;unsignedinttime_sq[4]={0};typedefunsignedcharuchar;unsignedcharcodelcd3[]={0123456789abcdef};unsignedcharcodelcdnow[]={NOW:000};unsignedcharcodelcdset[]={SET:000};unsignedcharCONTROL[8]={0x38,0x18,0x98,0x88,0xC8,0x48,0x68,0x28};unsignedcharcodes1[8]={0xb8,0x98,0xd8,0xc8,0xe8,0x68,0x78,0x38};//9,18,36,45,54,63,72,81度顺时针unsignedcharcodes2[8]={0xb8,0x98,0xd8,0xc8,0xe8,0x68,0x78,0x38};//9,18,36,45,54,63,72,81度逆时针unsignedcharcounts,pt;unsignedcharuc_KeyTemp=0;unsignedcharuc_ClickCount=0;unsignedcharucCount;bitflag=1;//度数,正反转,速度控制bita_ac=0;//比较系统标志bitbleept=0;//报警标准bitmoto=0;//电机标志位bita_key=0;bitb_key=0;voidvKeyProcess(unsignedcharucKeyCode);voidbleep();//报警voidac();//电机速度比校voidakey();//功能处理voidgetspeed();//速度检侧voidstdisplay();//显示voidDelay(unsignedintt);voiddelay_50ms(unsignedintt);//延时voidSendCommand(unsignedcharch);//发送命令voidvWriteData(unsignedcharch);//发送数据voidInitLcd();//初始化voidDisplayOneChar(unsignedcharx,unsignedchary,unsignedcharddata);//按指定位置显示一个字符voidDisplayListChar(unsignedcharx,unsignedchary,unsignedchar*DData);//按指定位盆显示一串字符//================================================//================================================voidDelay(unsignedintt)//delay40us{//for(;t!=0;t--);while(t--);}voiddeley_50ms(unsignedintt){unsignedintj;//可以在此加少许延时补偿,以称补大数值传递时(如delay_50ms(1000))造成的误差,但付出的代价是造成传递小数值//(delay_50ms(1))造成更大的误差。因为实际应用更多时候是传递小数值,所以补建议加补偿!for(;t!=0;t--)for(j=6245;j0;j--);}//==============================================//===============================================voidSendCommand(unsignedcharch)//发送命令{/*CheckBusy();*/RS=0;RW=0;DB0_DB7=ch;E=1;Delay(1);E=0;Delay(5);//delay40us}//=============================================//===================================================voidvWriteData(unsignedcharch)//发送数据{/*CheckBusy();*/RS=1;RW=0;DB0_DB7=ch;E=1;Delay(1);E=0;Delay(5);//delay40us}//=========================================================//===========================================================voidInitLcd()//初始化{SendCommand(0x38);Delay(1);SendCommand(0x08);//设置工作方式Delay(1);SendCommand(0x01);//显示状态设置Delay(1);SendCommand(0x06);//清屏Delay(1);SendCommand(0x0c);//输入方式设置Delay(1);}//=========================================================//===========================================================voidDisplayOneChar(unsignedcharx,unsignedchary,unsignedcharddata)//按指定位置显示一//个字符{y&=0x1;x&=0xf;//限制X不能大于15,Y不能大于1if(y)x|=0x40;//当要显示第二行时,地址码+0x40;x|=0x80;//算出指令码SendCommand(x);vWriteData(ddata);}//=========================================================//===========================================================voidDisplayListChar(unsignedcharx,unsignedchary,unsignedchar*DData)//按指定位盆显示一串字符{unsignedcharListLength;ListLength=0;y&=0x1;x&=0xf;//限制X不能大于15,Y不能大于1while(DData[ListLength]0x20){if(x=0xf){DisplayOneChar(x,y,DData[ListLength]);//显示单个字符ListLength++;x++;}}}//=========================================================//===========================================================voidvShowOneChar(unsignedcharucChar){switch(ucChar){case'0':vWriteData(0x30);break;case'1':vWriteData(0x31);break;case'2':vWriteData(0x32);break;case'3':vWriteData(0x33);break;case'4':vWriteData(0x34);break;case'5':vWriteData(0x35);break;case'6':vWriteData(0x36);break;case'7':vWriteData(0x37);break;case'8':vWriteData(0x38);break;case'9':vWriteData(0x39);break;case'a':vWriteData(0x61);break;case'b':vWriteData(0x62);break;case'c':vWriteData(0x63);break;case'd':vWriteData(0x64);break;case'e':vWriteData(0x65);break;case'f':vWriteData(0x66);break;default:break;}}//==============================================//==============================================unsignedcharucKeyScan(){unsignedcharucTemp=0;//扫描状态暂存unsignedcharucRow=0,ucLine=0;//行号列号for(ucLine=0;ucLine4;ucLine++)//列扫描{SCANPORT=uca_LineScan[ucLine];//输出扫描电位ucTemp=SCANPORT&0x0f;//输出扫描电位并屏蔽高4位if(ucTemp!=0x0f){switch(ucTemp){case0x0e:ucRow=10;break;//如果有则判断行号case0x0d:ucRow=20;break;case0x0b:ucRow=30;break;case0x07:ucRow=40;break;default:ucRow=50;break;}break;}}//恢复键扫描处理前舒适状态SCANPORT=0x0f;//恢复P2口returnucRow+ucLine+1;//返回按键编码格式为2位数高位为行号地位为列号}//==============================================//==============================================voidvKeyProcess(unsignedcharucKeyCode){SendCommand(0xc4+uc_ClickCount);if(a_key==1){switch(ucKeyCode){case41:vShowOneChar('7');temp=7;break;case42:vShowOneChar('8');temp=8;break;case43:vShowOneChar('9');temp=9;break;case31:vShowOneChar('4');temp=4;break;case32:vShowOneChar('5');temp=5;break;case33:vShowOneChar('6');temp=6;break;case21:vShowOneChar('1');temp=1;break;case2
本文标题:液体点滴速度监控装置设计的程序
链接地址:https://www.777doc.com/doc-5263481 .html