#include <STC15F2K60S2.H>
#include <intrins.h>
#define u8 unsigned char
#define u16 unsigned int
u8 seg_display[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
u8 seg[8]={0xff,0xff,0xff,0,0xff,0xff,0xff,0xff};
sbit TX=P1^0;//发送
sbit RX=P1^1;//接收
bit display_distance=0;
u16 timer,distance;
void allint();
void Timer1Init(void);
void display();
void show_distance();
void Delay12us() ;
void send_wave();//发送
void measure_distance();
void Delay1ms() ;
void main()
{
allint();
Timer1Init();
while(1)
{
show_distance();
if(display_distance==1)
{
measure_distance();
display_distance=0;
}
}
}
void allint()
{
P0=0X00;
P2=P2&0X1F|0XA0;
P2&=0X1F;
P0=0Xff;
P2=P2&0X1F|0Xe0;
P2&=0X1F;
P0=0X00;
P2=P2&0X1F|0Xc0;
P2&=0X1F;
P0=0Xff;
P2=P2&0X1F|0X80;
P2&=0X1F;
}
void Timer1Init(void) //1毫秒@12.000MHz
{
AUXR |=
蓝桥杯超声波测距 - 基于定时器0
于 2022-03-19 15:40:08 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)