引用 5 楼 peasant_lee 的回复:
安装楼主你的回答,我现在的理解是:mian()函数,就是一些串口和中断初始化。所有的操作都是放在中断函数里面,建议将这个函数贴出来吧,问题很有可能就在那里。
好的
#include
#include
#include
#define uchar unsigned char
#define uint unsigned int
uchar temp;
uint num,a;
sbit P1_7=P1^7;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void Int0() interrupt 0
{
EX0=0;
P1=0xfe;
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P1;
switch(temp)
{
case 0xbe:num=1;
break;
case 0xde:num=2;
break;
case 0xee:num=3;
break;
}
if(temp!=0xf0)
{
temp=P1;
temp=temp&0xf0;
}
}
}
P1=0xfd;
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P1;
switch(temp)
{
case 0xbd:num=4;
break;
case 0xdd:num=5;
break;
case 0xed:num=6;
break;
}
if(temp!=0xf0)
{
temp=P1;
temp=temp&0xf0;
}
}
}
P1=0xfb;
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P1;
switch(temp)
{
case 0xbb:num=7;
break;
case 0xdb:num=8;
break;
case 0xeb:num=9;
break;
}
if(temp!=0xf0)
{
temp=P1;
temp=temp&0xf0;
}
}
}
P1=0xf7;
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P1;
switch(temp)
{
case 0xd7:num=0;
break;
}
if(temp!=0xf0)
{
temp=P1;
temp=temp&0xf0;
}
}
}
SBUF=num;
printf("%d",num);
while(!TI);
TI=0;
a++;
}
main()
{
a=0;
while(a