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
It also has various indicator lights:
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 ……………………
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
- Popular Resources
- Popular amplifiers
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
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- TMS320F28335 SVPWM source program
- 【RPi PICO】CircuitPython Firmware
- Microwave Circuit Appreciation
- Microcontroller learning notes, teach you how to learn in three steps!
- msp430f5529 uart pwm adc
- WiFi NeoPixel Cube
- [Help] In the design of lithium battery power modules, why is every 1V of lithium battery voltage very valuable?
- [DIY Bing Dun Dun] + Limited Edition Homemade Dun Dun is here
- EEWORLD University Hall----Live Replay: Unlocking New Possibilities of TI Sitara AM2x MCU in Motor Drive
- 02.USART routines and tests