#include <reg51.h>
#include "intrins.h"
#define LBIT P0
#define LNUM P2
#define IO_KEY P1
unsigned char code ledTab[]={0x3F,0x06,0x5B,0x4F,
0x66,0X6D,0X7D,0X07,
0X7F,0X6F,0X77,0X7C,
0x39,0x5E,0x79,0x71,
0x76,0x73,0x38,0x3e,0x00};//´æ·ÅLEDµÄµãÕóÂë
unsigned char code tabIndex[]={0xfe,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F};
unsigned char Num[8]={20,20,20,20,20,20,20,20};
void Delay_us(unsigned int time)
{
while(time--);
}
void dynamicLed(unsigned char Counter,unsigned char Ligh)
{
unsigned char i;
for(i=0;i<Counter;i++)
{
LBIT=tabIndex[i%8];
LNUM=ledTab[Num[i]%21];
Delay_us(Ligh);
LNUM=0x00;
}
}
unsigned char scanKey()
{
unsigned char temp,tempCode,i=0;
unsigned char LastCode=0;
tempCode=0x00;
IO_KEY=0x0F;
temp=IO_KEY;
if((temp&0x0F)!=0x0F)
{
Delay_us(200);
temp=0xF7;
while(i<4)
{
temp=_crol_(temp,1);
IO_KEY=temp;
tempCode=IO_KEY&0x0f;
if(tempCode!=0x0F)
{
switch(tempCode)
{
case 0x0E:
LastCode=LastCode+0;
break;
case 0x0D:
LastCode=LastCode+1;
break;
case 0x0B:
LastCode=LastCode+2;
break;
case 0x07:
LastCode=LastCode+3;
break;
default:
LastCode=LastCode+0;
break;
}
IO_KEY=0x0F;
temp=IO_KEY;
while((temp&0x0F)!=0x0F)
{
IO_KEY=0x0F;
temp=IO_KEY;
}
break;
}
i++;
LastCode+=4;
}
}
else
LastCode=16;
return LastCode;
}
void main(void)
{
unsigned char tempkey,i;
while(1)
{
tempkey=scanKey();
if(tempkey!=16)
{
for(i=0;i<7;i++)
{
Num[i]=Num[i+1];
}
Num[7]=tempkey;
}
dynamicLed(8,10);
}
}