哪里出了问题,搞不懂。
nt main(void)
{
int distance ;
u16 TIM = 0;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//éèÖÃÏμí3ÖD¶ÏóÅÏ輶·Ö×é2
delay_init(168); //3õê¼»ˉÑóê±oˉêy
LED_Init(); //3õê¼»ˉLED¶Ë¿ú
uart_init(115200);
TIM3_Int_Init(5000-1,8400-1); //¶¨ê±Æ÷ê±Öó84M£¬·ÖÆμÏμêy8400£¬ËùòÔ84M/420=200KhzμļÆêyÆμÂ꣬¼Æêy5000′ÎÎa500ms
Ultran_Init() ;
while(1)
{
GPIO_SetBits(ULTRA_PORT, ULTRA_TRIG); //¸øtrig′óóú10usμĸßμçƽ
delay_us(20);
GPIO_ResetBits(ULTRA_PORT, ULTRA_TRIG);
while(!GPIO_ReadInputDataBit(ULTRA_PORT, ULTRA_ECHO)) //μè′yecho¸ßμçƽ
TIM_SetCounter(TIM3,0);
TIM_Cmd(TIM3,ENABLE); //¶¨ê±Æ÷¼ÆêyÆ÷ÖÃá㣬òòÎa′óÕaàï¿a꼼Ǽ¸ßμçƽ걼ä
while(GPIO_ReadInputDataBit(ULTRA_PORT, ULTRA_ECHO)) //μè′yμíμçƽ
TIM_Cmd(TIM3, DISABLE); //¸ßμçƽ½áêø£¬1رն¨ê±Æ÷
TIM = TIM_GetCounter(TIM3);
distance = TIM*0.85;
printf("distance is = %d cm
",distance);
delay_ms(500);
LED0=!LED0;
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
能发一份给我吗
一周热门 更多>