📄 ultrasonic11.c
字号:
#include<P89V51.H>
#include<LCD.C>
sbit P1_6 =P1^6;
sbit P1_7 =P1^7;
unsigned char a,b;
unsigned int c;
char count=0;
void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData);
/////////////////////////////////////////////////////
void timer0(void) interrupt 1 using 1 //定时发射超声波250us//定时器0
{
count=count+1;
if(count==1)
P1_6=0;
if(count>5)
{ P1_6=1;
count=0;
TMOD=0x01;
TH0=(65535-500)/256;
TL0=(65535-500)%256; //定时250us发送声波
//IP=0x02; //中断优先级
ET0=1;
TR0=1;
//IT1=1;
//EX1=1;
//IE1=1;
}
}
//////////////////////////////////////////////////////
////////////////////////////////////////////////////////
void counter(void) interrupt 2 using 2 //测出往返时间
{
IE1=0;
TR0=0;
a=TL0;
b=TH0;
TMOD=0x01;
TH0=(65535-500)/256;
TL0=(65535-500)%256; //定时250us发送声波
//IP=0x02; //中断优先级
TR0=1;
ET0=1;
//EA=0;
P1_7=!P1_7;
//IE1=1;
}
void Delay(unsigned char c,unsigned char d,unsigned char e)
{
unsigned char i,j,k;
for(i=0;i<=c;i++)
{
for(j=0;j<=d;j++)
for(k=0;k<=e;k++);
}
}
//////////////////////////////////////////////////////
main()
{
PSB=1;
RST=0;
Delay(100,100,1);
RST=1;
Delay(100,100,1);
EA=0;
LCMInit();
Delay(100,100,1);
TMOD=0x01;
TH0=(65535-500)/256;
TL0=(65535-500)%256; //定时250us发送声波
//IP=0x02; //中断优先级
EA=1;
ET0=1;
TR0=1;
P1_6=0;
P1_6=0;
while(1)
{
;//P1_6=0;
/*
c=((unsigned int)b<<8)+a;
DisplayOneChar(0,0,0x41);
DisplayInt(1,0,c);
Delay(100,100,5);
WriteCommandLCM(0x02,1);*/
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -