#include
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
extern void cs_t(void);
extern void delay(uint);
extern void display();
data uchar testok;
data ulong time,num;
uchar dispram[5]={0,0,0,0,0};
code tab[18]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xbf,0xff};
code btab[4]={0xfe,0xfd,0xfb,0xf7};
/*主程序*/
sbit send=P1^0;
uchar z;
void bcd(ulong num)
{ dispram[0] = num%10;
dispram[1] = (num/10)%10;
dispram[2] = (num/100)%10;
dispram[3] = (num/1000)%10;
}
void init(void)
{ TMOD = 0x21;
EA=1;
EX0 = 1;
ET1=1;
// ET0 = 1;
TH0=0;
TL0=0;
TH1=248;
TL1=248;
IT0=1;
TR0=1;
TR1=1;
}
void main(void)
{ uint i;
init();
testok = 0;
delay(100);
while (1)
{
//delay(1000);
//while (!testok) display(num);
if (testok == 1)
{
time *=172;
time /= 10000;
num=time;
bcd(num);
if (dispram[3]==0) dispram[3] = 17;
}
else
{
dispram[0] = 16;
dispram[1] = 16;
dispram[2] = 16;
dispram[3] = 16;
}
for (i=0; i<100; i++)
{
display();
}
}
}
/*超声接收程序(外中断0)*/
void cs_r(void) interrupt 0
{
TR0=0;
//EX0 = 0;
time = TH0;
time = (time<<8) | TL0;
TH0=0;
TL0=0;
testok = 1;
TR0=1;
}
/*超时清除程序(内中断T0)*/
/*void overtime(void) interrupt 1
{
EX0 = 0;
TR0 = 0;
ET0 = 0;
testok = 2;
}*/
void cs_t(void) interrupt 3
{ //uchar num;
TH1=248;
TL1=248;
send=~send;
//num++;
//if(num>=12)
//TR1=0;
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void display()
{ uchar i;
for(i=0;i<4;i++)
{ P2|=0x0f;
P0= tab[dispram];
P2= btab;
delay(1);
P2|=0x0f;
}
}
我怎么好像进不了外部中断0啊 晕啊 不显示 距离 清人指点一下啊 谢谢 我很急
你的初始化函数 void init()中的外部中断0允许ET0=1都被你用“//”号屏蔽了,起不了作用怎么启动外部中断点啊。。。。。。。。。。后面还有比较多的似乎画蛇添足的“//”号,应该反它们都去掉,它们屏蔽掉了许多函数的功能啊!