找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2761|回复: 3
收起左侧

单片机自动洗衣机源程序与Proteus仿真图

[复制链接]
ID:238019 发表于 2021-5-27 18:14 | 显示全部楼层 |阅读模式
上周做的洗衣机,整个框架已经搭好,包括源码和仿真图,子程序可以使用,各位吧友,可以根据需要自己进行更改

仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
51hei.png 1.png 2.png 3.png

单片机源程序如下:
  1. #include<reg51.h>
  2. #include <string.h>
  3. #define uchar unsigned char
  4. #define uint unsigned int
  5. ///1602 液晶 p0 为液晶数据口
  6. sbit RS=P3^0;
  7. sbit RW=P3^1;
  8. sbit E=P3^4;
  9. uchar code line1[]="mode:01 time:00";
  10. uchar code line2[]="state:  menu   ";
  11. uchar code line3[]="state:  work   ";
  12. uchar code line4[]="state:  stop   ";
  13. uchar code line5[]="state:  pause  ";
  14. // motor
  15. sbit Motor_In0=P1^5;
  16. sbit Motor_In1=P1^4;
  17. //water
  18. sbit Water_In0=P3^6;
  19. sbit Water_In1=P3^7;
  20. ///key
  21. sbit Key_water_mode=P1^0;
  22. sbit Key_water_time=P1^1;
  23. sbit Key_water_start=P1^6;
  24. sbit Key_water_stop=P3^2;
  25. sbit Key_water_pause=P3^3;

  26. ///
  27. void delay(uint time)
  28. {
  29.   uint i,j;
  30.   for(i=0;i<time;i++)
  31.    for(j=0;j<250;j++);
  32. }

  33. void Lcd1602_Write(uchar Cmd,uchar Cmd_Data)
  34. {
  35.         E=0;
  36.         RS=Cmd;  //  0 指令 1 数据
  37.         RW=0;
  38.         P0=Cmd_Data;
  39.         delay(1);
  40.         E=1;
  41.         E=0;
  42. }

  43. void Lcd1602_Init()
  44. {
  45.         E=0;
  46.         RW=1;
  47.         RS=1;
  48.         P0=0xff;
  49.         delay(15);
  50.         Lcd1602_Write(0,0x38);
  51.         delay(5);
  52.         Lcd1602_Write(0,0x38);
  53.         Lcd1602_Write(0,0x08);
  54.         Lcd1602_Write(0,0x0e);
  55.         Lcd1602_Write(0,0x06);
  56.         Lcd1602_Write(0,0x01);
  57. }

  58. void Lcd1602__byte(uchar y,uchar x,uchar z)    //Y=0,1(起始行)X=0~15(起始列) Z asii 码
  59. {         
  60.    if(y)  x+=0x40;   
  61.    x+=0x80;           //
  62.    Lcd1602_Write(0,x);  
  63.    Lcd1602_Write(1,z);   //
  64. }
  65. void Lcd1602__text(uchar y,uchar x,uchar table[])    //Y,X??????,table[]?????
  66. {      
  67.   uchar z=0;
  68.   uchar t;
  69.   t=strlen(table)+x; //  
  70.   while(x<t)        //
  71.   {                 //
  72.     Lcd1602__byte(y,x,table[z]);    //
  73.     x++;
  74.     z++;
  75.   }
  76. }
  77. void Timer0_Init(void)
  78. {

  79.      TMOD = 0x01;                            //T0 工作方式 1;16位 计数器;

  80.      TH0=(65536-50000)/256;          // 初值高 8 位 走 1000 次,每次 1us :晶振 12MHz;  
  81.      TL0=(65536-50000)%256;         // 初值低 8 位 走 1000 次,每次 1us :晶振 12MHz;  
  82.   
  83.      TR0  = 0;                                  // 开启 T0 定时器;
  84.      ET0  = 1;                                  // 允许 T0 定时器中断;
  85.      EA   = 1;                                 // 开启 总中断 允许;
  86. }
  87. ///
  88. void INT0_Init(void) //外部中断0初始化
  89. {
  90.   EA=1;          //全局中断开
  91.   EX0=1;         //外部中断0开
  92.   IT0=1;         //边沿触发
  93. }
  94. //
  95. void Timer0(void) interrupt 1 using 1
  96. {
  97.    
  98.          static uchar count=0;
  99.    
  100.          uchar time_s,time_g;
  101.          ET0=0;TR0=0;
  102.          TH0 = (65536-50000)/256;    // 中断后,赋初值;
  103.      TL0 = (65536-50000)%256;
  104.      count++;       // 每次中断,计数 累加 1;
  105.      if(count >=20)
  106.      {  
  107.           count = 0; // 计数值 清0 ;
  108.      }
  109.           ET0=1;TR0=1;
  110. }
  111. //
  112. void INT0_EX0(void) interrupt 0 using 1
  113. {

  114. }
  115. /////////////////////
  116. void main(void)
  117. {
  118.         uint i=0;
  119.         INT0_init();
  120.         Timer0_Init();
  121.         Lcd1602_Init();
  122.         Lcd1602__text(0,0,line1);
  123.         Lcd1602__text(1,0,line2);
  124.         Motor_In0=0;
  125.         Motor_In1=1;
  126.         while(1)
  127.                 {
  128.                         
  129.                 }
  130. }
复制代码
51hei.png
按键部分还未完成,希望大家补全:
3-water.rar (47.2 KB, 下载次数: 82)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

ID:769946 发表于 2021-5-29 20:57 | 显示全部楼层
按键咋没效果
回复

使用道具 举报

ID:28992 发表于 2021-5-30 03:22 | 显示全部楼层
great job, thank you!
回复

使用道具 举报

ID:929543 发表于 2021-5-30 18:35 | 显示全部楼层
按钮不起作用
回复

使用道具 举报

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

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

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