【Proteus仿真】基于51单片机液位控制系统仿真设计
【Proteus仿真】基于51单片机液位控制系统仿真设计
Proteus仿真

STC98C52、1位共阴是数码管、液位传感器(常开型)
功能讲解
当水位低于1时,自动启动电机,加水,当水位达到6时,自动停止;当水位没有达到6时,可以手动启动电机加水,直到水位达到6,才会停止加水。
实例代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
| #include <STC89C5xRC.H>
unsigned char code table[]= {0x3f,0x06,0x5b,0x4f,0x66, 0x6d,0x7d,0x07,0x7f,0x6f };//共阴数码管 sbit shuiman=P1^0;//水满 sbit sw5=P1^1;//水位5 sbit sw4=P1^2;//水位4 sbit sw3=P1^3;//水位3 sbit sw2=P1^4;//水位2 sbit sw1=P1^5;//水位1 /\*液位指示灯\*/ sbit level1=P2^1; sbit level2=P2^2; sbit level3=P2^3; sbit level4=P2^4; sbit level5=P2^5; sbit level6=P2^6;
sbit shougong=P1^6;//手工上水 sbit dianji=P1^7;//电机控制位 sbit state=P3^7;//电机工作指示 /\*延时程序\*/ //毫秒级延时 void delay(unsigned int z) { unsigned int x,y; for(x=z; x>>0; x--) for(y=110; y>>0; y--); } main() { P0=0; P2=0xff; P1=0xff; while(1) { /\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*常开型触发传感器\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/ //水满 if(shuiman==0)//当水位6时发生,立即停机 { dianji=1;//关电机 state=1;//电机工作指示灯熄灭 P2=0xBF; P0=table[6];//显示水位深度:6\*\*\*\* 已满 delay(3000);//延时一段时间让数码管显示给人以提示:水已满 } //水位5 if(shuiman==1&&sw5==0)//当水位5时发生 { P0=table[5];//显示水位深度:5 P2 =0xDF;
} //水位4 if(shuiman==1&&sw5==1&&sw4==0)//当水位4时发生 { P0=table[4];//显示水位深度:4 P2=0xEF;
} //水位3 if(shuiman==1&&sw5==1&&sw4==1&&sw3==0)//当水位3时发生 { P0=table[3];//显示水位深度:5 P2=0xF7;
} //水位2 if(shuiman==1&&sw5==1&&sw4==1&&sw3==1&&sw2==0)//当水位2时发生 { P0=table[2];//显示水位深度:2 P2=0xFB;
} //水位低 if(shuiman==1&&sw5==1&&sw4==1&&sw3==1&&sw2==1&&sw1==1)//当水位1时发生 { dianji=0;//开电机 state=0;//电机工作指示灯打开 P0=table[1];//显示水位深度:1 P2=0xFD; } //手工上水(水位没有满的情况下才可以启动) if(shougong==0)//当按手工上水按钮时发生 { if(shuiman==1){//判断液位是否满 dianji=0;//开电机 state=0;//电机工作指示灯打开 // P0=table[0];//显示0表示手工上水已有反应 delay(2000);//延时一段时间让数码管显示给人以提示:已开始手工上水 } } }
}
|
程序源码和仿真资源
1 2 3
| 链接:https://pan.baidu.com/s/1TxRTGEdYR4wkqpnsJLwSfw 提取码:xjxw
|
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!