#include <reg52.h>
#include <intrins.h>
#include <absacc.h>
#define somenop{_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();}
#define uchar unsigned char
sbit TX=P0^0;
sbit RX=P0^1;
sbit d1=P0^2;
unsigned int intr=0;
bit s_flag;
unsigned int t=0;
void delay_20us()
{
uchar bt;
for(bt=0;bt<10;bt++);
}
void main(void)
{
unsigned int distance;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
d1=1;
while(1)
{
if(s_flag)
{
s_flag=0;
ET0=0;
TX=1;
delay_20us();
TX=0;
EX1=1;
while((RX==0)&&(TF1==1));
TR1=1;
while((RX==1)&&(TF1==0));
TR1=0;
if(TF1==1)
{
TF1=0;
distance=9999;
}
else
{
t=TH1;
t<<=8;
t=TL1;
distance=t*0.017;
if(distance<=5)
{
d1=0;
}
else
{
d1=1;
}
}
TH1=0;
TL1=0;
}
}
}
void isr_
timer_0(void) interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
intr++;
if(intr==20)
{
s_flag=1;
intr=0;
}
}
不知道我这程序是不是有问题?
一周热门 更多>