#include "led.h"
#include "delay.h"
#include "sys.h"
#include "usart.h"
#include "timer.h"
#include "chao.h"
u16 S;
void StartModule()
{
TX=1;
delay_us(15);
TX=0;
delay_us(300);
}
void Count()
{
S=(TIM3->CNT*340/2000);
printf("\n测得的距离:%d毫米\n\n",S);
LED1=!LED1;
}
int main(void)
{
SystemInit();
delay_init(72); //延时初始化
NVIC_Configuration();
uart_init(9600); //串口初始化
chao_init();
LED_Init(); //LED端口初始化
Timerx_Init(60000,71);//10Khz的计数频率,计数到5000为500ms
while(1)
{
printf("\nEEPW ARM DIY 奋斗STM32");
printf("\n超声波模块测距串口显示\n\n");
StartModule();
LED4=!LED4;
while(RX==0); //当RX为零时等待
TIM3->CNT=0;
TIM_Cmd(TIM3, ENABLE); //使能定时器3 //开启计数
while(RX==1); //当RX为1计数并等待
TIM_Cmd(TIM3, DISABLE); //关闭定时器3
Count(); //计算
delay_ms(200);
}
}
待会上传视频。。
void KeyDispose(u8 KEY)
{
if(KEY&0x01)
{
LedIndex=0;
LedDirection=1;
RunMode=(RunMode+1)%6;
}
if(KEY&0x02)
{
if(SystemSpeedIndex<28)
{
++SystemSpeedIndex;
SetSpeed(SystemSpeedIndex);
}
}
if(KEY&0x04)
{
if(SystemSpeedIndex>0)
{
--SystemSpeedIndex;
SetSpeed(SystemSpeedIndex);
}
}
}
void TIM3_IRQHandler(void) //TIM3中断
{
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET) //检查指定的TIM中断发生与否:TIM 中断源
{
TIM_ClearITPendingBit(TIM3, TIM_IT_Update ); //清除TIMx的中断待处理位:TIM 中断源
if(++TimerCount>=SystemSpeed)
{
TimerCount=0;
TimerEventRun();
}
}
}
int main(void)
{
u8 KEY;
SystemInit(); //系统时钟设置
delay_init(72); //延时初始化
NVIC_Configuration();//设置NVIC中断分组2:2位抢占优先级,2位响应优先级
LED_Init(); //初始化与LED连接的硬件接口
Init_CPU();
Timerx_Init(13000,71);
KEY_Init(); //初始化与按键连接的硬件接口
while(1)
{
KEY=KEY_Scan();
if(KEY!=0x00)
{
KeyDispose(KEY);
}
}
}
回复
有奖活动 | |
---|---|
【有奖活动——B站互动赢积分】活动开启啦! | |
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |