基于c51单片机,基本功能:按键调节模式,时间,电机转动,led显示,报警等功能
欢迎讨论
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
51单片机洗衣机程序.zip
(242.22 KB, 售价: 1 E币)
单片机源程序如下:
- #include<reg52.h>
- #include<intrins.h>
- #include<absacc.h>
- sbit m=P2^0;
- sbit time_set=P2^1;
- sbit mode=P2^2;
- sbit ma=P1^0;
- sbit mb=P1^1;
- sbit waterin=P1^3;
- sbit washing=P1^2;
- sbit waterout=P1^4;
- sbit finish=P1^5;
- sbit tuoshui=P1^6;
- sbit T_key=P1^7;
- sbit SPEAKER=P3^0;
- sbit LCD_E=P3^1;
- sbit Honggan=P3^4;
- sbit motor=P3^5;
- sbit LCD_RS=P3^6;
- sbit LCD_RW=P3^7;
- #define LCD_DB P0
- #define daport XBYTE[0x8000] // 0832地址 Y0
- #define uchar unsigned char
- #define uint unsinged int
- void LCD_init(void);
- void LCD_write_command(uchar command);
- void LCD_write_data(uchar dat);
- void LCD_disp_char(uchar x,uchar y,uchar dat);
- void delay_n40us(int n);
- int time[3]={0,0,0};
- int time1=0,t1,t2,t3;
- unsigned char pos[6]={0x01,0x02,0x08,0x10,0x40,0x80};
- unsigned char DSY_CODE[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};
- unsigned char code work_order[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
- int count=0,time_wash=1,time_total=100,model=0,mo_shi=0;moshi_set=0,flag=9500,inte_wrong=0;
- int z=0,begin=0,minute=0,second=0,hour=0,minute1=0,second1=0,hour1=0;
- int water[2]={0,0};
- sbit led=P0^0;
- void delay1(unsigned char i1)
- {
- unsigned char ii;
- unsigned int jj;
- for (ii=0;ii<i1;ii++)
- for (jj=0;jj<0x10;jj++);
- }
- void motor1()
- {
- char hight,low;
- bit updown;
- updown=1;
- hight=0xff;
- low=0x00;
- while( time_total==7||time_total==6||time_total==5)
- {
- daport=0xff; // 输出5V
- delay1(hight);
- daport=0x00; // -5V
- delay1(low);
- if (updown)
- { ma=1;
- mb=0; //改变占空比
- hight++;
- low--;
- if (hight==0xff) updown=0;
- }
- else
- { mb=0;
- ma=1;
- hight--;
- low++;
- if (hight==0x0) updown=1;
- }
- }
- }
- void delay()
- {
- unsigned char i;
- for(i=0;i<20;i++);
- }
- void Delayms(int t)
- {
- int x,y;
- for(x=t;x>0;x--)
- for(y=120;y>0;y--);
- }
- void sound()
- {
- int i=0;
- for(i=0;i<=10;i++)
- SPEAKER=1;
- for(i=0;i<=5;i++)
- SPEAKER=0;
- }
- void LCD_init(void)
- {
- LCD_write_command(0x38);
- LCD_write_command(0x0c);
- LCD_write_command(0x06);
- LCD_write_command(0x01);
- LCD_write_command(0x02);
- delay_n40us(100);
- }
- void LCD_write_command(uchar dat)
- {
- LCD_DB=dat;
- LCD_RS=0;
- LCD_RW=0;
- LCD_E=1;
- LCD_E=0;
- delay_n40us(1);
- }
- void LCD_write_data(uchar dat)
- {
- LCD_DB=dat;
- LCD_RS=1;
- LCD_RW=0;
- LCD_E=1;
- LCD_E=0;
- delay_n40us(1);
- }
- void LCD_disp_char(uchar x,uchar y,uchar dat)
- {
- uchar address;
- if(y==1)
- address=0x80+x;
- else
- address=0xc0+x;
- LCD_write_command(address);
- LCD_write_data(dat);
- }
- void delay_n40us(int n)
- {
- int i;
- uchar j;
- for(i=n;i>0;i--)
- for(j=0;j<2;j++);
- }
- int main()
- {
- int i,d2;
- IE=0x87;
- TCON=0x05;
- TMOD=0x11;
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- ET1=1;
- TR0=0;
- LCD_init();
- motor=0;
- while(1)
- {
- int j=0,time_wash_dis;
- //PA=work_order[w];
- //PA=work_order[w];
- while(begin==0)
- { waterout=1;
- finish=1;
- waterin=1;
- tuoshui=1;
- washing=1;
- T_key=1;
- //HEAT1=1;
- //HEAT2=0;
- if(Honggan==0)
- {Delayms(200);
- if(Honggan==0)
- {mo_shi=mo_shi+1;
- if(mo_shi==2)
- {mo_shi=0;}}}
-
- if(mode==0)
- {Delayms(200);
- if(mode==0)
- {model=model+1;
- if(model==4)
- {model=0;}
- }}
- if(time_set==0)
- {Delayms(200);
- if(time_set==0)
- {time_wash=time_wash+1;
- if(time_wash==10)
- {time_wash=1;}}}
-
- if(m==0)
- {Delayms(200);
- if(m==0&&time_wash>0)
- {time_wash=time_wash-1;
- }
- }
- time_wash_dis=DSY_CODE[time_wash];
- LCD_disp_char(14,1,time_wash_dis);
- LCD_disp_char(15,1,'0');
- if(mo_shi==0)
- {
- LCD_disp_char(0,2,'n');
- LCD_disp_char(1,2,'o');
- LCD_disp_char(2,2,'r');
- LCD_disp_char(3,2,' ');
- }
- if(mo_shi==1)
- {
- LCD_disp_char(0,2,'s');
- LCD_disp_char(1,2,'o');
- LCD_disp_char(2,2,'f');
- LCD_disp_char(3,2,'t');
- }
-
- time[1]=time_wash;
- //writetlc5615(137);
- }
- //初始启动设置
- while(inte_wrong)
- {
- sound();
- }
-
-
- if(time_total==9||time_total==8) //进水
- {
- waterin=0;
- }
- if(time_total==7||time_total==6||time_total==5) //洗涤
- { waterin=1;
- washing=0;
- motor1();
-
- }
-
-
- if(time_total==4||time_total==3) // 排水
- { washing=1;
- ma=0;
- mb=0;
- waterout=0;
- }
- if(time_total==2) //脱水
- { waterout=1;
- tuoshui=0;
- }
-
- if(time_total==0)
- { sound();
- finish=0;
- tuoshui=1;
- Delayms(200);
- Delayms(200);
- Delayms(200);
- while(1){
- LCD_disp_char(0,2,'f');
- LCD_disp_char(1,2,'i');
- LCD_disp_char(2,2,'n');
- LCD_disp_char(3,2,'i');
- LCD_disp_char(4,2,'s');
- LCD_disp_char(5,2,'h');
- LCD_disp_char(6,2,' ');
- LCD_disp_char(7,2,' ');
- LCD_disp_char(8,2,' ');
- LCD_disp_char(9,2,' ');
- LCD_disp_char(10,2,' ');
- LCD_disp_char(11,2,' ');
- LCD_disp_char(12,2,' ');
- LCD_disp_char(13,2,' ');
- LCD_disp_char(14,2,' ');
- LCD_disp_char(15,2,' ');
- LCD_disp_char(0,1,' ');
- LCD_disp_char(1,1,' ');
- LCD_disp_char(2,1,' ');
- LCD_disp_char(3,1,' ');
- LCD_disp_char(4,1,' ');
- LCD_disp_char(5,1,' ');
- LCD_disp_char(6,1,' ');
- LCD_disp_char(7,1,' ');
- LCD_disp_char(8,1,' ');
- LCD_disp_char(9,1,' ');
- LCD_disp_char(10,1,' ');
- LCD_disp_char(11,1,' ');
- LCD_disp_char(12,1,' ');
- LCD_disp_char(13,1,' ');
- LCD_disp_char(14,1,' ');
- LCD_disp_char(15,1,' ');
- T_key=1;
- TR1=0; }
- }
- // SPEAKER=0;
- /* for(i=0;i<3;i++)
- { t1=DSY_CODE[time[i]/10];
- LCD_disp_char(j,1,t1);
- t2=DSY_CODE[time[i]%10];
- LCD_disp_char(j+1,1,t2);
- j=j+3;
- } */
- }
- return 0;
- }
- void time_interrrupt0() interrupt 1 // 定时中断
- {
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- if(++count==2)
- { time1+=1;
- t1=DSY_CODE[time1/10];
- LCD_disp_char(0,1,t1);
- t2=DSY_CODE[time1%10];
- LCD_disp_char(1,1,t2);
- if(time1>=60&&second==0)
- {time[1]=time[1]-1;
- time[2]=9;
- }
- if(time1>=60&&second!=0)
- {time[2]=time[2]-1;
- }
- if(time1>=60)
- {time1=0;}
- hour=time[0];
- minute=time[1];
- second=time[2];
- time_total=10*minute+second;
- hour1=DSY_CODE[hour];
- minute1=DSY_CODE[minute];
- second1=DSY_CODE[second];
- LCD_disp_char(13,1,hour1);
- LCD_disp_char(14,1,minute1);
- LCD_disp_char(15,1,second1);
- count=0;
-
- }
- }
- void begain() interrupt 0 //启动中断
- {
- begin=~begin;
- TR0=1;
- T_key=0;
- }
- void wrong() interrupt 2 //故障中断
- {
- inte_wrong=~inte_wrong;
- TR0=~TR0;
- }
复制代码
【必读】版权免责声明
1、本主题所有言论和内容纯属会员个人意见,与本论坛立场无关。2、本站对所发内容真实性、客观性、可用性不做任何保证也不负任何责任,网友之间仅出于学习目的进行交流。3、对提供的数字内容不拥有任何权利,其版权归原著者拥有。请勿将该数字内容进行商业交易、转载等行为,该内容只为学习所提供,使用后发生的一切问题与本站无关。 4、本网站不保证本站提供的下载资源的准确性、安全性和完整性;同时本网站也不承担用户因使用这些下载资源对自己和他人造成任何形式的损失或伤害。 5、本网站所有软件和资料均为网友推荐收集整理而来,仅供学习用途使用,请务必下载后两小时内删除,禁止商用。6、如有侵犯你版权的,请及时联系我们(电子邮箱1370723259@qq.com)指出,本站将立即改正。
|
|