51 microcontroller realizes simple washing machine control system design

Chapter 1 Main tasks of course design

1. Design content

(1) Design a washing machine control system that uses the speed of the DC motor to characterize three different washing methods: weak washing, strong washing, and rinsing;

(2) Use three independent buttons to set different washing methods for the laundry to achieve a maximum timer of 10 minutes:

    Silk clothes: Rinse for 3 minutes

Cotton clothes: weak wash for 2 minutes; strong wash for 5 minutes; rinse for 3 minutes;

Chemical fiber clothes: strong wash for 4 minutes; rinse for 2 minutes;

(3) When the timer expires, the buzzer will sound.

Chapter 2 Overall Design

2.1 Overall design and functional description

This design uses the microcontroller AT89C51 as the control core and adopts a modular design. It is divided into the following functional modules: microcontroller control system module, power module, clock module, reset module, button control module, DC motor control module and display module, etc. The washing machine mainly has three functions: scheduled washing mode, alarm and pause.

The system structure block diagram is shown in Figure 2-1 below: 

 

The functions of each module are as follows:

1.AT89C51 microcontroller: the core control device of the washing machine control system.

2. Clock circuit module: generates a clock to drive the microcontroller to work.

3. Reset circuit module: Reset the registers of the microcontroller to return the program pointer to its original position. So that when the system is running, the program starts executing from the initial position.

4. Motor speed control module: The L298 driver chip is used to input different signals to cause the motor to rotate forward and reverse.

5. Display module: The display module circuit uses 3 LEDs, 3 resistors and an LCD screen to connect to the microcontroller, and uses C language programming to realize the automatic display function of the washing machine.

6. Alarm module: When the timer expires, the buzzer will sound.

2.2 System hardware design

(1) Design of microcontroller control module

AT89C51 microcontroller is a high-efficiency microcontroller and a low-power high-performance microcontroller. The microcontroller is the core of this design and mainly plays a control role. It adopts a 40-pin dual in-line package and has 32 external bidirectional input/output (I/O) ports. It also contains 2 external interrupt ports and 2 16-bit interrupt ports. Program the timing counter and 2 full-duplex serial communication ports. Due to the limitation of the number of pins, many pins have secondary functions. The appearance and pin arrangement are shown in Figure 2-2.

 The main pin functions of AT89C51 microcontroller:

VCC: Supply voltage.

 GND: Ground.

 Port P0: Port P0 is an 8-bit open-drain bidirectional I/O port, each pin can absorb 8TTL gate current. When a 1 is written to the pin of port P1 for the first time, it is defined as a high-impedance input. P0 can be used in external program data memory and can be defined as the eighth data/address bit.

P1 port: P1 port is an 8-bit bidirectional I/O port with an internal pull-up resistor. The P1 port buffer can receive and output 4TTL gate current. After writing 1 to the P1 port pin, it is internally pulled high and can be used as an input. When P1 port is externally pulled down to low level, it will output current. This is due to the internal pull-up.

 P2 port: P2 port is an 8-bit bidirectional I/O port with an internal pull-up resistor. The P2 port buffer can receive and output 4 TTL gate currents. When P2 port is written with 1, its pin is pulled up by the internal pull-up resistor. Pulled high and used as input. Therefore, when used as an input, the pin of port P2 is externally pulled low and will output current.

P3 port: P3 port is 8 bidirectional I/O ports with internal pull-up resistors, which can receive and output 4 TTL gate currents. When a 1 is written to port P3, they are internally pulled high and used as inputs. As an input, since the external pull-down is low, port P3 will output current (ILL). This is due to the pull-up. RST: Reset input. When the oscillator resets the device, the RST pin is held high for two machine cycles.

ALE/PROG: When accessing external memory, the address latch allows the output level to be used to latch the bit byte of the address. During FLASH programming, this pin is used to input programming pulses. In normal times, the ALE terminal outputs a positive pulse signal at a constant frequency period, which is 1/6 of the oscillator frequency. Therefore it can be used as a pulse to an external output or for timing purposes.

PSEN: Strobe signal for external program memory. PSEN is asserted twice per machine cycle during instruction fetches from external program memory. But when accessing external data memory, these two valid PSEN signals will not appear.

 EA/VPP: When EA remains low, the external program memory (0000H-FFFFH) is used during this period, regardless of whether there is internal program memory. Note that in encryption mode 1, the EA is internally locked to RESET; when the EA terminal remains high, the internal program memory is locked. During FLASH programming, this pin is also used to apply the 12V programming power (VPP).

                      

Figure 2-2 Pin diagram of AT89C51 microcontroller

 Power supply, clock signal and reset circuit are the basic conditions for the operation of the microcontroller, and they are indispensable. The basic working circuit of the AT89C51 microcontroller system includes the power circuit, clock circuit, and reset circuit. Its block diagram is shown in Figure 2-3.

          

 (2) Clock circuit module design

The power circuit module provides +5V power to the system circuit and other modules. The power supply can be provided by a switching power supply.

Design of clock circuit module

 Since the AT89C51 microcontroller chip has a clock oscillation circuit, the microcontroller of this system adopts the internal clock method. As long as the XTAL1 and XTAL2 pins of the microcontroller are externally connected to a quartz crystal and a trimmer capacitor, a self-excited oscillator is formed and a clock pulse signal is generated inside the microcontroller. , the specific circuit design is shown in Figure 2-4. Working principle: Clock signals are usually obtained in two circuit forms: internal oscillation and external oscillation. By connecting external timing components to the XTAL1 and XTAL2 pins, a self-oscillation circuit can be formed. The timing component usually uses a parallel resonant circuit composed of a quartz crystal and a capacitor. Generally, capacitors C4 and C5 mainly play the role of frequency fine-tuning, and the capacitance value can be selected to be about 30pF or 40pF; the crystal oscillator, referred to as crystal oscillator, has a crystal frequency (fosc) range of 1. 2MHz~12MHz, and 12MHz is selected in this design. The higher the crystal oscillation frequency, the higher the system clock frequency, and the faster the microcontroller operates.

Figure 2-4 Clock oscillation circuit

(3) Reset circuit module design

The reset circuit puts the microcontroller or other components in the system in a certain state. When a high level is introduced at the RST pin of the MCS-51 series microcontroller and maintained for 2 machine cycles, the microcontroller performs a reset operation internally. There are two basic forms of reset operation: one is power-on reset, and the other is button reset. This design uses a button reset method. As shown in Figure 2-5, the working principle: When the button is pressed, RST is directly connected to VCC, and more than 2 high levels appear to form a reset. At the same time, the electrolytic capacitor is short-circuited and discharged; when the button is released, the capacitor is charged and current flows through the resistor. , RST is high level, it is still reset. After charging is completed, the capacitor is equivalent to an open circuit, RST is low level, and it works normally.

Figure 2-5 Reset circuit

(4) Button control circuit design

In the design of microcontroller, an important module is the design of buttons. Common microcontroller button designs are divided into independent and determinant (matrix). The design of independent buttons is simple, but it occupies more I/O ports; the design of row-type buttons is relatively complex, but it occupies less I/O ports. As shown in Figure 2-6.

 Figure 2-6 Control circuit. For ease of use, five independent buttons are designed, namely silk, cotton, chemical fiber, start and pause.

Silk: K1 key selects the washing method;

Cotton: K2 key selects the washing method;

Cotton: K2 key selects the washing method.

Start: The washing machine starts and starts washing.

Stop: The washing machine will stop working no matter what the working status is, and the buzzer will alarm to end the washing.

(5) Buzzer alarm circuit design 

In this design, when a certain laundry program is completely completed, there will be a 3S buzzer alarm time. The buzzer circuit design is shown in Figure 2-7. The signal directly output by the microcontroller is not enough to drive the buzzer. Therefore, add a PNP transistor as a driver between the microcontroller and the buzzer. The base of the transistor is connected to the corresponding I/O of the microcontroller through a 4.7K ohm resistor, the power supply and buzzer are connected to the emitter, and the collector is connected to ground. This completes the buzzer driving circuit.

Figure 2-7 Buzzer driving circuit

(6) Display circuit design

 In microcontroller application systems, the operating status and operating results of the system usually need to be displayed visually. This design uses three common anode light-emitting diodes and an LCD display. The display circuit is shown in Figure 2-8. The display circuit consists of 3 LEDs and 3 resistors. The three resistors are all 100 ohms each. In the circuit, the resistors play the role of current limiting protection to prevent the LED from being burned out. The three LEDs are common anodes. When the input is low, the LED lights up. When the input is high, the LED goes out.

      Figure 2-8 Display circuit (LED light and LCD display)

(7) DC motor drive circuit design

Figure 2-9 DC motor circuit

 Figure 2-9 shows a typical DC motor control circuit

The DC motor is controlled through the L298 motor driver chip, which can control two motors at the same time. When IN1 and IN2 input high level or low level at the same time, the motor stops and does not rotate. When IN1 inputs low level, IN2 inputs high level, the motor reverses. At the same time, ENA and ENB are enable terminals respectively, which can control the motor's PWM speed. . L298N can directly control the motor. By setting its control level through the I/O input of the main control chip, it can drive the motor in forward and reverse directions. It is simple to operate and has good stability, and can meet the large requirements of DC motors. Current driving conditions. Use digital frequency to replace the voltage waveform of Vc, especially the Vc waveform corresponding to the rising or falling edge of the PWM pulse.

2.3 Hardware simulation circuit diagram

As shown in Figure 2-10

                             

Chapter 3 System Software Design

The software is built on the hardware platform to complete the control and coordination of each part of the hardware. System functions are realized by software and hardware. Due to the scalability of software, the final system functions may be strong or weak, and the difference may be huge. The software adopts a modular design method, which not only facilitates program design and debugging, but also reduces software failure rates and improves software reliability. At the same time, comprehensive testing of software is also an important means of detecting errors and troubleshooting. Since programming mostly involves numerical operations, it is relatively complex, and the display design of LCD lamps requires multiple selection judgments, which is difficult to achieve with our usual assembly programming. Here we choose a program with good value shifting and structure. Programming is implemented using C language that is clear and capable of performing complex operations.

3.1 Main program flow of the software

The functions of the entire system are realized by hardware circuits and software. When the hardware is basically finalized, the software is basically finalized. Based on the different functions of the software, it can be divided into two categories: One is the monitoring software (main program) which is The core of the entire software is specially used to coordinate the connection between various execution modules and operators. The second is the execution software (subroutine), which is used to complete various substantive tasks, such as measurement, calculation, display, communication, etc. Each execution software is a small execution module. Here each module is listed one by one, and the function definition and interface definition are made for each execution module. After each execution module is planned, the monitoring software can be planned. First, we must select the most appropriate monitoring program structure based on the overall function of the system, and then reasonably arrange the scheduling relationship between the monitoring software and the execution software based on real-time conditions.

After the washing machine is powered on, the microcontroller first initializes the program, including the initialization of timer 0, external interrupt 0, external interrupt 1 and the setting of the initial values ​​of each parameter. Then perform button detection, and the default washing intensity is "silk clothes" rinsing for 3 minutes. Scan the button status to determine the washing process. When the start button is pressed, the washing machine enters the working state from the standby state and displays the clothes, washing mode and countdown on the LCD1602 display. Among them, silk clothes: rinse time is 3 minutes; cotton clothes: weak wash for 2 minutes; strong wash for 5 minutes; rinse for 3 minutes; chemical fiber clothes: strong wash for 4 minutes; rinse for 2 minutes; control the buzzer to sound when the washing is completed. .

The main flow chart is as shown in Figure 3-1                 

 

3.2.Main subroutines

The main subroutines include silk clothes washing program, cotton clothes washing program, chemical fiber clothes washing program, motor control subroutine, T0 interrupt service subroutine, etc.

3.2.1 Silk clothing washing program design

Start selecting button, press K1 to select silk clothes, then press K4 to start the washing machine, enter the 3-minute timer rinse, if you press K5 during the process, it will pause, the buzzer will sound an alarm, and the washing will end; otherwise, the buzzer will end the 3-minute rinse. An alarm sounds and the laundry is finished.

The flow chart is as shown in Figure 3-2-1

3.2.2 Design of washing program for cotton clothes

Start selecting button, press K2 to select cotton clothes, then press K4 to start the washing machine, enter the 2-minute scheduled weak wash, if you press K5 during the process, it will pause, the buzzer will sound an alarm, and the washing will end; otherwise, the weak wash will end and enter 5 minutes. For strong washing, pause and end the washing in the same way. Otherwise, after strong washing and rinsing for 3 minutes, the buzzer will sound an alarm and the washing will end.

The flow chart is as shown in Figure 3-2-2

3.2.3 Design of washing program for chemical fiber clothes

Start selecting button, press K3 to select chemical fiber clothes, then press K4 to start the washing machine, enter the 4-minute timed weak wash, if you press K5 during the process, it will pause, the buzzer will sound an alarm, and the washing will end; otherwise, the weak wash will end and enter the 2-minute rinse. The buzzer sounds an alarm and the washing process ends.

The flow chart is as shown in Figure 3-2-3

3.2.4 Design and implementation of strong washing, weak washing and rinsing programs with DC motor speed

The digital frequency of DC motor speed can realize strong washing, weak washing and rinsing.

When the digital frequency of the motor speed is less than 10, the motor rotates to achieve rinsing; when the digital frequency of the motor speed is greater than 10 and less than 30, the motor rotates to achieve rinsing; when the digital frequency of the motor speed is greater than 30 and less than 50, the motor rotates to achieve rinsing;

The flow chart is as shown in Figure 3-2-4

DC motor speed realizes strong washing, weak washing and rinsing procedures:

void pwm(uchar k)//weak wash, strong wash, rinse; 

{

uchar i;

for(i=0;i<99;i++)

{

if(k==1)

{

if(i<30) //weak wash

out=0;

else

out=1;

}

if(k==2)

{

if(i<50) //Force washing

out=0;

else

out=1;

}

if(k==3)

{

if(i<10) //rinse

out=0;

else

out=1;

}

}

}  

3.2.5 T0 interrupt service subroutine

This subroutine uses timer T0 to interrupt. The main function of this subroutine is to make the 1 second flag true when the time reaches 1 second. Return to the main function and reduce the running time by 1. If the 1 second flag is false, call the subroutine again. The program uses this to reduce the display time by 1 per second.

Chapter 4 System Simulation

4.1 Protoeus8.11 and keil μ Vision5

This design uses Proteus 8.11 software for drawing, and C language controls the microcontroller. It is easy to read and understand. Keil μVision5 software is used for debugging.

4.2 Problems encountered during debugging :

When the compilation is passed, but when the Debug function is clicked and you can enter the debugging interface, it immediately crashes. There are Chinese characters in the path name and the computer user name is Chinese.

Solution: Change to a shallower path. After changing the path, you must recompile everything, otherwise MDK will still look for the source code of the old path when debugging; change individual paths, just do not include Chinese in the path; change the computer user name. This computer: Right-click->Manage->Local Users and Groups->Users. Right click -> Rename.

After modifying and recompiling, the compilation result is shown in Figure 4-1 below:

Figure 4-1 Keil μVision5 debugging results

4.3 Simulation diagram

After generating the .hex file in Keil, open the schematic diagram in proteus and load the generated file into the microcontroller. After repeated debugging, the three clothing washing methods are as follows: 4-2, 4-3-1, 4-3- 2, 4-3-3, 4-4-1, 4-4-2 are shown:

(1) Simulation diagram of silk silk clothes: The 3-minute countdown to rinsing reaches 0 and the buzzer alarm indicates the end of washing.

Figure 4-2 Proteus8.11 silk silk clothes being rinsed

(2) Simulation diagram of cotton clothes: Cotton clothes are first washed lightly for two minutes, then washed hard for five minutes, and then rinsed for three minutes to achieve a maximum countdown of 10 minutes. When the timer reaches 0, the buzzer alarms and the washing is completed.

Figure 4-3-1 Proteus8.11 cotton cotton clothes are being washed weakly

Figure 4-3-2 Proteus8.11 cotton cotton clothes being washed

Figure 4-3-3 Proteus8.11 cotton cotton clothes being rinsed

(3) Simulation diagram of chemical fiber clothes: Chemical fiber clothes are first forced washed for four minutes and then rinsed for two minutes to achieve a 6-minute countdown. When the timer reaches 0, the buzzer alarms and the washing is completed.

Figure 4-4-1 Proteus8.11chemical chemical fiber clothes being washed

Figure 4-4-2 Proteus8.11chemical chemical fiber clothes are being rinsed

Chapter 5 Summary

1. Through the final simulation and debugging of hardware and software, the research work on this topic has reached the expected requirements, which can be summarized as follows:

(1) This topic realizes the automation of the washing machine control system.

(2) The system hardware design uses chip AT89C51, capacitor, crystal oscillator, resistor, L298 driver, lcd1602 liquid crystal display, LED light, buzzer, button, transistor PNP, DC motor, etc.

(3) System software design includes initialization program, T0 interrupt service program, three mode programs, LCD1602 display program, delay function, alarm program, etc., completing the automation of the washing machine control system.

2. This design is mainly based on AT89C51 microcontroller, and the washing machine is simply designed and explained. This design can be said to be a combination of software and hardware, with hardware as the main component and software as the supplement. Today's technology is developing rapidly, and microcontroller embedded development has a bright future. Because microcontrollers are economical, practical, and easy to develop, they still occupy a wide market in industrial control, home appliances and other fields. Since I have not seriously studied the C language of the 51 microcontroller before, I feel that the task of course design is very urgent. Through the design of this system, I learned the basic processes of hardware development and software development and gained a certain ability to control this development process. Through actual programming and continuous debugging, I have become more proficient in the programming methods of microcontroller-related programs. In the continuous design process, I have a deeper understanding of the microcontroller system, and I have further become familiar with and mastered the functions of microcontrollers. Structure and its working principle, I have a deeper understanding of timing, interrupt programs, etc., and learned how to skillfully use the simulation software Proteus8.11 and the programming software Keil uVision5. Although there is a lot of hard work in the process of programming, it is more of a joy after the program is successfully debugged.

In short, this course design was a relatively comprehensive, creative and exploratory exercise for me, and it fulfilled my wish when choosing the topic. I am deeply touched and will benefit a lot from my future study, work and life!

                                Chapter 6 Source Code (please refer to the author’s profile for Q&A if necessary)

Guess you like

Origin blog.csdn.net/qq_51660769/article/details/129211182