#include<reg51.h>
#include<intrins.h>
#define GPI0_LED P0
#define GPI0_KEY P1
void Delay10ms(unsigned int c);
unsigned char Key_Scan();
void LED1();
void LED2();
void LED3();
void LED4();
void LED5();
void LED6();
void LED7();
void LED8();
void main(void)
{
unsigned char keyNum;
while(1)
{ keyNum=Key_Scan();
switch (keyNum)
{
case(0xEF):
LED1();
break;
case(0xDF):
LED2();
break;
case(0xBF):
LED3();
break;
case(0x7F):
LED4();
break;
case(0xFE):
LED5();
break;
case(0xFD):
LED6();
break;
case(0xFB):
LED7();
break;
case(0xF7):
LED8();
break;
dafault:
break;
}
}
}
unsigned char Key_Scan()
{ unsigned char keyValue=0,i;
if (GPI0_KEY != 0xFF)
{
Delay10ms(1);
if (GPI0_KEY != 0xFF)
{
keyValue=GPI0_KEY;
i=0;
while((i<50)&&(GPI0_KEY != 0xFF))
{
Delay10ms(1);
i++;
}
}
}
return keyValue;
}
void Delay10ms(unsigned int c)
{unsigned char a,b;
for (;c>0;c--)
{
for (b=38;b>0;b--)
{
for (a=130;a>0;a--);
}
}
}
void LED1()
{
GPI0_LED=0x00;
Delay10ms(50);
GPI0_LED=0xFF;
Delay10ms(50);
}
void LED2()
{
GPI0_LED=0xCC;
Delay10ms(5);
GPI0_LED=0x33;
Delay10ms(5);
GPI0_LED=0xCC;
Delay10ms(5);
GPI0_LED=0x33;
Delay10ms(5);
}
void LED3()
{
GPI0_LED=0x99;
Delay10ms(5);
GPI0_LED=0x66;
Delay10ms(5);
GPI0_LED=0x99;
Delay10ms(5);
GPI0_LED=0x66;
Delay10ms(5);
}
void LED4()
{
GPI0_LED=0xAA;
Delay10ms(5);
GPI0_LED=0x55;
Delay10ms(5);
GPI0_LED=0xAA;
Delay10ms(5);
GPI0_LED=0x55;
Delay10ms(5);
}
void LED5()
{
LED1();
LED2();
LED3();
LED4();
}
void LED6()
{GPI0_LED=0xFE;
while(1)
{ Delay10ms(50);
GPI0_LED=_crol_(P0,1);
}
}
void LED7()
{GPI0_LED=0x7F;
while(1)
{ Delay10ms(50);
GPI0_LED=_cror_(P0,1);
}
}
void LED8()
{
GPI0_LED=0x00;
此帖出自
小平头技术问答
同意。也觉得是流水灯的程序占用太多时间,用中断的方式处理比较好。
一周热门 更多>