《基于的51单片机全自动洗衣机设计北理工.doc》由会员分享,可在线阅读,更多相关《基于的51单片机全自动洗衣机设计北理工.doc(22页珍藏版)》请在课桌文档上搜索。
1、 全自动洗衣机课程设计基于51单片机,C语言实现。基本要求模拟全自动洗衣机工作过程。以电机替代洗衣机电机。显示洗衣机工作的状态进水、浸泡、洗衣、脱水、结束。显示工作剩余时间洗衣程序可自定义,时间精度:秒。洗衣时交替正、反转。扩展要求洗衣和脱水时电机转速不同。增加水位传感器输入。故障报警。增加声音提示。其它自定义功能。设计用Preteus仿真:仿真图如下:C文件函数代码:#include/*/#define uchar unsigned char#define uint unsigned int/*/*/sbit mo_r = P32; /电机右控制线sbit mo_l = P33;/电机左控制
2、线/*/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_work = P06; / 电机工作指示灯
3、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; / 出水次数标志uchar flag3
4、=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; / 按键扫描子程序/*/ 延时函数/*/void delayuint x,y;for0;x
5、- for0;y-;/*/ 工作on处理子程序/*/void onTMOD=0x01;TH0=/256;TL0=%256;EA=1;ET0=1;TR0=1;P0 = 0xff;if in;if xi;if pao;if xx;if out;/*/ 结束子程序/*/void overother=0;anther=0;P0 = 0xff;mo_r=0;mo_l=0;led_over = 0;EA=0;/*/ 进水子程序/*/void inanther=0;other=0;P0 = 0xff;led_in = 0;flag1+;mo_r = 0;mo_l = 0;min = 0;sec = 8;/*
6、/洗衣子程序/*/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 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 xxother=1;anther=0;P0 = 0xff;led_xx = 0
7、;mo_r = 0;mo_l = 1;min = 0;sec = 50;/*/ 出水子程序/*/void outanther=0;other=0;P0 = 0xff;led_out = 0;flag2+;mo_r = 0;mo_l = 0;min = 0;sec = 5;/*/ 显示菜单选择/*/void seP0 = 0xff;if= 5flag0 = 0; ifled_in = 0;ifled_xi=0;ifled_pao=0;ifled_xx=0;ifled_out=0;/*/ 菜单处理子程序/*/void menu min = 0;sec = 0;mo_r=0;mo_l=0;SEG_d
8、isplay; while ifdelay;ifwhile;on;break;/*/ifdelay;ifwhile;over;break;/*/ifdelay;ifwhile;flag0+;se;/*/ 按键扫描子程序/*/void key_scan ifdelay;ifwhile;menu;/*/ifdelay;ifwhile;on;/*/ifdelay;ifwhile;over;/*/显示子程序/*/void SEG_displayP1=0x01;P2 = nummin/10;delay;P1 = 0x02;P2 = nummin%10;delay;P1 = 0x04;P2 = numse
9、c/10;delay;P1 = 0x08;P2 = numsec%10;delay;/*/ 主函数/*/void mainled_in=0;anther=0;other=0;whileSEG_display;key_scan;/*/ 定时器0中断处理程序/*/void timer0 interrupt 1TH0=/256;TL0=%256;count+; if count = 0;sec-;if| quan+;switch 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;cas
10、e 25:mo_r=0;mo_l=0;break;default:; if quan=0; /*/if& min-; sec = 59; /*/ifsec& /进水结束 switch case 1:flag0=1;xi;break;case 2:flag0=2;pao;break;case 3:flag0=2;pao;break;case 4:flag0=2;pao;break;default: err=1;led_wring = 0; /*/ifsec& /洗衣结束 flag0 = 4; out; /*/ifsec& /泡衣结束 switch case 1:flag0=4;out;break;case 2:flag0=4;out;break;case 3:flag0=4;out;break;default: err=1;led_wring = 0; /*/ifsec& /出水结束switch case 1:flag0=0;in;break;case 2:flag0=0;in;break;case 3:flag0=0;in;break;case 4:flag0=3;xx;break;default: err= 1;led_wring = 0; /*/ifsec& sec = 0; over;