开关接在P1.0。
#include
sbit key1=P1^0;
#define uint unsigned int
#define uchar unsigned char
uint n,a;uchar aa;
void delay(uint a)
{
uint i,j;
for(i=a;i>0;i--)
for(j=110;j>0;j--);
}
void keyscan()
{
if(key1==0)
{
delay(150);
if(key1==0)
{
n++;
if(n==2)n=0;
}
}
}
void main()
{
n=0;
aa=0xff;
while(1)
{
keyscan();
if(n==0)
{
aa=0xff;
};
if(n==1)
{
aa=0x00;
};
P2=aa;
}
}