引用: Study_Stellaris 发表于 2014-11-6 09:19
你应该用 TimerValueGet
uint32_t timer_value,wave_distance; uint8_t s[25]; TimerLoadSet(TIMER0_BASE,TIMER_A,SysCtlClockGet());//初值装满 GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_3, 0x08);//触发信号 SysCtlDelay(800/3); //延时20微秒 GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_3, 0x00);//触发信号结束 while(GPIOPinRead(GPIO_PORTA_BASE, GPIO_PIN_2)==0x00);//收到回波检测到上升沿跳出 TimerEnable(TIMER0_BASE, TIMER_A);//开始计时 while(GPIOPinRead(GPIO_PORTA_BASE, GPIO_PIN_2)==0x04);//回波信号结束检测到下降沿跳出 timer_value=SysCtlClockGet()-TimerValueGet(TIMER0_BASE, TIMER_A);//读取值 TimerDisable(TIMER0_BASE, TIMER_A);//停止计时 wave_distance=timer_value*344000/SysCtlClockGet();//计算距离 sprintf(s,"%d",wave_distance);//写入字符数组 UARTSend(s);//通过串口打印 |