The source program of the single chip microcomputer is as follows:
#include
//Define an array so that the numbers displayed by the digital tube are equal to the subscripts of the array elements
unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f};
sbit shuiman=P1^0;//water full
sbit sw5=P1^1;//water level 5
sbit sw4=P1^2;//water level 4 sbit sw3=P1^
3;//water level 3
sbit sw2=P1^4;//water level 2
sbit sw1=P1^5;//water level 1
sbit shougong=P1^6;//manual water filling
sbit dianji=P1^7;//motor control
bit sbit state=P3^7;//Motor working indication
/*Delay program*/
void delay02s(void)
{
unsigned char i,j,k;
for(i=100;i>0;i--)
for(j=100;j>0;j--)
for(k=248;k>0;k--);
}
main()
{
P0=0;
while(1)
{ /*************************The sensor is designed to trigger only one sensor unit at a time?****************************
//Water fullif
(shuiman==0&&sw5==1&&sw4==1&&sw3==1&&sw2==1&&sw1==1)//Occurs when only one sensor unit is closed: water level 6
{
dianji=1;//Turn off the motorstate
=1;//The motor working indicator light goes outP0
=table[6];//Show water level depth: 6**** Full
delay02s(); // Delay for a while to let the digital tube display a prompt: the water is full
}
// Water level 5
if(shuiman==1&&sw5==0&&sw4==1&&sw3==1&&sw2==1&&sw1==1)// Occurs when only one sensor unit is closed: water level 5
{
P0=table[5]; // Display water level depth: 5
}
// Water level 4
if(shuiman==1&&sw5==1&&sw4==0&&sw3==1&&sw2==1&&sw1==1)// Occurs when only one sensor unit is closed: water level 4
{
P0=table[4]; // Display water level depth: 4
}
// Water level 3
if(shuiman==1&&sw5==1&&sw4==1&&sw3==0&&sw2==1&&sw1==1)//When only one sensor unit is closed: water level 3
{
P0=table[3]; //Display water level depth: 5
}
//Water level 2
if(shuiman==1&&sw5==1&&sw4==1&&sw3==1&&sw2==0&&sw1==1)//When only one sensor unit is closed: water level 2
{
P0=table[2]; //Display water level depth: 2
}
//Water level low
if(shuiman==1&&sw5==1&&sw4==1&&sw3==1&&sw2==1&&sw1==0)//When only one sensor unit is closed: water level 1
{
dianji=0;//turn on the motor
state=0;//the motor working indicator light turns on
P0=table[1];//displays the water level depth: 1
}
//manual water
fillingif(shougong==0)//occurs when the manual water filling button is pressed
{
dianji=0;//turn on the motor
state=0;//the motor working indicator light turns on
P0=table[0];//displays 0, indicating that manual water filling has responded
delay02s();//delay for a period of time to let the digital tube display a prompt: manual water filling has started
}
}
}
Previous article:Single chip infrared transmitting and receiving circuit
Next article:LCD1602+DTH11+MQ-135 air pollution detection temperature and humidity program
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- Interface corresponding to SNVS_TAMPER3 signal
- Looking for a good and available domestic accelerometer
- nRF52832-QFAA Hardware Reference Design
- How to design the MCU+8266 program structure
- 【RPi PICO】Snapshot of the RP2040 chip
- Why does TIM1_CH3N not output PWM after configuring PWM in STM32F103C8T6?
- Please advise on the PinMux code
- Can you recommend a chip that can boost 3.3V to 5V?
- How to quickly gain points?
- [National Technology N32G457 Review] RT_Thread solves the problem that SPI NSS cannot be pulled low