试试看:
#include
#include
#define uint code unsigned int
#define uchar code unsigned char
sbit k5 = P1^4;
sbit k6 = P1^5;
sbit k7 = P1^6;
sbit k8 = P1^7;
//---------------------------------------------
void delay1ms(unsigned int i)
{
unsigned char j;
while(i--)
for(j = 0; j < 125; j );
}
//---------------------------------------------
void main( )
{
unsigned char t, ky;
P0 = 0xFe;
P0 = 0x7F;
ky = 0;
//---------------------------------------------
while(1) {
//-----------根据ky值散转----------------------
switch(ky)
{
case 0:
for(t = 0; t < 8; t ); {
P0 = _crol_(P0, 1); delay1ms(1000);
}
break;
case 1:
for(t = 0; t < 8; t ); {
P0 = _cror_(P0, 1); delay1ms(1000);
}
break;
case 2:
P0 = 0xF0;
break;
case 3:
P0 = 0x0F;
break;
default:
P0 = 0xFF;
break;
}
//-----------根据按键,修改ky值----------------
if(k5 == 0) ky = 0;
if(k6 == 0) ky = 1;
if(k7 == 0) ky = 2;
if(k8 == 0) ky = 3;
}
}
根据按键,修改ky值的部分,也可以弄个中断,时效性更强。
全部