|
楼主 |
发表于 2013-5-1 22:17:57
|
显示全部楼层
#include<reg52.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
uchar aa,i,temp,key;
void one();
void two ();
void three ();
void four ();
void delay (uint x)
{
uint i,j;
for( i=x; i>0; i-- )
for( j=110; j>0; j-- );
}
void keyscan()
{
P1=0x7f;
temp=P1;
temp=temp&0x0f;
if(temp!=0x0f)
{
delay(10);
temp=P1;
temp=temp&P1;
if(temp!=0x0f)
{
delay(10);
temp=P1;
switch( temp )
{
case 0x77:
key=1;
break;
case 0x7b:
key=2;
break;
case 0x7d:
key=3;
break;
case 0x7e:
key=4;
break;
while(temp!=0x0f)
{
temp=P1;
temp=temp&P1;
}
while(1);
}
}
}
}
void one ()
{
P0=0;
}
void two ()
{
delay(75);
P0=~P0;
}
void three ()
{ aa=0xfe;
for(i=8;i>0;i--)
{
P0=aa;
aa=_crol_(aa,1);
delay(100);
}
aa=0x7f;
for(i=8;i>0;i--)
{
P0=aa;
aa=_cror_(aa,1);
delay(100);
}
}
void four ()
{
aa=0xfe;
for(i=4;i>0;i--)
{
P0=aa;
aa=_crol_(aa,2);
delay(500);
}
aa=0x7f;
for(i=4;i>0;i--)
{
P0=aa;
aa=_cror_(aa,2);
delay(500);
}
}
void main ()
{
while(1){
keyscan();
if(key==1)
{
one();
}
if(key==2)
{
two();
}
if(key==3)
{
three();
}
if(key==4)
{
four();
}
}
}
改成这样就可以了 |
|