#include "pic.h"
#define uchar unsigned char
#define uint unsigned int
//__CONFIG(0xff3);
#define DIGITKEY RA0
uchar LEDFLASH_Type=0;
uchar i=0;
void System_Init(void);
void Process_Key(void);
void Led_Display(void);
void LED_Delay(uint j);
const uchar LEDCODE0[]={0x5a,0x5a,0x5a,0x5a,0xa5,0xa5,0xa5,0xa5,};
const uchar LEDCODE1[]={0xf0,0xf0,0xf0,0xf0,0x0f,0x0f,0x0f,0x0f,};
const uchar LEDCODE2[]={0xe7,0xe7,0xe7,0xe7,0xdb,0xdb,0xdb,0xdb,
0xbd,0xbd,0xbd,0xbd,0x7e,0x7e,0x7e,0x7e,};
void main()
{
System_Init();
while(1)
{
Process_Key();
Led_Display();
}
}
void System_Init()
{
TRISA=0x01;
RA0=1;
TRISB=0x00;
PORTB=0x00;
}
void Process_Key()
{
if(0==DIGITKEY)
{ LED_Delay(10);
if(0==DIGITKEY)
{ LEDFLASH_Type++;
if(LEDFLASH_Type==3)LEDFLASH_Type=0;
}
while(0!=DIGITKEY){Led_Display();}
}
}
void Led_Display()
{uchar k;
switch(LEDFLASH_Type)
{
case 0: for(i=0;i<sizeof(LEDCODE0);i++)
{
PORTB=LEDCODE0[i];
LED_Delay(100);
PORTB=0xff;
LED_Delay(50);
}
break;
case 1: for(i=0;i<sizeof(LEDCODE1);i++)
{
PORTB=LEDCODE1[i];
LED_Delay(100);
PORTB=0xff;
LED_Delay(50);
}
break;
case 2:for(i=0;i<sizeof(LEDCODE2);i++)
{
PORTB=LEDCODE2[i];
LED_Delay(100);
PORTB=0xff;
LED_Delay(50);
}
break;
}
}
void LED_Delay(uint j)
{
uint a,b;
for(a=j;a>0;a--)
for(b=65;b>0;b--);
}