#include "reg52.h"
#include "intrins.h"
#define uchar unsigned char
#define uint unsigned int
sbit wei=P2^7;
sbit duan=P2^6;
sbit key=P3^2;
uchar bb,aa;
uchar code table1[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uchar code table2[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
void delay(uint ms)
{
uint a,b;
for(a=ms;a>0;a--)
for(b=110;b>0;b--);
}
void main()
{
uint aa,bb,num;
wei=1;
P0=0xfe;
wei=0;
while(1)
{
aa=0xff;
P3=aa;
if(P3!=0xff)
{
delay(10);
if(P3!=0xff)
{
bb=P3;
switch(bb)
{
case 0x7f:num++;if(num==10) num=0;break;
case 0xbf:num--;if(num==-1) num=9;break;
case 0xef:num=0;break;
case 0xfd:num=9;break;
//default:num=0;break;
}
while(P3!=0xff);
}
delay(10);
while(P3!=0xff);
}
duan=1;
P0=table1[num];
duan=0;
if(key==0) //用这两句可以识别
num=9; //用switch不行
}
}
为什么P3^2不起作用 ?? |