本帖最后由 2596226218 于 2018-12-19 10:28 编辑
#include "led.h"
#include "delay.h"
#include "key.h"
#include "sys.h"
#include "usart.h"
#include "timer.h"
/************************************************
************************************************/
extern u8 TIM5CH1_CAPTURE_STA;
extern u16 TIM5CH1_CAPTURE_VAL;
int main(void)
{
u16 dat;
u32 temp=0;
delay_init();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
uart_init(115200);
LED_Init();
TIM3_PWM_Init(899,0);
TIM5_Cap_Init(0XFFFF,72-1);
while(1)
{
if(TIM5CH1_CAPTURE_STA&0X80)
{
if(temp<0xffffffff)
{
temp=TIM5CH1_CAPTURE_STA&0X3F;
temp*=65536;
temp+=TIM5CH1_CAPTURE_VAL;
printf("°′¼üê±3¤:%d us\r\n",temp);
TIM5CH1_CAPTURE_STA=0;
if(temp<10000000000.0)
{
dat=(temp/1000000000.0)*65535;
TIM_SetCompare2(TIM3,dat);
}
else TIM_SetCompare2(TIM3,65535);
}
else TIM_SetCompare2(TIM3,65535);
}
}
}
|