1. Design tasks and requirements
Use 51 single-chip microcomputer to simulate a fully automatic intelligent washing machine.
Key function requirements
Use the "K1" key to step through the four modes of "Standard] Economy, Single, Drainage" and execute the corresponding program. The corresponding indicator light is on.
Use the "K2" key to step through the two modes of "strong wash and weak wash", execute the corresponding program, and the corresponding indicator light will light up.
Use the "K3" key to control the washing machine's operation, pause and alarm release functions.
Mode function selection requirements
The steps of a general washing machine are: washing, rinsing, and dehydration. When in a certain state, the corresponding indicator light flashes at a cycle of 0.7S. When the washing machine is in the washing process, the washing indicator light flashes. You can set the specific operation process by selecting the mode.
Standard mode: water inlet—> washing—> drainage—> water inlet—> rinsing—> drainage—> water inlet—> rinsing—> drainage—> spin.
Economic mode: water inlet—> washing—> drainage—> water inlet—> rinsing—> drainage—> dehydration.
Single mode: water inlet->washing.
Drainage method: drainage -> dehydration.
Strong washing means that the motor speed is fast, and weak washing means that the motor speed is slow.
Machine function requirements
The default state when the machine is turned on is standard mode and strong washing.
During the washing and rinsing process, the motor rotates forward once and reverses once, running continuously.
During the water inlet and dehydration process, the corresponding indicator light comes on and the relay closes.
When executing a certain step, only the "K3" key is valid. Press it to pause, and then press it again to resume.
Scheme design and demonstration
The block diagram of the implementation scheme of the fully automatic washing machine is shown in Figure 1. It mainly consists of a power supply, a single-chip minimum system, a switch detection circuit, a control button input circuit and an LED indication circuit, a relay and a motor circuit.
Hardware circuit design
Figure II
Circuit design of motor drive module
The motor drive uses the LD298 motor drive chip. The single-chip P25 and P24 are connected to IN1 and IN2 of L298 respectively. ENA is directly connected to VCC. The four diodes VD3 to VD6 added later play a continuous role. The motor drive circuit schematic is shown in Figure 2.
Power module circuit design
The power supply VCC and VS of the motor driver chip are isolated by a 0 ohm resistor R20 to power LD298.
Control buttons
As shown in Figure 2, the K3 key is connected to the external interrupt 0 of the microcontroller, and the control functions of running, pausing, and continuing to run are realized through interrupts. When the K3 key is pressed for the first time (num2=1), it runs normally, and when the K3 key is pressed for the second time (num2=2), it pauses.
Inlet valve and drain valve control relay
As shown in Figure 2, P23 of the microcontroller is used to control the drain valve relay, and P22 is used to control the inlet valve relay. When the corresponding output of P22 and P23 is 0, the corresponding valve is opened, and when the output is 1, the corresponding valve is closed.
software design
1) Flowchart
The main program flow chart is shown in Figure 3.
program
The program is attached at the end
Figure 3
Debugging and profiling
1. Software debugging:
When writing program code, you should first build the hardware circuit, and then write the program code according to the hardware circuit. When debugging the program, first ensure that the program can run without errors, and then burn it into the actual object to observe the results.
2. Hardware debugging:
After the hardware circuit design and software design are completed, the program is burned into the microcontroller to observe whether the running results meet the requirements. If it does not meet the design requirements, you should first check whether the hardware can work properly, such as using the correct code that comes with the experimental board to detect the hardware circuit; then debug the program code according to the design requirements. For example, the design requires LCD, matrix keyboard, timer, independent keyboard, interrupt and LED lights. If the LCD module cannot display normally or displays garbled characters during the test, the LCD module should be separated for testing, and the same applies to other modules. After the program is debugged, it should be run repeatedly on the hardware circuit to ensure the stability of the program and hardware circuit.
Summarize
I feel that I have gained a lot from this MCU Programming Week, especially in terms of improving my work and self-learning abilities. I started to learn MCU in the laboratory in the first semester of my sophomore year, but because I was self-taught, my self-awareness was very poor, and self-study was also a relatively difficult thing. During the learning process, I was always learning and imitating other people's codes. I always felt that I could understand the program codes written by others, so I basically did not conceive and write program codes by myself. The only time I made a fully automatic washing machine was by looking at the source code written by others and constantly modifying it.
When I first got the design topic this time, I thought it was not difficult and I was full of confidence at the beginning. However, I felt a little confused when I started to do it, especially because there were some knowledge in the topic that I had not learned yet, such as liquid crystal. So our group had to learn about liquid crystal first. After learning the modules that needed to be learned, we first wrote the main program without any clue. The whole process was difficult. Then we learned other people's design methods and began to divide the work and modules. The group built the hardware circuit and wrote the program in groups. First build the circuit, then write the program. In the process of writing the program, we divided the program into several small modules: LCD display module, keyboard input module, and answer module, and then wrote each module as a subroutine. In the main program, we only need to call each subroutine.
During the debugging process, I encountered various problems, but they were all solved one by one. During the entire design process, I learned a lot of knowledge that teachers could not teach me in class, and I also made a product of my own.
The microcontroller source program is as follows:
#include #define uchar unsigned char #define uint unsigned int uchar num=0,num1=0,num2=0,num3=0,num4=0,num5=0,num6=0,flag=0,flag1=0,flag4=0,flag5=0,circle=0; sbit ledbiaozhun=P1^0; //LED indicator light sbit ledjingji =P1^1; sbit leddandu =P1^2; sbit ledpaishui =P1^3; sbit ledqiangxi =P1^4; sbit ledruoxi =P1^5; sbit ledxidi =P1^6; sbit ledpiaoxi =P1^7; sbit ledtuoshui =P2^0; sbit sshuiwei =P3^6; //water level switch sbit sgai =P3^7; //cover switch sbit paishui=P2^3; //drain valve control sbit jinshui=P2^2; //water inlet valve control sbit U2=P2^4; sbit U3=P2^5; sbit k1=P3^0; // Step by step change the four modes of "standard, economic, single, drainage" sbit k2=P3^1; // strong wash, weak wash sbit k3=P3^2; //Run, pause and release the alarm function void init() { uchar a=0,b=0,c=0; TMOD=0x01; //T0 works in mode 1 TH0=(65536-50000)/256; //timing time 50ms TL0=(65536-50000)%256; EA=1; //Open the general interrupt ET0=1; //Open T0 interrupt TR0=0; //Close T0 EX0=1; //Open external interrupt 0 IT0=1; //External interrupt 0 edge trigger mode U2=1; //Motor stops U3=1; P0=0xff; } void delayms(uint xms) //delay { uint i,j; for(i=xms;i>0;i--) for(j=110;j>0;j--); } void key() //Control button { circle=1; if(k1==0) //Standard, Economy, Single, Drainage Press { delayms(10); //delay to eliminate jitter if(k1==0) //Re-judge { num++; //The number of times K1 is pressed plus 1 if(num==4) num=0; //equal to 4, the number of presses is cleared to 0 while(!k1); //Wait for the button to be released } } if(k2==0) //Strong or weak selection { delayms(10); //delay to eliminate jitter if(k2==0) //Re-judge { num1++; // press times plus 1 if(num1==2) num1=0; //equal to 2, the number of presses is cleared to 0 while(!k2); //Wait for the button to be released } } } void qiang() //strong { if(flag4==0) //Motor rotates forward { U2=0; U3=1; } if(flag4==1) //motor reverse { U2=1; U3=0; } } void ruo() //weak { if(flag5==0) //Motor rotates forward { U2=0; U3=1; }
Previous article:Simulation and Program of Stepper Motor Controlled by STC89C52RC MCU
Next article:MCU + ADC0832 simple digital voltmeter proteus simulation and program source code
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
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
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- The first article is about downloading GD32L233C development resources
- In a superheterodyne receiver, after selecting the frequency of the signal, how does the receiver know what the frequency is in Hz?
- Purgatory Legend-RAM War
- TI Smart Building Systems: Using mmWave to count and track people
- RF front-end market in the 5G era
- FPGA_100 Days_Calculator Design
- What is a thick film non-inductive resistor? What is its main use?
- The video signal carrying capacity close to 1MHz is not enough. What op amp can I use to design a voltage follower?
- MCU's ADC sampling error
- LC Application Circuit Collection