標(biāo)題: 單片機(jī)自動(dòng)洗衣機(jī)源程序與Proteus仿真圖 [打印本頁(yè)]

作者: xitaiguang    時(shí)間: 2021-5-27 18:14
標(biāo)題: 單片機(jī)自動(dòng)洗衣機(jī)源程序與Proteus仿真圖
上周做的洗衣機(jī),整個(gè)框架已經(jīng)搭好,包括源碼和仿真圖,子程序可以使用,各位吧友,可以根據(jù)需要自己進(jìn)行更改

仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)


單片機(jī)源程序如下:
  1. #include<reg51.h>
  2. #include <string.h>
  3. #define uchar unsigned char
  4. #define uint unsigned int
  5. ///1602 液晶 p0 為液晶數(shù)據(jù)口
  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 數(shù)據(jù)
  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位 計(jì)數(shù)器;

  80.      TH0=(65536-50000)/256;          // 初值高 8 位 走 1000 次,每次 1us :晶振 12MHz;  
  81.      TL0=(65536-50000)%256;         // 初值低 8 位 走 1000 次,每次 1us :晶振 12MHz;  
  82.   
  83.      TR0  = 0;                                  // 開啟 T0 定時(shí)器;
  84.      ET0  = 1;                                  // 允許 T0 定時(shí)器中斷;
  85.      EA   = 1;                                 // 開啟 總中斷 允許;
  86. }
  87. ///
  88. void INT0_Init(void) //外部中斷0初始化
  89. {
  90.   EA=1;          //全局中斷開
  91.   EX0=1;         //外部中斷0開
  92.   IT0=1;         //邊沿觸發(fā)
  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++;       // 每次中斷,計(jì)數(shù) 累加 1;
  105.      if(count >=20)
  106.      {  
  107.           count = 0; // 計(jì)數(shù)值 清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. }
復(fù)制代碼

按鍵部分還未完成,希望大家補(bǔ)全:
3-water.rar (47.2 KB, 下載次數(shù): 83)


作者: ABBAS5195    時(shí)間: 2021-5-29 20:57
按鍵咋沒(méi)效果

作者: usaboy    時(shí)間: 2021-5-30 03:22
great job, thank you!
作者: sdgsfghfg    時(shí)間: 2021-5-30 18:35
按鈕不起作用





歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1