用于EagleEye3.0 规则集漏报和误报测试的示例项目,项目收集于github和gitee
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.3 KiB

5 months ago
#include "stm32f10x.h"
#include "delay.h"
#include "servo.h"
void ServoTurn(int dir)
{
TIM_SetCompare3(TIM4,dir);
delay_ms(ServoDelayTime);
}
void ServoInit(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM4_TimeBase;
TIM_OCInitTypeDef TIM4_OC;
//PB8
//GPIO<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB , ENABLE);
// RCC_APB1PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>PWM<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ20ms<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
TIM4_TimeBase.TIM_ClockDivision = 0;
TIM4_TimeBase.TIM_CounterMode = TIM_CounterMode_Up;
TIM4_TimeBase.TIM_Period = 200 - 1;
TIM4_TimeBase.TIM_Prescaler = 7200 - 1; //Ĭ<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD>Ϊ72MHz
TIM_TimeBaseInit(TIM4, &TIM4_TimeBase);
TIM4_OC.TIM_OCMode = TIM_OCMode_PWM1;
TIM4_OC.TIM_OCPolarity=TIM_OCPolarity_High;
TIM4_OC.TIM_OutputState = TIM_OutputState_Enable;
TIM4_OC.TIM_Pulse=100;
TIM_OC3Init(TIM4, &TIM4_OC);
TIM_Cmd(TIM4, ENABLE);
ServoTurn(SERVO_FRONT); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD>
}