在Proteus仿真的时候P0.6和P0.7口一直输出高电平
如图
我并没有按下任何按键,按理说应该是显示0才对。
程序如下
#include<reg51.h>
sbit P14=P1^4;
sbit P15=P1^5;
sbit P16=P1^6;
sbit P17=P1^7;
sbit P25=P2^5;
sbit P26=P2^6;
unsigned char code Tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
unsigned char keyval=0;
void delay()
{
unsigned char i;
for(i=0;i<230;i++);
}
void display(unsigned char k)
{
unsigned char a=0;
P2=0;
a=Tab[k/10];
P0=a;
P25=1;
delay();
a=0xff;
P0=a;
P25=0;
a=Tab[k%10];
P0 = a;
P26=1;
delay();
P26=0;
a=0xff;
P0=a;
//TR0 = 1;
}
void delay20ms(void)
{
unsigned char i,j;
for(i=0;i<100;i++)
for(j=0;j<60;j++);
}
void main(void)
{
EA=1;
ET0=1;
TMOD=0x01;
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
TR0=1;
keyval=0x00;
P0=0xff;
while(1)
{
display(keyval);
}
}
void time0_interserve(void) interrupt 1
{
TR0=0;
P1=0xf0;
if((P1&0xf0)!=0xf0)
{
delay20ms();
if((P1&0xf0)!=0xf0)
{
P1=0xfe;
if(P14==0)
keyval=1;
if(P15==0)
keyval=2;
if(P16==0)
keyval=3;
if(P17==0)
keyval=4;
P1=0xfd;
if(P14==0)
keyval=5;
if(P15==0)
keyval=6;
if(P16==0)
keyval=7;
if(P17==0)
keyval=8;
P1=0xfb;
if(P14==0)
keyval=9;
if(P15==0)
keyval=10;
if(P16==0)
keyval=11;
if(P17==0)
keyval=12;
P1=0xf7;
if(P14==0)
keyval=13;
if(P15==0)
keyval=14;
if(P16==0)
keyval=15;
if(P17==0)
keyval=16;
}
}
TH0=(65536-500)/256;
TL0=(65536-500)%256;
TR0=1;
}
|