《基于的51单片机全自动洗衣机设计》由会员分享,可在线阅读,更多相关《基于的51单片机全自动洗衣机设计(24页珍藏版)》请在金锄头文库上搜索。
1、 全自动洗衣机课程设计基于 51 单片机, C 语言实现。基本要求模拟全自动洗衣机工作过程。以电机替代洗衣机电机。显示洗衣机工作的状态(进水、浸泡、洗衣、脱水、结束) 。显示工作剩余时间(洗衣程序可自定义,时间精度:秒) 。洗衣时交替正、反转。扩展要求洗衣和脱水时电机转速不同。增加水位传感器输入。故障报警。增加声音提示。其它自定义功能。设计用 Preteus 仿真:仿真图如下:C 文件函数代码:#include/*/#define uchar unsigned char#define uint unsigned int/*/*/sbit mo_r = P32; /电机右控制线sbit mo_l
2、 = P33; /电机左控制线/*/sbit key_menu = P34; / 菜单按键sbit key_on = P35; / 开始按键sbit key_off = P36; / 结束按键sbit key_se = P37; / 菜单选择按键/*/sbit led_in = P00; / 进水指示灯sbit led_xi = P01; / 洗衣指示灯sbit led_pao = P02; / 泡洗指示灯sbit led_xx = P03; / 脱水指示灯sbit led_out = P04; / 出水指示灯sbit led_over = P05; / 洗衣结束指示灯sbit led_wor
3、k = P06; / 电机工作指示灯sbit led_wring = P07; / 报警指示灯sbit other = P31; / 脱水电源控制开关sbit anther = P30; / 洗衣电源控制开关/*/uchar code num10=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90;/*/char sec = 0; / 时间秒char min = 0; / 时间分uchar count=0; / 中断计数uchar flag0=0; / 洗衣机工作状态标志uchar flag1=0; / 进水次数标志uchar flag2=0;
4、/ 出水次数标志uchar flag3=0; / 泡洗次数标志uchar err =0; / 报警标志uchar quan = 0;/正反转计数 /*/ 函数声明/*/void delay();/ 延时函数void in(); / 进水子程序void out(); / 出水子程序void over(); / 结束子程序void xi(); / 洗衣子程序void pao();/ 泡衣子程序void xx(); / 脱水子程序void on(); / 工作 on 处理子程序void se(); / 显示菜单选择void SEG_display(); /显示时间子程序void key_scan()
5、; / 按键扫描子程序/*/ 延时函数/*/void delay(uint i)uint x,y;for(x=i;x0;x-) for(y=120;y0;y-);/*/ 工作 on 处理子程序/*/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();/*/ 结束子程序/*/void ov
6、er() other=0;anther=0;P0 = 0xff;mo_r=0;mo_l=0;led_over = 0;EA=0;/*/ 进水子程序/*/void in() anther=0;other=0;P0 = 0xff;led_in = 0;flag1+;mo_r = 0;mo_l = 0;min = 0;sec = 8;/*/ 洗衣子程序/*/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;/*/ 泡衣子程序/*/void
7、pao()anther=1;other=0;P0 = 0xff;led_pao = 0;led_work = 0;flag3+;mo_r = 1;mo_l = 0;min = 1;sec = 35;quan = 0;/*/ 脱水子程序/*/void xx() other=1;anther=0;P0 = 0xff;led_xx = 0;mo_r = 0;mo_l = 1;min = 0;sec = 50;/*/ 出水子程序/*/void out() anther=0;other=0;P0 = 0xff;led_out = 0;flag2+;mo_r = 0;mo_l = 0;min = 0;se
8、c = 5;/*/ 显示菜单选择/*/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;/*/ 菜单处理子程序/*/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
9、_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();/*/ 按键扫描子程序/*/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_
10、on);on();/*/if(key_off = 0)delay(5);if(key_off = 0)while(!key_off);over();/*/ 显示子程序/*/void SEG_display()P1=0x01;P2 = nummin/10;delay(10);P1 = 0x02;P2 = nummin%10;delay(10);P1 = 0x04;P2 = numsec/10;delay(10);P1 = 0x08;P2 = numsec%10;delay(10);/*/ 主函数/*/void main()led_in=0;anther=0;other=0;while(1)SEG_display();key_scan();/*/ 定时器 0 中断处理程序/*/void timer0() interrupt 1TH0=(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