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

 找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 3303|回復(fù): 1
打印 上一主題 下一主題
收起左側(cè)

按鍵控制步進(jìn)電機(jī)并在數(shù)碼管顯示

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:79544 發(fā)表于 2015-10-28 19:40 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
步進(jìn)電機(jī)任意角度控制并顯示
  1. /*****************************************************
  2.                                     程序說(shuō)明
  3.     通過(guò)改變脈沖個(gè)數(shù)改變步進(jìn)電機(jī)的角度,通過(guò)按鍵可以讓步進(jìn)
  4. 電機(jī)停在任意角度及正反轉(zhuǎn) 并在數(shù)碼管顯示,正轉(zhuǎn)顯示1,反轉(zhuǎn)顯示2

  5.         單片機(jī)        :STC12C5A60S2
  6.         晶振            :11.0592MHZ
  7.         步進(jìn)電機(jī)驅(qū)動(dòng)芯片:ULN2003A
  8.         作者            :蘇義江
  9.         時(shí)間            :2015年6月5日
  10.         八拍方式驅(qū)動(dòng)    :順序?yàn)锳 AB B BC C CD D DA
  11. zhengzhuan[]={0x01,0x03,0x02,0x06,0x04,0x0c,0x08,0x09};
  12. fanzhuan[]  ={0x09,0x08,0x0c,0x04,0x06,0x02,0x03,0x01};

  13. *****************************************************/
  14. #include<12c5a.H>
  15. //#include <reg52.h>
  16. //#define uchar unsigned char
  17. //#define uint unsigned int

  18. sbit key=P1^0; //按鍵控制步進(jìn)電機(jī)的正轉(zhuǎn)方向  
  19. sbit key1=P1^1; //按鍵控制步進(jìn)電機(jī)的反轉(zhuǎn)方向
  20. sbit dula  =P0^7;    //段鎖存使能
  21. sbit wela  =P0^6;    //位鎖存使能


  22. uchar code zhengzhuan[]={0x01,0x03,0x02,0x06,0x04,0x0c,0x08,0x09};
  23. uchar code fanzhuan[]={0x09,0x08,0x0c,0x04,0x06,0x02,0x03,0x01};
  24. //共陽(yáng)段碼
  25. uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,
  26.                                 0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,
  27.                                 0xa1,0x86,0x8e,0x89};

  28. uchar code tab_f[]={0x0c,0x06,0x03,0x09,
  29.                                                 0x0c,0x06,0x03,0x09};//2相勵(lì)磁 反傳
  30. uchar code tab_z[]={0x09,0x03,0x06,0x0c,
  31.                                                 0x09,0x03,0x06,0x0c};//2相勵(lì)磁 正傳

  32. void Delay( uint i)//延時(shí)
  33. {
  34.         uint x,y;
  35.         for(x=i;x>0;x--)
  36.         for(y=300;y>0;y--);

  37. }
  38. void display()
  39. {
  40.         wela=1;
  41.         P2=0xfe;
  42.         wela=0;       
  43.         dula  =1;
  44.         P2=0xf9;//正轉(zhuǎn)顯示1
  45.         Delay( 10);

  46.         P2=0xff;
  47.         dula  =0;
  48. }
  49. void display1()
  50. {
  51.         wela=1;
  52.         P2=0xf7;
  53.         wela=0;
  54.         dula  =1;
  55.         P2=0xa4;//反轉(zhuǎn)顯示2
  56.         Delay( 10);

  57.         P2=0xff;
  58.         dula  =0;
  59. }
  60. void main()  
  61. {
  62.    uint i,j;//j代表脈沖.i代表數(shù)據(jù)
  63.         P0M1=0;        //設(shè)置P0口為強(qiáng)推免輸出模式,下同
  64.         P0M0=0XFF;
  65.         while(1)
  66.         {
  67.        
  68.                 //j等于13個(gè)脈沖,電機(jī)旋轉(zhuǎn)一周。改變j的值就會(huì)改變電機(jī)的角度
  69.                 for(j=3;j>0;j--)//正轉(zhuǎn)4分之一周
  70.                 {
  71.                         for(i=0;i<8;i++)
  72.                           {
  73.                                 display();                               
  74.                                  P0=zhengzhuan[i];//正轉(zhuǎn)數(shù)組
  75.                                    Delay(5);//5秒旋轉(zhuǎn)一周 改變延時(shí)改變速度                                       
  76.                         }       
  77.                 }
  78.                 Delay(200);//正反轉(zhuǎn)之間延時(shí)
  79.                 for(j=3;j>0;j--)//反轉(zhuǎn)4分之一周
  80.                 {
  81.                         for(i=0;i<8;i++)
  82.                           {
  83.                                 display1();                               
  84.                                  P0=fanzhuan[i];//反轉(zhuǎn)數(shù)組
  85.                                    Delay(5);//5秒旋轉(zhuǎn)一周 改變延時(shí)改變速度                                               
  86.                         }       
  87.                 }
  88.                 Delay(200);               
  89.         }
  90. /********下面程序都正常控制步進(jìn)電機(jī)狀態(tài)*****************/       
  91. /*        while(1)
  92.         {
  93.                 if(!key)
  94.                 Delay(10);
  95.                 {
  96.                         if(!key)
  97.                         {
  98.                                 display();
  99.                                 Delay(10);
  100.                                 for(j=7;j>0;j--)//j=7個(gè)脈沖,正轉(zhuǎn)半周
  101.                                 {
  102.                                         for(i=0;i<8;i++)
  103.                                           {
  104.                                          P0=zhengzhuan[i];//正轉(zhuǎn)數(shù)組
  105.                                                    Delay(10);       
  106.                                         }       
  107.                                 }
  108.                         }
  109.                         while(!key);       
  110.                 }

  111.                 if(!key1)
  112.                 Delay(10);
  113.                 {
  114.                         if(!key1)

  115.                         {
  116.                                 display1();
  117.                                 Delay(10);
  118.                                 for(j=7;j>0;j--)//j=7個(gè)脈沖,反轉(zhuǎn)半周
  119.                                 {
  120.                                         for(i=0;i<8;i++)
  121.                                           {
  122.                                          P0=fanzhuan[i];//反轉(zhuǎn)數(shù)組
  123.                                                    Delay(10);       
  124.                                         }       
  125.                                 }                               
  126.                         }
  127.                         while(!key1);       
  128.                 }
  129.                
  130.         }*/
  131. /*        while(1)
  132.         {
  133.        
  134.                 //j等于13個(gè)脈沖,電機(jī)旋轉(zhuǎn)一周。改變j的值就會(huì)改變電機(jī)的角度
  135.                 for(j=13;j>0;j--)//正轉(zhuǎn)一周
  136.                 {
  137.                         for(i=0;i<8;i++)
  138.                           {
  139.                                 display();                               
  140.                                  P0=zhengzhuan[i];//正轉(zhuǎn)數(shù)組
  141.                                    Delay(5);//6秒旋轉(zhuǎn)一周                                       
  142.                         }       
  143.                 }
  144.                 Delay(2000);
  145.                 for(j=13;j>0;j--)//反轉(zhuǎn)一周
  146.                 {
  147.                         for(i=0;i<8;i++)
  148.                           {
  149.                                 display1();                               
  150.                                  P0=fanzhuan[i];//反轉(zhuǎn)數(shù)組
  151.                                    Delay(5);//6秒旋轉(zhuǎn)一周                                       
  152.                         }       
  153.                 }
  154.                 Delay(2000);               
  155.         }
  156.         */
  157.        
  158. /*        while(1)
  159.         {
  160.        
  161.                 //j等于13個(gè)脈沖,電機(jī)旋轉(zhuǎn)一周。改變j的值就會(huì)改變電機(jī)的角度
  162.                 for(j=25;j>0;j--)//正轉(zhuǎn)二周
  163.                 {
  164.                         for(i=0;i<8;i++)
  165.                           {
  166.                                 display();
  167.                        
  168.                                  P0=zhengzhuan[i];//正轉(zhuǎn)數(shù)組
  169.                                    Delay(3);
  170.                                        
  171.                         }       
  172.                 }
  173.                 Delay(2000);
  174.                 for(j=25;j>0;j--)//反轉(zhuǎn)一周
  175.                 {
  176.                         for(i=0;i<8;i++)
  177.                           {
  178.                                 display1();
  179.                                
  180.                                  P0=fanzhuan[i];//反轉(zhuǎn)數(shù)組
  181.                                    Delay(3);
  182.                                        
  183.                         }       
  184.                 }
  185.                 Delay(2000);
  186.         }*/
  187.        
  188.        
  189. /*        while(1)
  190.         {
  191.        
  192.                 //j等于13個(gè)脈沖,電機(jī)旋轉(zhuǎn)一周。改變j的值就會(huì)改變電機(jī)的角度
  193.                 for(j=250;j>0;j--)//正轉(zhuǎn)二十周
  194.                 {
  195.                         for(i=0;i<8;i++)
  196.                           {
  197.                                 display();                               
  198.                                  P0=zhengzhuan[i];//正轉(zhuǎn)數(shù)組
  199.                                    Delay(6);        //延時(shí)控制轉(zhuǎn)速不能小于500
  200.                                
  201.                         }       
  202.                 }
  203.                 Delay(2000);
  204.                 for(j=250;j>0;j--)//反轉(zhuǎn)二十周
  205.                 {
  206.                         for(i=0;i<8;i++)
  207.                           {
  208.                                 display1();
  209.                                  P0=fanzhuan[i];//反轉(zhuǎn)數(shù)組
  210.                                    Delay(6);        //延時(shí)控制轉(zhuǎn)速不能小于500
  211.                                
  212.                         }       
  213.                 }
  214.                 Delay(20000);
  215.         }*/

  216. /* while(1)
  217.   {

  218.        
  219.            for(i=0;i<8;i++)
  220.           {
  221.                   if(key)       //按鍵未按下,正轉(zhuǎn)
  222.                  {
  223.                            P0=zhengzhuan[i];//正轉(zhuǎn)數(shù)組
  224.                            Delay(8);
  225.                    }
  226.            else      //按鍵按下,反轉(zhuǎn)
  227.                  {
  228.                           P0=fanzhuan[i];//反轉(zhuǎn)數(shù)組
  229.                            Delay(8);
  230.                   }
  231.             }   
  232.    }*/
  233. }
復(fù)制代碼


評(píng)分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的積分獎(jiǎng)勵(lì)!

查看全部評(píng)分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩

相關(guān)帖子

回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:711365 發(fā)表于 2020-3-24 18:20 | 只看該作者
請(qǐng)問(wèn)有沒(méi)有仿真圖呢?謝謝啦
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表