我寫了一個按鍵檢測程序按下后只顯示00,按鍵不管用不知道哪里有問題希望有大佬幫忙解答一下
單片機源程序如下:
#include <STC15F2K60S2.H>
#define uint unsigned int
#define uchar unsigned char
uchar sce,temp,i;
const uchar LED7Code[]={0xC0,0xF9,0xA4,0xB0,
0x99,0x92,0x82,0xF8,
0x80,0x90,0x88,0x83,
0xC6,0xA1,0x86,0x8E
};
void anjian()
{
uchar aa,aa1,aa2;
P1=0xf0;
if(P1!=0xf0)
{
P2=0xff;
aa=P1;
P1=0x0f;
if(P1!=0x0f)
{aa1=P1;}
}
aa2=aa|aa1;
switch(aa2)
{
case 0xee:sce=0;break;
case 0xed:sce=1;break;
case 0xeb:sce=2;break;
case 0xe7:sce=3;break;
case 0xde:sce=4;break;
case 0xdd:sce=5;break;
case 0xdb:sce=6;break;
case 0xd7:sce=7;break;
case 0xbe:sce=8;break;
case 0xbd:sce=9;break;
case 0xbb:sce=10;break;
case 0xb7:sce=11;break;
case 0x7e:sce=12;break;
case 0x7d:sce=13;break;
case 0x7b:sce=14;break;
case 0x77:sce=15;break;
default:break;
}
}
void IO_Init()
{
P0M0 = 0x00;P0M1 = 0x00;
P1M0 = 0x00;P1M1 = 0x00;
P2M0 = 0x00;P2M1 = 0x00;
P3M0 = 0x00;P3M1 = 0x00;
P4M0 = 0x00;P4M1 = 0x00;
P5M0 = 0x00;P5M1 = 0x00;
P6M0 = 0x00;P6M1 = 0x00;
P7M0 = 0x00;P7M1 = 0x00;
P0 = 0x00;P1 = 0x00;P2 = 0xff;P3 = 0x00;
P4 = 0x00;P5 = 0x00;P6 = 0x00;P7 = 0x00;
}
void main()
{
P2=0;
IO_Init();
while(1)
{
anjian();
P0=LED7Code[sce];
}
}
|