该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
程序如下:
#include
sbit ADDR0=P3^0;
sbit ADDR1=P3^1;
sbit ADDR2=P3^2;
sbit ADDR3=P3^3;
sbit KEY1=P3^4;
sbit KEY2=P3^5;
sbit KEY3=P3^6;
sbit KEY4=P3^7;
unsigned char code LED[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E
};
unsigned char keysta[4][4]={
{1,1,1,1},{1,1,1,1},{1,1,1,1},{1,1,1,1}
};
void main()
{
unsigned char keyback[4][4]={
{1,1,1,1},{1,1,1,1},{1,1,1,1},{1,1,1,1}
};
unsigned char i,j;
TMOD=0x01;
TH0=0xFC;
TL0=0x18;
TR0=1;
EA=1;
ET0=1;
P0=LED[0];
while(1)
{
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
if(keysta[i][j]!=keyback[i][j])
{
if(keyback[i][j]==0)
{
P0=LED[4*i+j];
}
keyback[i][j]=keysta[i][j];
}
}
}
}
}
void interruptTimer0() interrupt 1
{
static unsigned char keyout=0;
static unsigned char keybuff[4][4]={
{0xFF,0xFF,0xFF,0xFF},{0xFF,0xFF,0xFF,0xFF},{0xFF,0xFF,0xFF,0xFF},{0xFF,0xFF,0xFF,0xFF}
};
unsigned char i;
TH0=0xFC;
TL0=0x18;
keybuff[keyout][0]=(keybuff[keyout][0]<<1)|KEY1;
keybuff[keyout][1]=(keybuff[keyout][1]<<1)|KEY2;
keybuff[keyout][2]=(keybuff[keyout][2]<<1)|KEY3;
keybuff[keyout][3]=(keybuff[keyout][3]<<1)|KEY4;
for(i=0;i<4;i++)
{
if(keybuff[keyout][i]&0x0F==0x00)
{
keysta[keyout][i]=0;
}
else if(keybuff[keyout][i]&0x0F==0x0F)
{
keysta[keyout][i]=1;
}
else
{
}
}
keyout++;
keyout=keyout&0x03;
switch(keyout)
{
case 0:ADDR0=0;ADDR1=1;ADDR2=1;ADDR3=1;break;
case 1:ADDR0=1;ADDR1=0;ADDR2=1;ADDR3=1;break;
case 2:ADDR0=1;ADDR1=1;ADDR2=0;ADDR3=1;break;
case 3:ADDR0=1;ADDR1=1;ADDR2=1;ADDR3=0;break;
default:break;
}
}
为什么不成功。。。。。。求大神帮忙