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

標題: STM32單片機PWM驅動電機程序 [打印本頁]

作者: 小鋇愛學    時間: 2023-10-21 13:44
標題: STM32單片機PWM驅動電機程序
#include "stm32f10x.h"                  // Device header
#include "PWM.h"

void Motor_Init(void)
{
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
        
        GPIO_InitTypeDef GPIO_InitStructure;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(GPIOA, &GPIO_InitStructure);
        
        PWM_Init();
}

void Motor_SetSpeed(int8_t Speed)
{
        if (Speed >= 0)
        {
                GPIO_SetBits(GPIOA, GPIO_Pin_4);
                GPIO_ResetBits(GPIOA, GPIO_Pin_5);
                PWM_SetCompare3(Speed);
        }
        else
        {
                GPIO_ResetBits(GPIOA, GPIO_Pin_4);
                GPIO_SetBits(GPIOA, GPIO_Pin_5);
                PWM_SetCompare3(-Speed);
        }
}

  1. #include "stm32f10x.h"                  // Device header
  2. #include "Delay.h"
  3. #include "OLED.h"
  4. #include "Motor.h"
  5. #include "Key.h"

  6. uint8_t KeyNum;
  7. int8_t Speed;

  8. int main(void)
  9. {
  10.     OLED_Init();
  11.     Motor_Init();
  12.     Key_Init();
  13.    
  14.     OLED_ShowString(1, 1, "Speed:");
  15.    
  16.     while (1)
  17.     {
  18.         KeyNum = Key_GetNum();
  19.         if (KeyNum == 1)
  20.         {
  21.             Speed += 20;
  22.             if (Speed > 100)
  23.             {
  24.                 Speed = -100;
  25.             }
  26.         }
  27.         Motor_SetSpeed(Speed);
  28.         OLED_ShowSignedNum(1, 7, Speed, 3);
  29.     }
  30. }
復制代碼

原理圖: 無
仿真: 無
代碼: PWM驅動直流電機.7z (176.85 KB, 下載次數: 22)






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