探索TIM2两个PWM输出
视频:B站BV1vb4y1T72L
Main.C
主函数部分节选
#include "stm32f10x.h" // Device header
#include "Delay.h"
#include "OLED.h"
#include "TestLED.h"
#include "PWM.h"
#include "KEY.h"
#include "Servo.h"
int main(void)
{
TestLED_Init();
PWM_Init();
OLED_Init();
OLED_ShowString(1, 1,"CCR1 CCR2");
OLED_ShowString(3, 1,"Turn Angle");
OLED_ShowNum(2, 1,0, 5);
OLED_ShowNum(2, 8,0, 5);
OLED_ShowSignedNum(4, 1,0, 5);
OLED_ShowNum(4, 8,0, 5);
Key_Init();
Servo_Init();
int16_t i=0,flag1=1,flag2=1,x=90;
float tmp1,tmp2;
while(1)
{
if(Key_GetNum()==1)
{
i+=(20*flag1);
x+=(4*flag2);
tmp1=(x/180)*2000+500.00;
tmp2=(i/180)*2000+500.00;
if(i==180){flag1=-1;}
if(i==0) {flag1=1;}
if(x==98){flag2=-1;}
if(x==82) {flag2=1;}
OLED_ShowNum(2, 1,tmp1, 5);
OLED_ShowNum(2, 8,tmp2, 5);
OLED_ShowSignedNum(4, 1,flag2, 5);
OLED_ShowNum(4, 8,i, 5);
}
Servo_SetAngle2(i);
Servo_SetAngle1(x);
}
}