|
使用TIM1的CH1輸出PWM信號,使用定時器的PWM輸出功能,通過按鍵調(diào)整電機(jī)轉(zhuǎn)向及轉(zhuǎn)速
單片機(jī)源程序如下:
- #include "bsp_led.h"
- #include "systick.h"
- #include "bsp_usart.h"
- #include "bsp_motor.h"
- #include "bsp_AdvanceTim.h"
- #include "bsp_key.h"
- #include "stdio.h"
- u16 temp = 200;
- int main(void)
- {
- RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI);
- KEY_GPIO_Config();
- Motor_GPIO_Init();
- ADVANCE_TIM_GPIO_Config();
- ADVANCE_TIM_Mode_Config();
- while(1)
- {
-
- if(Key_Scan(KEY_GPIO_PORT,KEY1_GPIO_PIN)==KEY_ON)
- {
- Motor_Backward();
- }
- if(Key_Scan(KEY_GPIO_PORT,KEY2_GPIO_PIN)==KEY_ON)
- {
- Motor_Forward();
- }
- if(Key_Scan(KEY_GPIO_PORT,KEY3_GPIO_PIN)==KEY_ON)
- {
- if(temp>0)
- temp-=100;
- else
- temp = 0;
- }
- if(Key_Scan(KEY_GPIO_PORT,KEY4_GPIO_PIN)==KEY_ON)
- {
- if(temp<1000)
- temp+=100;
- else
- temp = 999;
- }
- TIM_SetCompare1(TIM1,temp);
- }
- }
-
復(fù)制代碼
Keil代碼與Proteus仿真下載: 求指導(dǎo)
工程1.7z
(247.5 KB, 下載次數(shù): 11)
2022-11-25 20:03 上傳
點擊文件名下載附件
keil工程+proteus工程
|
|