標(biāo)題: 我寫的單片機程序循環(huán)讓步進電機轉(zhuǎn)一定角度,可它一直轉(zhuǎn)求大神解答 [打印本頁]

作者: 15939010388    時間: 2018-4-4 15:26
標(biāo)題: 我寫的單片機程序循環(huán)讓步進電機轉(zhuǎn)一定角度,可它一直轉(zhuǎn)求大神解答
通電以后步進電機一直在轉(zhuǎn),我分析的應(yīng)該轉(zhuǎn)5個周期就停下了啊

單片機源程序如下:
  1. #include<reg51.h>
  2. #define uint unsigned int
  3. #define uchar unsigned char      
  4. #define GPIO_DJ P1
  5. unsigned char code eight_pos[8]={0x06,0x07,0x03,0x0b,0x09,0x0d,0x0c,0x0e};//八拍驅(qū)動方式正轉(zhuǎn)表 AD-D-DC-C-CB-B-BA-A
  6. unsigned char code eight_rev[8]={0x0e,0x0c,0x0d,0x09,0x0b,0x03,0x07,0x06};//八拍驅(qū)動方式反轉(zhuǎn)表 A-AB-B-BC-C-CD-D-DA
  7. unsigned char code eight_pos[8]={0x06,0x07,0x03,0x0b,0x09,0x0d,0x0c,0x0e};//八拍驅(qū)動方式正轉(zhuǎn)表 AD-D-DC-C-CB-B-BA-A
  8. unsigned char code eight_rev[8]={0x0e,0x0c,0x0d,0x09,0x0b,0x03,0x07,0x06};//八拍驅(qū)動方式反轉(zhuǎn)表 A-AB-B-BC-C-CD-D-DA
  9. void Delay1ms(unsigned int c);//定義延時程序   
  10. unsigned   int a,b,i,j,k,z;          //采集的亮度值及當(dāng)前的步進電機角度
  11. unsigned   char pp;                              //讀取二十次ad值for循環(huán)
  12. unsigned   int  c=0,d=0;                  

  13. void Delay(unsigned int i)//延時
  14. {
  15. while(--i);
  16. }

  17. void delay1ms(z)
  18. {
  19. unsigned int x,y;
  20.         for(x=z;x>0;x--)
  21.                 for(y=110;y>0;y--);
  22. }
  23. void m_eight_pos()
  24. {

  25.                 j=0;
  26.                 for(i=0;i<8;i++)//在八拍工作方式下,一個脈沖轉(zhuǎn)子轉(zhuǎn)動角度為5.625度,八拍共45度
  27.                 {
  28.                         P1=eight_pos[j];
  29.                         delay1ms(2);
  30.                         j++;
  31.                 }
  32.       
  33. }
  34. /*******************八拍驅(qū)動反轉(zhuǎn)(N*45/16)度***********************/
  35. void m_eight_rev()
  36. {
  37.                 j=0;
  38.                 for(i=0;i<8;i++)//在八拍工作方式下,一個脈沖轉(zhuǎn)子轉(zhuǎn)動角度為5.625度,八拍共45度
  39.                 {
  40.                         P1=eight_rev[j];
  41.                         delay1ms(2);
  42.                         j++;
  43.                 }
  44. }
  45. void main(void)
  46. {   
  47.    b=0;
  48.    while(1)
  49.    {

  50.      a=100;
  51.                 if(a>=b)
  52.             {  
  53.                   for(i=((a-b)/20);i>0;i--)
  54.                            {
  55.                              b+=20;
  56.                              m_eight_rev();
  57.                                 }
  58.              }
  59.                  else
  60.                  {
  61.                    for(i=((b-a)/20);i>0;i--)
  62.                        {
  63.                         b-=20;
  64.                                 m_eight_pos();
  65.                             }
  66.                  }
  67.   }
  68. }
復(fù)制代碼


作者: 賊心不死    時間: 2018-9-15 08:30
想問下樓主解決了嗎?我們也遇到了類似的問題....




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