想要通过独立键盘控制数码管每按一次加1,警告说没有位选,烧到单片机上没有数码管亮,按键也没有反应,程序如下。
如何正确的位选?谢谢
#include
#define uchar unsigned char
#define uint unsigned int
***it key1=P3^0;
***it key2=P3^1;
***it key3=P3^2;
***it key4=P3^3;
uchar code table[]={
0xc0,0xf9,0xa4,0xb0, //ÊýÂë¹Ü±àÂë
0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,
0xcb,0xa1,0x86,0x8e};
unsigned char code seg[]={
0x7f,0xbf,0xdf,0xef,
0xf7,0xfb,0xfd,0xfe};
void delayms(uint);
void display(uchar);
uchar num,num0;
uchar shi,ge;
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void display(uchar num)
{
shi=num/10;
ge=num%10;
P2=0x7f;
P0=table[shi];
delayms(5);
P2=0xff;
delayms(8);
P2=0xbf;
P0=table[ge];
delayms(5);
P2=0xff;
delayms(8);
}
void keyscan()
{
if(!key1)
delayms(10);
if(!key1)
num++;
if(num==60)
num=0;
}
void main()
{
while(1);
display(num);
keyscan();
}
|