MCU code for fully automatic washing machine controller design

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

The washing machine controller based on the single chip microcomputer
uses a two-digit digital tube to display the washing time, and uses a driver chip to control the motor rotation .

The course design of the fully automatic washing machine

is based on the 51 single chip microcomputer and implemented in C language.
Basic requirements

Simulate the working process of the fully automatic washing machine. Replace the washing machine motor with a motor. Display the working status of the washing machine (water inlet, soaking, washing, dehydration, end). Display the remaining working time (the washing program can be customized, the time accuracy is: seconds).
Alternate forward and reverse when washing.

Extension requirements

Different motor speeds during washing and dehydration. Add water level sensor input. Fault alarm. Add sound prompts. Other custom functions.


Design with Preteus simulation:

0.png (203.38 KB, Downloads: 13)

Download attachments   and save them to the photo album

Uploaded on 2018-6-25 06:57

 

The simulation diagram is as follows:

#include

//****************************//

#define uchar unsigned char

#define uint unsigned int


//*******************************//

//***************************//

sbit mo_r = P3^2; //Motor right control line

sbit mo_l = P3^3; //motor left control line


//****************************//

sbit key_menu = P3^4; // Menu button

sbit key_on = P3^5; // Start button

sbit key_off = P3^6; // End key

sbit key_se = P3^7; // Menu selection button


//***************************//

sbit led_in = P0^0; // Water inlet indicator light

sbit led_xi = P0^1; // laundry indicator light

sbit led_pao = P0^2; //bath indicator light

sbit led_xx = P0^3; // Dehydration indicator light

sbit led_out = P0^4; // Water out indicator light

sbit led_over = P0^5; // Washing end indicator light

sbit led_work = P0^6; // Motor working indicator light

sbit led_wring = P0^7; // Alarm indicator light


sbit other = P3^1; // Dehydration power control switch

sbit anther = P3^0; // Washing machine power control switch


//******************************//

uchar code num[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};

                                                                   //

//*********************************//

char sec = 0; // time seconds

char min = 0; // time division

uchar count=0; // interrupt count

uchar flag0=0; //Washing machine working status flag

uchar flag1=0; //Water inflow times flag

uchar flag2=0; //Water discharge times flag

uchar flag3=0; // Washing times flag

uchar err =0; // alarm flag

uchar quan = 0; // forward and reverse count  

//**********************************//

// Function declaration

//****************************************//

void delay(); // Delay function

void in(); // Water inlet subroutine

void out(); // water out subroutine

void over(); // End subroutine

void xi(); // laundry subroutine

void pao(); // bubble clothing subroutine

void xx(); // dehydration subroutine

void on(); //Work on processing subroutine

void se(); // Display menu selection

void SEG_display(); //Display time subroutine

void key_scan(); //Key scanning subroutine


//*********************************//

// Delay function

//****************************//

void delay(uint i)

{

        uint x,y;

        for(x=i;x>0;x--)

         for(y=120;y>0;y--);

}


//******************************//

//Work on processing subroutine

//************************************//

void on()

{

        TMOD=0x01;

        TH0=(65536-50000)/256;

        TL0=(65536-50000)%256;

        EA=1;

        ET0=1;

        TR0=1;


        P0 = 0xff;

        if(flag0 == 0)

            in();

        if(flag0 == 1)

            xi();

        if(flag0 == 2)

            pao();

        if(flag0 == 3)

            xx();

        if(flag0 == 4)

            out();

                

}


//*******************************//

// End subroutine

//*************************************//

void over()

{other=0;

        anther=0;

        P0 = 0xff;

        mo_r=0;

        mo_l=0;

        led_over = 0;

        EA=0;


}


//*************************************//

// Water inlet subroutine

//*************************************//

void in()

{ anther=0;

        other=0;

        P0 = 0xff;

        led_in = 0;

        flag1++;

        mo_r = 0;

        mo_l = 0;

        min = 0;

        sec = 8;

}

//*************************************//

// Laundry subroutine

//*************************************//

void xi()

{ anther=1;

         other=0;

     P0 = 0xff;

         led_work = 0;

         led_xi = 0;

         mo_r = 1;

         mo_l = 0;

         min = 1;

         sec = 36;

         quan = 0;

}

//*************************************//

// Soaking clothes subroutine

//*************************************//

void pao()

{        

    another=1;

        other=0;

        P0 = 0xff;

        led_pao = 0;

        led_work = 0;

        flag3++;

        mo_r = 1;

        mo_l = 0;

        min = 1;

        sec = 35;

        quan = 0;

}

//*************************************//

// Dehydration subroutine

//*************************************//

void xx()

{other=1;

        anther=0;

        P0 = 0xff;

        led_xx = 0;

        mo_r = 0;

        mo_l = 1;

        min = 0;

        sec = 50;

}

//*************************************//

// Water outlet subroutine

//*************************************//

void out()

{ anther=0;

        other=0;

        P0 = 0xff;

        led_out = 0;

        flag2++;

        mo_r = 0;

        mo_l = 0;

        min = 0;

        sec = 5;

}

//*************************************//

// Display menu selection

//*************************************//

void se()

{

        P0 = 0xff;

        if(flag0 >= 5)

                flag0 = 0; 

        if(flag0 == 0)

        {

                led_in = 0;

        }

        if(flag0 == 1)

        {

                led_xi=0;

        }

        if(flag0 == 2)

        {

                led_pao=0;

        }

        if(flag0 == 3)

        {

                led_xx=0;

        }

        if(flag0 == 4)

        {

                led_out=0;

        }

}

//************************************//

//Menu processing subroutine

//**********************************//

void menu()

{        

    min = 0;

        sec = 0;

        mo_r=0;

        mo_l=0;

        SEG_display();


           while(1)

        {

           if(key_on == 0)

                {

                        delay(5);

                        if(key_on == 0)

                        {

                                while(!key_on);

                                on();

                                break;

                        }

                }

//**************************//

                if(key_off == 0)

                {

                        delay(5);

                        if(key_off == 0)

                        {

                                while(!key_off);

                                over();

                                break;

                        }

                }

//****************************//

                if(key_se == 0)

                {

                        delay(5);

                        if(key_se == 0)

                        {

                                while(!key_se);

                                flag0++;

                                se();

                        }

                }                                

        }

}

//*************************************//

//Key scanning subroutine

//*************************************//

void key_scan()

        if(key_menu == 0)

        {

                delay(5);

                if(key_menu == 0)

                {

                        while(!key_menu);

                        menu();

                }

        }

//************************************//

        if(key_on == 0)

        {

                delay(5);

                if(key_on == 0)

                {

                        while(!key_on);

                        on();

                }

        }

//*************************************//

        if(key_off == 0)

        {

                delay(5);

                if(key_off == 0)

                {

                        while(!key_off);

                        over();

                }

        }

}

//*******************************//

// Display subroutine

//*************************************//

void SEG_display()

{

        P1=0x01;

        P2 = num[min/10];

        delay(10);

        P1 = 0x02;

        P2 = num[min%10];

        delay(10);

        P1 = 0x04;

        P2 = num[sec/10];

        delay(10);

        P1 = 0x08;

        P2 = num[sec%10];

        delay(10);

}

//*************************************//

// Main function

//*************************************//

void main()

{

        led_in=0;

        anther=0;

        other=0;

        while(1)

        {

                

                SEG_display();

                key_scan();

        }

}

//**********************************//

// Timer 0 interrupt handler

//**********************************//

void timer0() interrupt 1

{

        TH0=(65536-50000)/256;

        TL0=(65536-50000)%256;

        count++;

    if(count==20)

        {        

                 count = 0;

                sec--;

                if((flag0==1)||(flag0==2))

                {

                    quan++;

                        switch(quan)

                         {

                                 case 1:mo_r=1;mo_l=0;break;

                                case 10:mo_r=0;mo_l=0;break;

                                case 15:mo_r=0;mo_l=1;break;

                                case 25:mo_r=0;mo_l=0;break;

                                default:;

                         }


                        if(quan==30)

                        {

                           quan=0;

                        }


                }

         //**********************************//

                if((sec == 0)&&(min != 0))

                {

                  min--;

                  sec = 59;

                 }

          //**********************************//

                if((sec<0)&&(min==0)&&(flag0==0)) //Water inflow ends

                {         

                     switch(flag1)

                         {

                                 case 1:flag0=1;xi();break;

                                case 2:flag0=2;pao();break;

                                case 3:flag0=2;pao();break;

[1] [2]
Reference address:MCU code for fully automatic washing machine controller design

Previous article:Single chip electronic clock class design assembly language code and proteus simulation
Next article:VL53L0X laser ranging module MCU driver

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号