Single chip fully automatic washing machine program + simulation + schematic design debugging and analysis

Publisher:RoboPilotLatest update time:2019-12-05 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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;

                      }

      [1] [2] [3] [4]
      Reference address:Single chip fully automatic washing machine program + simulation + schematic design debugging and analysis

      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

      Latest Microcontroller Articles
      Change More Related Popular Components

      EEWorld
      subscription
      account

      EEWorld
      service
      account

      Automotive
      development
      circle

      About Us Customer Service Contact Information Datasheet Sitemap LatestNews


      Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

      Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号