標(biāo)題:
stm32f103按鍵控制舵機(jī)程序
[打印本頁]
作者:
15290037438
時(shí)間:
2021-4-16 09:37
標(biāo)題:
stm32f103按鍵控制舵機(jī)程序
定時(shí)器4通道3PB8
PWM周期為20ms
0.5ms---0度
-
-
-
2.5ms--180度
單片機(jī)源程序如下:
#include "stm32f10x.h"
#include "bsp_led.h"
#include "bsp_GeneralTim.h"
#include "key.h"
#include "systick.h"
#include <math.h>
#include <stdlib.h>
int main(void)
{
/* led 端口配置 */
LED_GPIO_Config();
Key_GPIO_Config();
/* 定時(shí)器初始化 */
GENERAL_TIM_Init();
//LED1_TOGGLE;
uint16_t jiaodu=0,pulse=0;
while(1)
{
if( Key_Scan(KEY1_GPIO_PORT,KEY1_GPIO_PIN) == KEY_ON )
{
LED1_TOGGLE;
jiaodu=jiaodu+10;
}
if( Key_Scan(KEY2_GPIO_PORT,KEY2_GPIO_PIN) == KEY_ON )
{
LED2_TOGGLE;
jiaodu=jiaodu-10;
}
if((jiaodu>0) && (jiaodu<=180))
{
pulse=500+(2500-500)/180*jiaodu;
TIM_SetCompare3(GENERAL_TIM ,pulse);
}
else
{
jiaodu=0;
pulse=500+(2500-500)/180*jiaodu;
TIM_SetCompare3(GENERAL_TIM ,pulse);
}
}
}
/*********************************************END OF FILE**********************/
復(fù)制代碼
所有代碼51hei提供下載:
按鍵控制舵機(jī).7z
(182.96 KB, 下載次數(shù): 44)
2021-4-16 19:02 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1