51 single chip washing machine proteus simulation and source code design

Publisher:东土大唐88Latest update time:2019-12-31 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

A fully functional washing machine simulation and source code, controlled by a 51 single-chip microcomputer, with strong wash button, weak wash button, standard wash button, and spin dry button.


It has all the functions such as liquid level sensor, drain valve button, etc.

The simulation schematic diagram is as follows

0.png

It also has various indicator lights:
0.png 

The microcontroller source program is as follows:

#include

#define uchar unsigned char

#define uint unsigned int

#define qiang_ledon qiang_led=1;

#define qiang_ledoff qiang_led=0;

#define biao_ledon biao_led=1;

#define biao_ledoff biao_led=0;

#define ruo_ledon ruo_led=1;

#define ruo_ledoff ruo_led=0;

#define piao_ledon piao_led=1;

#define piao_ledoff piao_led=0;

#define sgan_ledon sgan_led=1;

#define sgan_ledoff sgan_led=0;

#define jin_ledon jin_led=1;

#define jin_ledoff jin_led=0;

#define pai_ledon pai_led=1;

#define pai_ledoff pai_led=0;

unsigned char code Tab[11]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F}; //Segment code table of digital tube display 0~9

unsigned char int_time; //Record interrupt times

unsigned char second; //Store seconds

uint t=0,tt=0;

   sbit k1=P0^0;

   sbit k2=P0^1;

   sbit k3=P0^2;

   sbit sg=P0^3;

   sbit hk1=P0^4;

   sbit hk2=P0^5;

   sbit ledon=P0^7;

   sbit qiang_led=P2^0;

   sbit biao_led=P2^1;

   sbit ruo_led=P2^2;

   sbit piao_led=P2^3;

   sbit sgan_led=P2^4;

   sbit jin_led=P2^5;

   sbit pai_led=P2^6;

   sbit p30=P3^0;

   sbit p31=P3^1;

   sbit beepon=P2^7;

   sbit sm1=P3^6;

   sbit sm2=P3^7;

void delay2(void)

   {

  unsigned char m;

  for(m=0;m<200;m++)

        ;

   }


void delay1(int s)

   { 

   int i;

   for(;s>0;s--)

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

   }


void delay(uint i)

   {

   uchar j;

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

   for(j=255;j>0;j--);

   }


void DisplaySecond(unsigned char k)

{

   

   sm1=0; //P2.6 pin outputs low level, DS6 lights up 

   P1=Tab[k/10]; //Display tens digit

     delay2();

     delay2();

   sm1=1;

   sm2=0; //P2.7 pin outputs low level, DS7 lights up 

   P1=Tab[k%10]; //Display the unit digit

     delay2();

     delay2();

   P3=0xff; //Turn off all digital tubes

   P1=1; //Display the unit digit

     delay2();

     delay2();

}

           

void beep()

   {

          p30=0;

    p31=0;

           t=0;

        while(1)

        {

          beepon^=1;

      delay(300);

      if(t>=80) break;

        }

        beepon=0;

        biao_led=0;

    }

          

void f_qiang()

    {         

         qiang_ledon;

         t=0;

         tt=0;        

     int_time=0;

     second=00;

         while(1)

    {        

          if(tt>=400) break; 

      t=0;

          while(t<80&&tt<=400)

          {        

            p31=0;

            p30=1; //Forward 4s

        DisplaySecond(second);

            }

          t=0; //Reverse 4s        

          while(t<80&&tt<=400)

          {

            p30=0;

            p31=1;

            DisplaySecond(second);

            }

     }

          p30=0;

          p31=0;          

     }


void f_biao()

        {

          qiang_led=0;

      biao_led=1;

          t=0;

          tt=0;

      int_time=0;

      second=00;

         while(1)

     {

           if(tt>=400) break; 

           t=0;

          while(t<60&&tt<=400)

           {        

          p31=0;

                  p30=1; //Forward 3s

          DisplaySecond(second);

       }


                t=0; //Reverse 3s

          while(t<60&&tt<=400)

       {

              p30=0;

                  p31=1;

                  DisplaySecond(second);

                }

       }

       p30=0;

           p31=0;

         }


void f_ruo()

    {

          qiang_led=0;

          biao_led=0;

          ruo_led=1;

          t=0;

          tt=0;

      int_time=0;

       second=00;

                while(1)

       {

                    if(tt>=400) break; 

                 t=0;

               while(t<40&&tt<=400)

           { p31=0;

                        p30=1; //Forward 2s

                DisplaySecond(second);

                }

             t=0; //Reverse 2s

               while(t<40&&tt<=400)

            { p30=0;

                        p31=1;

                        DisplaySecond(second);

                      }

         }

                p30=0;

            p31=0;

       }


void f_piao()

        {

           qiang_ledoff;

           biao_ledoff;

           piao_ledon;

           t=0;

           tt=0;

       int_time=0;

       second=00;

                 while(1)

          {

                      if(tt>=400) break; 

                   t=0;

                 while(t<40&&tt<=400)

               { p31=0;

                        p30=1; //Forward 2s

                    DisplaySecond(second);

                   }

                   t=0; //Reverse 2s

                 while(t<40&&tt<=400)

               { p30=0;

                            p31=1;

                             DisplaySecond(second);

                       }

             }

          p30=0;

      p31=0;

          piao_ledoff;

          }


void pai_leds()

     {

            p30=0;

            p31=0;

               pai_led=1; //Drain valve light is on and waiting for Hall switch 2 

            while(hk2);

            if(hk2==0) //If closed

            pai_led=0; //Drain light off

     }


void jin()

    {

            p30=0;

            p31=0;

            jin_ledon; 

            while(hk1);

            if(hk1==0)

            jin_ledoff;

     }


void sgan()

    {

            sgan_ledon; //Spin-drying light on

            t=0;

        int_time=0;

        second=00;

             while(t<=400)

            {        

                            p31=0;

                        p30=1;        

                DisplaySecond(second);

                 }

        sgan_ledoff;

    }


void sgan1()

    {

           sgan_ledon;

           t=0;

       int_time=0;

       second=00;

             while(t<=400)

            {        

                           p31=0;

                   p30=1;        

               DisplaySecond(second);

                 }

        piao_ledoff;

        sgan_ledoff;

        beep();

            t=401;

    }



void f_an1()

   {  

        qiang_ledon; //Solution 1: the light is on

        jin(); //Enter strong wash

        f_qiang(); //Loop 20S

        delay1(4000); //delay 4s

        f_biao(); //Loop 20S

        delay1(4000); //delay 4s

        f_ruo(); //Loop 20S

        ruo_ledoff;        

        pai_leds();

        delay1(1000); //Delay 1S to enter the spin dry

        sgan(); //Spin dry for 20 seconds

        sgan_ledoff;

        ruo_ledoff;

        piao_ledoff;

        jin();

        delay1(1000); //delay 1S to enter rinsing

        f_piao(); //Loop 20S

        sgan_ledoff;

        piao_ledoff;

        pai_leds();

        delay1(1000); //Delay 1S to enter the spin dry

        sgan1(); //Finally spin dry for 20 seconds

        delay(500); //delay        

        beep();

   }


void f_an2()

   {  

        biao_ledon; //Solution 1: light on

        jin();

        f_biao(); //Loop 20S

        delay1(4000); //delay 4S

        f_ruo(); //Loop 20S

        ruo_ledoff;

        pai_leds();

        delay1(1000); //Delay 1S to enter the spin dry

        sgan(); //Spin dry for 20 seconds

        ruo_ledoff;

        piao_ledoff;

        jin();

        delay1(1000); //delay 1S to enter rinsing

        f_piao(); //Loop 20S

        sgan_led=0;

        pai_leds();

        delay1(1000); //Delay 1S to enter the spin dry

        sgan(); //Finally spin dry for 20 seconds

        delay(500); //delay 5s

        piao_led=0;

        beep(); 

   }


void f_an3()

  {  

        ruo_led=1; //Scheme 1 light is on

        jin();

        f_ruo(); //Loop 20S

        ruo_ledoff;

        pai_leds();

        delay1(1000); //Delay 1S to enter the spin dry

        sgan(); //Spin dry for 20 seconds

        ruo_ledoff;

        piao_ledoff;

        jin();

        delay1(1000); //delay 1S to enter rinsing

        f_piao(); //Loop 20S

        sgan_led=0;

        pai_leds();

        delay1(1000); //Delay 1S to enter the spin dry

        sgan(); //Finally spin dry for 20 seconds

        delay(500); //delay 5s

        piao_led=0;

        p30=0;

        beep();

   }



int main(void)

{         

  TMOD=0x01; //Mode 1 16-bit counter

  TH0=-50000/256; //Set the initial value

  TL0=-50000%256;

  EA=1; //Open the general interrupt

  ET0=1; //Open timer 0 interrupt

  TR0=1; //Start timer 0

  P2=0;

  int_time=0; //Interrupt times initialization

  second=00; //second initialization

         while(1)

    {        

          if(k1==0)

        {         

                delay(10);

                if(k1==0) 

            {

                        f_an1();

                }

        }

        if(k2==0)

        {

                delay(10);

                if(k2==0)

                {

                        f_an2();

                }

        }

        if(k3==0)

        {

            delay(10);

           if(k3==0)

            {

                    f_an3();

            }

        }


        if(sg==0)

        {

                delay(10);

                if(sg==0)

                {

                   sgan1();

                }

        }

}

        return 0;

}  



void time0() interrupt 1 using 1

   {  

     int_time ++; //Every time an interruption occurs, the interruption count int_time is incremented by 1

    if(int_time==20) //Enough interrupts for 20 times, i.e., sampling of test results once every 1 second

……………………



Reference address:51 single chip washing machine proteus simulation and source code design

Previous article:51 single-chip heart-shaped water flow and digital tube synchronization effect display simulation and program
Next article:Program for making a microcontroller tracking car

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号