找回密码
 注册

QQ登录

只需一步,快速开始

搜索

51单片机半自动洗衣机系统Proteus仿真程序

[复制链接]
coolice 发表于 2020-1-23 00:29:56 | 显示全部楼层 |阅读模式
基于c51单片机,基本功能:按键调节模式,时间,电机转动,led显示,报警等功能
欢迎讨论
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
51单片机洗衣机程序.zip (242.22 KB, 售价: 1 E币)
1.jpg
单片机源程序如下:
  1. #include<reg52.h>
  2. #include<intrins.h>
  3. #include<absacc.h>


  4. sbit m=P2^0;
  5. sbit time_set=P2^1;
  6. sbit mode=P2^2;

  7. sbit ma=P1^0;
  8. sbit mb=P1^1;

  9. sbit waterin=P1^3;
  10. sbit washing=P1^2;
  11. sbit waterout=P1^4;
  12. sbit finish=P1^5;

  13. sbit tuoshui=P1^6;
  14. sbit T_key=P1^7;

  15. sbit SPEAKER=P3^0;
  16. sbit LCD_E=P3^1;
  17. sbit Honggan=P3^4;
  18. sbit motor=P3^5;
  19. sbit LCD_RS=P3^6;
  20. sbit LCD_RW=P3^7;

  21. #define LCD_DB P0

  22. #define daport XBYTE[0x8000]   // 0832地址  Y0
  23. #define uchar unsigned char
  24. #define uint unsinged  int
  25. void LCD_init(void);
  26. void LCD_write_command(uchar command);
  27. void LCD_write_data(uchar dat);
  28. void LCD_disp_char(uchar x,uchar y,uchar dat);
  29. void delay_n40us(int n);

  30. int time[3]={0,0,0};
  31. int time1=0,t1,t2,t3;
  32. unsigned char pos[6]={0x01,0x02,0x08,0x10,0x40,0x80};
  33. unsigned char DSY_CODE[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};
  34. unsigned char code work_order[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
  35. int count=0,time_wash=1,time_total=100,model=0,mo_shi=0;moshi_set=0,flag=9500,inte_wrong=0;
  36. int z=0,begin=0,minute=0,second=0,hour=0,minute1=0,second1=0,hour1=0;
  37. int water[2]={0,0};
  38. sbit led=P0^0;

  39. void delay1(unsigned char i1)
  40. {
  41.    unsigned char ii;
  42.    unsigned int jj;
  43.    for (ii=0;ii<i1;ii++)
  44.       for (jj=0;jj<0x10;jj++);
  45. }

  46. void motor1()
  47. {
  48.     char hight,low;
  49.     bit updown;
  50.     updown=1;
  51.     hight=0xff;
  52.     low=0x00;
  53.     while( time_total==7||time_total==6||time_total==5)
  54.     {
  55.        daport=0xff;                          // 输出5V
  56.        delay1(hight);
  57.        daport=0x00;                          // -5V
  58.        delay1(low);
  59.        if (updown)
  60.        {  ma=1;
  61.               mb=0;                                          //改变占空比
  62.           hight++;
  63.           low--;
  64.           if (hight==0xff) updown=0;
  65.        }
  66.        else
  67.        {  mb=0;
  68.               ma=1;
  69.           hight--;
  70.           low++;
  71.           if (hight==0x0) updown=1;
  72.        }
  73.     }
  74. }



  75. void delay()
  76. {
  77. unsigned char i;
  78. for(i=0;i<20;i++);
  79. }
  80. void Delayms(int t)
  81. {
  82. int x,y;
  83. for(x=t;x>0;x--)
  84.    for(y=120;y>0;y--);
  85. }

  86. void sound()
  87. {
  88. int i=0;
  89.                       for(i=0;i<=10;i++)
  90.            SPEAKER=1;
  91.                    for(i=0;i<=5;i++)
  92.                    SPEAKER=0;
  93. }

  94. void LCD_init(void)
  95. {
  96.   LCD_write_command(0x38);
  97.   LCD_write_command(0x0c);
  98.   LCD_write_command(0x06);
  99.   LCD_write_command(0x01);
  100.   LCD_write_command(0x02);
  101.   delay_n40us(100);
  102. }



  103. void LCD_write_command(uchar dat)
  104. {
  105. LCD_DB=dat;
  106. LCD_RS=0;
  107. LCD_RW=0;
  108. LCD_E=1;
  109. LCD_E=0;
  110. delay_n40us(1);
  111. }

  112. void LCD_write_data(uchar dat)
  113. {
  114.   LCD_DB=dat;
  115.   LCD_RS=1;
  116.   LCD_RW=0;
  117.   LCD_E=1;
  118.   LCD_E=0;
  119.   delay_n40us(1);
  120. }

  121. void LCD_disp_char(uchar x,uchar y,uchar dat)
  122. {
  123.   uchar address;
  124.   if(y==1)
  125.     address=0x80+x;
  126.   else
  127.     address=0xc0+x;
  128.   LCD_write_command(address);
  129.   LCD_write_data(dat);
  130. }

  131. void delay_n40us(int n)
  132. {
  133. int i;
  134.   uchar j;
  135.     for(i=n;i>0;i--)
  136.           for(j=0;j<2;j++);
  137. }

  138. int main()
  139. {
  140.         int i,d2;
  141.          IE=0x87;
  142.         TCON=0x05;
  143.         TMOD=0x11;         
  144.         TH0=(65536-50000)/256;
  145.         TL0=(65536-50000)%256;
  146.      ET1=1;
  147.         TR0=0;
  148.         LCD_init();
  149.         motor=0;
  150.         while(1)
  151.         {   
  152.         int j=0,time_wash_dis;
  153.                 //PA=work_order[w];
  154.                 //PA=work_order[w];

  155.                 while(begin==0)
  156.                 {         waterout=1;
  157.              finish=1;
  158.                      waterin=1;
  159.              tuoshui=1;
  160.                          washing=1;
  161.                          T_key=1;
  162.                                 //HEAT1=1;
  163.                 //HEAT2=0;
  164.                   if(Honggan==0)
  165.                   {Delayms(200);
  166.                   if(Honggan==0)
  167.                   {mo_shi=mo_shi+1;
  168.                    if(mo_shi==2)
  169.                    {mo_shi=0;}}}
  170.         
  171.                  if(mode==0)
  172.                   {Delayms(200);
  173.                   if(mode==0)
  174.                   {model=model+1;
  175.                   if(model==4)
  176.                   {model=0;}
  177.                   }}

  178.                   if(time_set==0)
  179.                   {Delayms(200);
  180.                   if(time_set==0)
  181.                   {time_wash=time_wash+1;
  182.                    if(time_wash==10)
  183.                    {time_wash=1;}}}
  184.                      
  185.                   if(m==0)
  186.                   {Delayms(200);
  187.                   if(m==0&&time_wash>0)
  188.                   {time_wash=time_wash-1;
  189.                    }
  190.                   }


  191.                   time_wash_dis=DSY_CODE[time_wash];
  192.                  LCD_disp_char(14,1,time_wash_dis);
  193.                  LCD_disp_char(15,1,'0');

  194.                  if(mo_shi==0)
  195.                   {
  196.                   LCD_disp_char(0,2,'n');
  197.                   LCD_disp_char(1,2,'o');
  198.                   LCD_disp_char(2,2,'r');
  199.                   LCD_disp_char(3,2,' ');
  200.                   }
  201.                                     if(mo_shi==1)
  202.                   {
  203.                   LCD_disp_char(0,2,'s');
  204.                   LCD_disp_char(1,2,'o');
  205.                   LCD_disp_char(2,2,'f');
  206.                   LCD_disp_char(3,2,'t');
  207.                   }
  208.         
  209.                  time[1]=time_wash;

  210.                  //writetlc5615(137);
  211.                 }        
  212.                                                                                                                        //初始启动设置         
  213.                 while(inte_wrong)
  214.                 {
  215.                 sound();
  216.                 }
  217.                
  218.         
  219.                         if(time_total==9||time_total==8)                 //进水
  220.                 {         
  221.                   waterin=0;
  222.                  }
  223.                         if(time_total==7||time_total==6||time_total==5)                //洗涤
  224.                 {                   waterin=1;
  225.                                  washing=0;        
  226.                          motor1();
  227.                  
  228.                 }
  229.         
  230.                      
  231.                             if(time_total==4||time_total==3)           //        排水
  232.                 {                   washing=1;
  233.                            ma=0;
  234.                                    mb=0;
  235.                                    waterout=0;
  236.                 }
  237.                                 if(time_total==2)             //脱水
  238.                 {                  waterout=1;
  239.                                     tuoshui=0;
  240.                 }
  241.                         
  242.                 if(time_total==0)
  243.                 { sound();
  244.                   finish=0;
  245.                   tuoshui=1;
  246.                  Delayms(200);
  247.                  Delayms(200);
  248.                  Delayms(200);
  249.                 while(1){
  250.            LCD_disp_char(0,2,'f');
  251.            LCD_disp_char(1,2,'i');
  252.            LCD_disp_char(2,2,'n');
  253.            LCD_disp_char(3,2,'i');
  254.            LCD_disp_char(4,2,'s');
  255.            LCD_disp_char(5,2,'h');
  256.            LCD_disp_char(6,2,' ');
  257.            LCD_disp_char(7,2,' ');
  258.            LCD_disp_char(8,2,' ');
  259.            LCD_disp_char(9,2,' ');
  260.            LCD_disp_char(10,2,' ');
  261.            LCD_disp_char(11,2,' ');
  262.            LCD_disp_char(12,2,' ');
  263.            LCD_disp_char(13,2,' ');
  264.            LCD_disp_char(14,2,' ');
  265.            LCD_disp_char(15,2,' ');
  266.            LCD_disp_char(0,1,' ');
  267.            LCD_disp_char(1,1,' ');
  268.            LCD_disp_char(2,1,' ');
  269.            LCD_disp_char(3,1,' ');
  270.            LCD_disp_char(4,1,' ');
  271.            LCD_disp_char(5,1,' ');
  272.            LCD_disp_char(6,1,' ');
  273.            LCD_disp_char(7,1,' ');
  274.            LCD_disp_char(8,1,' ');
  275.            LCD_disp_char(9,1,' ');
  276.            LCD_disp_char(10,1,' ');
  277.            LCD_disp_char(11,1,' ');
  278.            LCD_disp_char(12,1,' ');
  279.            LCD_disp_char(13,1,' ');
  280.            LCD_disp_char(14,1,' ');
  281.            LCD_disp_char(15,1,' ');
  282.            T_key=1;
  283.            TR1=0; }
  284.                 }

  285.           // SPEAKER=0;

  286.         /*        for(i=0;i<3;i++)
  287.                 {        t1=DSY_CODE[time[i]/10];
  288.                     LCD_disp_char(j,1,t1);
  289.                         t2=DSY_CODE[time[i]%10];
  290.                         LCD_disp_char(j+1,1,t2);
  291.                         j=j+3;
  292.                 }         */

  293.         }
  294.         return 0;
  295. }
  296. void time_interrrupt0() interrupt 1                                           // 定时中断
  297. {

  298.         TH0=(65536-50000)/256;
  299.         TL0=(65536-50000)%256;
  300.         if(++count==2)
  301.         {         time1+=1;
  302.              t1=DSY_CODE[time1/10];
  303.                  LCD_disp_char(0,1,t1);
  304.                  t2=DSY_CODE[time1%10];
  305.                  LCD_disp_char(1,1,t2);
  306.              if(time1>=60&&second==0)
  307.                  {time[1]=time[1]-1;
  308.                   time[2]=9;
  309.                  }
  310.                  if(time1>=60&&second!=0)
  311.                   {time[2]=time[2]-1;
  312.                   }

  313.                  if(time1>=60)
  314.                  {time1=0;}
  315.                 hour=time[0];
  316.                 minute=time[1];
  317.                 second=time[2];
  318.                 time_total=10*minute+second;

  319.             hour1=DSY_CODE[hour];
  320.                 minute1=DSY_CODE[minute];
  321.                 second1=DSY_CODE[second];

  322.                 LCD_disp_char(13,1,hour1);
  323.                 LCD_disp_char(14,1,minute1);
  324.                 LCD_disp_char(15,1,second1);
  325.                 count=0;
  326.                
  327.                 }
  328. }
  329. void begain() interrupt 0                 //启动中断
  330. {
  331. begin=~begin;
  332. TR0=1;
  333. T_key=0;
  334. }
  335. void wrong() interrupt 2                  //故障中断
  336. {
  337.    inte_wrong=~inte_wrong;
  338.    TR0=~TR0;
  339. }
复制代码


您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|ELEOK |网站地图

GMT+8, 2024-4-25 17:33

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表