以下程序出不来结果,哪位大侠指点一下
#include<reg52.h>
#define date P0
#define uchar unsigned char
#define uint unsigned int
sbit D=P2^2; //段码控制位
sbit W=P2^3; //位码控制位
sbit T=P1^0; //发射控制位
//sbit S=P2^0; //蜂鸣器控制位
uchar code duan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //0-9编码
uchar code wei[]={0xef,0xdf,0xbf,0x7f}; //数码管四个位编码
uchar temp[3];
uint timeh,timel,time;
bit succeed_flag;
void delayus(uchar t) //延时子函数
{
while(t--);
}
void delayms(uint o)
{
while(o--)
{
delayus(245); //大约延时1ms ,12m晶振
delayus(245);
}
}
void desplay(uint num) //显示距离子函数
{
uint ge,shi,bai,qian,i;
ge=(num%1000)%100%10;
shi=(num%1000)%100/10;
bai=num%1000/100;
qian=num/1000;
temp[3]=duan[ge];
temp[2]=duan[shi];
temp[1]=duan[bai];
temp[0]=duan[qian];
for(i=0;i<4;i++)
{
date=wei[i];
W=1;
W=0;
date=temp[i];
D=1;
D=0;
delayus(20);
}
}
void init_timer0() //定时器初始化
{
TMOD|=0x01;
TH0=(65536-5)/256;
TL0=(65536-5)%256;
}
void main()
{
while(1)
{
uint distance;
EA=0;
T=1;
T=0;
delayus(7); //产生一个20us的脉冲
T=1;
init_timer0();
EA=1; IT0=1;ET0=1; TR0=1; EX0=1;
// while(succeed_flag==0);
if(succeed_flag==1)
{
distance=time*7;
desplay(distance);
succeed_flag=0;
time=0;
}
else
{
desplay(125);
}
}
}
void timer0() interrupt 1 //定时器中断
{
TH0=(65536-5)/256;
TL0=(65536-5)%256;
time++;
}
void ext() interrupt 0 //外部中断0
{
succeed_flag=1;
EX0=0;
TR0=0;
} |