欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標(biāo)題: 電機(jī)調(diào)速+1602顯示程序 [打印本頁]

作者: YoungerM    時(shí)間: 2021-1-5 13:15
標(biāo)題: 電機(jī)調(diào)速+1602顯示程序
  1. #include <reg51.h>
  2. #include"lcd.h"

  3. #define uint unsigned int
  4. #define uchar unsigned char
  5. unsigned char table2[]={"Speed control   "};
  6. unsigned char table1[]={"Model:1      OFF"};
  7. sbit PWM_OUT = P1^0;
  8. sbit KEY1 = P3^1;  //    ON/OFF
  9. sbit KEY2 = P3^0; //     1檔
  10. sbit KEY3 = P3^2; //     2檔
  11. sbit KEY4 = P3^3; //     3檔

  12. uchar heigh = 1;  //檔位大小標(biāo)志  1:1檔  2:2檔  3:3檔
  13. bit ON_OFF = 0;   //0:OFF 1:ON
  14. uchar time_1ms = 0;

  15. void T0_init();
  16. void Delay5ms();        //@11.0592MHz
  17. void kaiguan()
  18. {
  19.     if(ON_OFF == 0)
  20.     {
  21.         LcdWriteCom(0x80+0x40+13);
  22.         LcdWriteData('O');
  23.         LcdWriteCom(0x80+0x40+14);
  24.         LcdWriteData('F');
  25.         LcdWriteCom(0x80+0x40+15);
  26.         LcdWriteData('F');
  27.     }
  28.     else
  29.     {
  30.         LcdWriteCom(0x80+0x40+13);
  31.         LcdWriteData(' ');
  32.         LcdWriteCom(0x80+0x40+14);
  33.         LcdWriteData('O');
  34.         LcdWriteCom(0x80+0x40+15);
  35.         LcdWriteData('N');
  36.     }
  37. }

  38. void main()
  39. {
  40.     unsigned char i,j;
  41.     LcdInit();
  42.     T0_init();
  43.     for(i=0;i<16;i++)
  44.     {
  45.         LcdWriteCom(0x80+i);
  46.         LcdWriteData(table2[i]);   
  47.     }
  48.     for(j=0;j<16;j++)
  49.     {
  50.         LcdWriteCom(0x80+0x40+j);
  51.         LcdWriteData(table1[j]);   
  52.     }
  53.    
  54.     while(1)
  55.     {
  56.         //開關(guān)按鍵檢測(cè)
  57.         if(KEY1 == 0)
  58.         {
  59.             Delay5ms();//軟件按鍵消抖處理
  60.             if(KEY1 == 0)
  61.             {
  62.                 ON_OFF = !ON_OFF;
  63.             }
  64.             while(KEY1 == 0);//按鍵松手檢測(cè)
  65.         }
  66.         
  67.         //1檔按鍵檢測(cè)
  68.         if(KEY2 == 0)
  69.         {
  70.             Delay5ms();//軟件按鍵消抖處理
  71.             if(KEY2 == 0)
  72.             {
  73.                 heigh = 1;
  74.             }
  75.             while(KEY2 == 0);//按鍵松手檢測(cè)
  76.         }

  77.         //2檔按鍵檢測(cè)
  78.         if(KEY3 == 0)
  79.         {
  80.             Delay5ms();//軟件按鍵消抖處理
  81.             if(KEY3 == 0)
  82.             {
  83.                 heigh = 2;
  84.             }
  85.             while(KEY3 == 0);//按鍵松手檢測(cè)
  86.         }
  87.    
  88.         //3檔按鍵檢測(cè)
  89.         if(KEY4 == 0)
  90.         {
  91.             Delay5ms();//軟件按鍵消抖處理
  92.             if(KEY4 == 0)
  93.             {
  94.                 heigh = 3;
  95.             }
  96.             while(KEY4 == 0);//按鍵松手檢測(cè)
  97.         }
  98.         LcdWriteCom(0x80+0x40+6);
  99.         LcdWriteData('0'+heigh);
  100.         kaiguan();
  101.     }
  102.    
  103.    
  104. }

  105. /*定時(shí)器0初始化函數(shù)*/
  106. void T0_init()
  107. {
  108.     TMOD = 0X01;            //定時(shí)器0工作模式1
  109.     TH0 = (65536-1000)/256;
  110.     TL0 = (65536-1000)%256; //定時(shí)中斷時(shí)間為1MS
  111.     EA = 1;                 //允許總中斷
  112.     ET0 = 1;                //允許定時(shí)器0中斷
  113.     TR0 =  1;              //開始計(jì)時(shí)
  114. }

  115. void Delay5ms()        //@11.0592MHz
  116. {
  117.     unsigned char i, j;

  118.     i = 18;
  119.     j = 244;
  120.     do
  121.     {
  122.         while (--j);
  123.     } while (--i);
  124. }

  125. void time0() interrupt 1
  126. {
  127.    
  128.     time_1ms++;
  129.     if(time_1ms >= 10) //脈沖周期為10MS
  130.         time_1ms = 0;
  131.    
  132.    
  133.     if(ON_OFF == 1)
  134.     {
  135.       if(heigh == 1)  //如果是1檔
  136.         {
  137.             if(time_1ms<=4)
  138.             {
  139.                 PWM_OUT =1;
  140.             }
  141.             else PWM_OUT = 0;
  142.         }
  143.         
  144.       if(heigh == 2)  //如果是2檔
  145.         {
  146.             if(time_1ms<=7)
  147.             {
  148.                 PWM_OUT = 1;
  149.             }
  150.             else PWM_OUT = 0;
  151.         }
  152.         
  153.       if(heigh == 3)  //如果是3檔
  154.         {
  155.             PWM_OUT = 1;
  156.         }
  157.     }
  158.    
  159.     else PWM_OUT =0;
  160.    
  161.     TH0 = (65536-1000)/256;
  162.     TL0 = (65536-1000)%256; //定時(shí)中斷時(shí)間為1MS
  163. }
復(fù)制代碼

電機(jī)調(diào)速+1602顯示.zip

33.07 KB, 下載次數(shù): 10, 下載積分: 黑幣 -5


作者: 51hei團(tuán)團(tuán)    時(shí)間: 2021-1-5 17:15
直流電機(jī)還是步進(jìn)電機(jī)能分享下電路圖嗎?
作者: YoungerM    時(shí)間: 2021-1-10 21:14
51hei團(tuán)團(tuán) 發(fā)表于 2021-1-5 17:15
直流電機(jī)還是步進(jìn)電機(jī)能分享下電路圖嗎?

步進(jìn)電機(jī),直流電機(jī)原理不同




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