給51黑電子論壇的壇友們分享一個51單片機做的液位監控系統的proteus仿真,下面是原理圖:
0.png (31.57 KB, 下載次數: 74)
下載附件
2016-9-27 12:56 上傳
按鍵:
0.png (3.93 KB, 下載次數: 53)
下載附件
2016-9-27 12:56 上傳
液位監控系統程序流程圖:
0.png (39.2 KB, 下載次數: 47)
下載附件
2016-9-27 12:56 上傳
液位監控系統的部分源程序預覽:
- #include <reg51.h>
- #include <DS18B20.h>
- #include <LCD1602.h>
- #include <TLC2543.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit PWM=P2^4; //電機PWM輸出端口
- sbit SW=P2^5; //電機正反轉控制端口
- sbit K1=P3^0; //功能設置按鍵
- sbit K2=P3^1; //加按鍵
- sbit K3=P3^2; //減按鍵
- uchar ratio=10; //PWM占空比
- uchar count=0; //PWM定時計數
- uchar func=0; //系統功能,0當前狀態,1上下限設置,2電機轉速
- uchar high=150,low=50,height=0;
- uchar LCD_Buf1[16]={"W = 000.0m"};
- uchar LCD_Buf2[16]={"T = 000.0C"};
- uchar LCD_Buf3[16]={"H = 150.0m"};
- uchar LCD_Buf4[16]={"L = 050.0m"};
- uchar LCD_Buf5[16]={"Full = 384r/m"};
- uchar LCD_Buf6[16]={"Now = 000r/m"};
- //------------------------------------------------------
- //顯示溫度及液位
- //------------------------------------------------------
- void Display_HT(void)
- {
- uint volt,t;
- //電壓值顯示數據處理
- volt=TLC2543(0)*50.0/4095*102.3/2.5;
- LCD_Buf1[4]=volt/1000+'0';
- LCD_Buf1[5]=volt/100%10+'0';
- LCD_Buf1[6]=volt/10%10+'0';
- LCD_Buf1[8]=volt%10+'0';
- //溫度值顯示數據處理
- t=ReadTemperature();
- LCD_Buf2[4]=t/1000+'0';
- LCD_Buf2[5]=t/100%10+'0';
- LCD_Buf2[6]=t/10%10+'0';
- LCD_Buf2[8]=t%10+'0';
- LCD_Buf2[15]='A';
- //刷新LCD數據
- LCD_Display_String(0,0,LCD_Buf1);
- LCD_Display_String(0,1,LCD_Buf2);
- }
- //------------------------------------------------------
- //上限設置程序
- //------------------------------------------------------
- void High_Set()
- {
- uint x;
- if(K2==0) //加按鍵
- { Delay(10);
- if((K2==0)&&(high<102))
- high++;
- while(K2==0);
- }
- if(K3==0) //減按鍵
- { Delay(10);
- if((K3==0)&&(high>low))
- high--;
- while(K3==0);
- }
- //上限顯示數據處理
- x=high*10;
- LCD_Buf3[4]=x/1000+'0';
- LCD_Buf3[5]=x/100%10+'0';
- LCD_Buf3[6]=x/10%10+'0';
- LCD_Buf3[8]=x%10+'0';
- LCD_Buf4[15]='B';
- //刷新LCD數據
- LCD_Display_String(0,0,LCD_Buf3);
- LCD_Display_String(0,1,LCD_Buf4);
- }
- //------------------------------------------------------
- //下限設置程序
- //------------------------------------------------------
- void Low_Set()
- {
- uint x;
- if(K2==0) //加按鍵
- { Delay(10);
- if((K2==0)&&(low<high))
- low++;
- while(K2==0);
- }
- if(K3==0) //減按鍵
- { Delay(10);
- if((K3==0)&&(low>1))
- low--;
- while(K3==0);
- }
- //下限顯示數據處理
- x=low*10;
- LCD_Buf4[4]=x/1000+'0';
- LCD_Buf4[5]=x/100%10+'0';
- LCD_Buf4[6]=x/10%10+'0';
- LCD_Buf4[8]=x%10+'0';
- LCD_Buf4[15]='C';
- //刷新LCD數據
- LCD_Display_String(0,0,LCD_Buf3);
- LCD_Display_String(0,1,LCD_Buf4);
- }
- //------------------------------------------------------
- //顯示電機全速與當前轉速
- //------------------------------------------------------
- void Display_Motor()
- {
- uint x;
- //電機當前轉速顯示數據處理
- switch(ratio)
- {
- case 100: x=384;break;
- case 43: x=192;break;
- case 26: x=115;break;
- case 0: x=0;
- }
- LCD_Buf6[7]=x/100+'0';
- LCD_Buf6[8]=x/10%10+'0';
- LCD_Buf6[9]=x%10+'0';
- LCD_Buf6[15]='D';
- //刷新LCD數據
- LCD_Display_String(0,0,LCD_Buf5);
- LCD_Display_String(0,1,LCD_Buf6);
- }
- //------------------------------------------------------
- //K1按鍵掃描及系統功能
- //------------------------------------------------------
- void Func_Choice()
- {
- if(K1==0)
- { Delay(10);
- if(K1==0)
- func=(++func)%4;
- while(K1==0);
- }
- switch(func)
- {
- case 0: Display_HT();break;
- case 1: High_Set();break;
- case 2: Low_Set();break;
- case 3: Display_Motor();
- }
- }
- //------------------------------------------------------
- //電機轉速和轉向控制
- //------------------------------------------------------
- void Motor()
- {
- uchar l;
- l=TLC2543(0)*5.0/4095*102.3/2.5;
- if(l<low) //低于下限正轉
- {
- SW=0;
- if(l<low*0.1) ratio=100;
- if((l>=low*0.1)&&(l<low*0.3)) ratio=42;
- if(l>=low*0.3) ratio=26;
- }
- else if(l>high) //高于上限反轉
- {
- SW=1;
- if(l<high+(204.7-high)*0.7) ratio=26;
- if((l>=high+(204.7-high)*0.7)&&(l<high+(204.7-high)*0.9)) ratio=43;
- if(l>=high+(204.7-high)*0.9) ratio=100;
- }
- else
- ratio=0;
- }
- //------------------------------------------------------
- //定時中斷初始化程序
- //------------------------------------------------------
- void T0_Init()
- {
- TMOD=0x01; //設置T0工作方式2
- TH0=(65535-500)/256; //定時1000us
- TL0=(65536-500)%256;
- EA=1; //開T0中斷
- ET0=1;
- TR0=1; //啟動定時
- }
- //------------------------------------------------------
- //T0中斷服務程序
- //------------------------------------------------------
- void Timer0() interrupt 1
- {
- TH0=(65535-500)/256; //定時1000us
- TL0=(65536-500)%256;
- if(ratio==0) PWM=1;
- else if(ratio==100) PWM=0;
- else
- { count++;
- if(count==100) count=0;
- if(count==1) PWM=0;
- else if(count==(ratio+1)) PWM=1;
- }
- }
- void main()
- {
- LCD_Init(); //液晶顯示器初始化
- T0_Init(); //中斷初始化
- while(1)
- {
- Func_Choice(); //系統功能選擇
- Motor(); //電機控制
- }
- }
復制代碼
0.png (65.38 KB, 下載次數: 50)
下載附件
2016-9-27 12:56 上傳
液位監控系統的所有資料打包下載:
Proteus C51液位監控.rar
(148 KB, 下載次數: 176)
2016-9-27 13:05 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|