[mw_shl_code=c,true]#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "led.h"
#include "TIMER.h"
u32 CAPTURE1;
int main()
{
SystemInit();
gpio_init();
TIM3_Int_Init();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置中断优先级分组
uart_init(115200);
delay_init();
LED_Init();
TIM3_Int_Init();
while(1)
{
CAPTURE1=(u32)TIM_GetCounter(TIM3);
printf("%d
",CAPTURE1);
delay_ms(100);
}
}
[/mw_shl_code]
[mw_shl_code=c,true]#include "TIMER.h"
#include "led.h"
#include "usart.h"
void gpio_init(void)
{
GPIO_InitTypeDef gpioinit;
RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOD,ENABLE);
gpioinit.GPIO_Mode=GPIO_Mode_IPD;
gpioinit.GPIO_Pin=GPIO_Pin_2;
gpioinit.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOD,&gpioinit);
}
void TIM3_Int_Init(void)//配置为外部计数器
{
TIM_TimeBaseInitTypeDef tim3init;
RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM3,ENABLE);
TIM_DeInit(TIM3);
tim3init.TIM_ClockDivision=0x0;
tim3init.TIM_CounterMode=TIM_CounterMode_Up;
tim3init.TIM_Period=0xFFFF;
tim3init.TIM_Prescaler=0X00;
TIM_TimeBaseInit(TIM3,&tim3init);
TIM_ETRClockMode2Config(TIM3,TIM_ExtTRGPSC_OFF,TIM_ExtTRGPolarity_NonInverted,0);
TIM_SetCounter(TIM3,0);
TIM_Cmd(TIM3,ENABLE);
}
[/mw_shl_code]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>