<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > STM32用IO口控制步進(jìn)電機的簡單程序

          STM32用IO口控制步進(jìn)電機的簡單程序

          作者: 時間:2016-11-21 來源:網(wǎng)絡(luò) 收藏
          練習(xí)IO口庫函數(shù)操作。
          1. //相序
          2. uint16_tphasecw[4]={0x2000,0x0001,0x0004,0x0008};//D-C-B-A
          3. uint16_tphaseccw[4]={0x0008,0x0004,0x0001,0x2000};//A-B-C-D

          本文引用地址:http://www.ex-cimer.com/article/201611/319100.htm
          1. //步進(jìn)電機相關(guān)IO口初始化
          2. //IN4:PC13
          3. //IN3:PC0
          4. //IN2:PC2
          5. //IN1:PC3
          6. voidMoto_Init(void)
          7. {
          8. GPIO_InitTypeDefGPIO_InitStructure;
          9. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);//GPIOCLOCKENABLE
          10. GPIO_InitStructure.GPIO_Pin=GPIO_Pin_13;
          11. GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;//推挽輸出
          12. GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;//50MHz速率
          13. GPIO_Init(GPIOC,&GPIO_InitStructure);
          14. GPIO_ResetBits(GPIOC,GPIO_Pin_13);//輸出低電平
          15. GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0;
          16. GPIO_Init(GPIOC,&GPIO_InitStructure);
          17. GPIO_ResetBits(GPIOC,GPIO_Pin_0);
          18. GPIO_InitStructure.GPIO_Pin=GPIO_Pin_2;
          19. GPIO_Init(GPIOC,&GPIO_InitStructure);
          20. GPIO_ResetBits(GPIOC,GPIO_Pin_2);
          21. GPIO_InitStructure.GPIO_Pin=GPIO_Pin_3;
          22. GPIO_Init(GPIOC,&GPIO_InitStructure);
          23. GPIO_ResetBits(GPIOC,GPIO_Pin_3);
          24. }

          1. //電機正轉(zhuǎn)
          2. voidMotorcw(void)
          3. {
          4. uint8_ti;
          5. for(i=0;i<4;i++)
          6. {
          7. GPIO_Write(GPIOC,phasecw[i]);
          8. delay_ms(4);
          9. }
          10. }
          11. //電機反轉(zhuǎn)
          12. voidMotorccw(void)
          13. {
          14. uint8_ti;
          15. for(i=0;i<4;i++)
          16. {
          17. GPIO_Write(GPIOC,phaseccw[i]);
          18. delay_ms(4);
          19. }
          20. }
          21. //點擊停止
          22. voidMotorStop(void)
          23. {
          24. GPIO_Write(GPIOC,0x0000);
          25. }


          記得使能IO口時鐘。



          關(guān)鍵詞: STM32IO口步進(jìn)電

          評論


          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();