標(biāo)題: 單片機(jī)基礎(chǔ)學(xué)習(xí)2.2—步進(jìn)電機(jī)的簡單使用 [打印本頁]

作者: hhh365    時間: 2020-6-21 17:34
標(biāo)題: 單片機(jī)基礎(chǔ)學(xué)習(xí)2.2—步進(jìn)電機(jī)的簡單使用
學(xué)習(xí)了步進(jìn)電機(jī)的簡單編程和仿真,分享給大家功能:實現(xiàn)步進(jìn)電機(jī)轉(zhuǎn)動(每次90°)


  1. #include <reg51.h>
  2. #define uint unsigned int
  3. unsigned char code f_rotation[4]={0xCF,0x9F,0x3F,0x6F };       //雙4拍正轉(zhuǎn)相序字
  4. unsigned char code b_rotation[4]={0x6F,0x3F,0x9F,0xCF };     //雙4拍反轉(zhuǎn)相序字
  5. void    delay_ms(uint x)         //以毫秒為單位的步間延時函數(shù)
  6. {
  7.     uint i,j;
  8.     for (i=x; i>0; i--)
  9.     for (j=700; j>0;j--);
  10. }
  11. void main()
  12. {   unsigned char i;
  13.     while(1)
  14.     {   
  15.      for(i=0;i<4;i++)      
  16.      {
  17. P2=f_rotation[ i];         //查表并輸出相序字,可自行換成反轉(zhuǎn)表格[ i]
  18.               delay_ms(200);             //改變延時可調(diào)整步進(jìn)電機(jī)的轉(zhuǎn)速
  19.            }
  20.     }
  21. }
復(fù)制代碼





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