新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > STM32用IO口控制步進電機的簡單程序

        STM32用IO口控制步進電機的簡單程序

        作者: 時間:2016-11-21 來源:網絡 收藏
        練習IO口庫函數操作。
        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.104case.com/article/201611/319100.htm
        1. //步進電機相關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. //電機正轉
        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. //電機反轉
        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口時鐘。



        關鍵詞: STM32IO口步進電

        評論


        技術專區

        關閉
        主站蜘蛛池模板: 调兵山市| 平和县| 双鸭山市| 镇远县| 田阳县| 五寨县| 剑河县| 左云县| 资中县| 南宫市| 曲阜市| 工布江达县| 潼南县| 荔浦县| 博罗县| 宜宾市| 永善县| 石渠县| 金阳县| 柘城县| 镇平县| 武陟县| 青田县| 贵溪市| 东至县| 乡宁县| 子长县| 成武县| 盐城市| 民勤县| 嘉禾县| 江山市| 馆陶县| 应城市| 昌都县| 常州市| 正阳县| 张家界市| 忻城县| 洛川县| 山丹县|