不知你要的是不是下面这种
这是源码:
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar code Table_OF_Digits[]=
{
0x00,0x3e,0x41,0x41,0x41,0x3e,0x00,0x00,
0x00,0x00,0x00,0x21,0x7f,0x01,0x00,0x00,
0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00,
0x00,0x22,0x49,0x49,0x49,0x36,0x00,0x00,
0x00,0x0c,0x14,0x24,0x7f,0x04,0x00,0x00,
0x00,0x72,0x51,0x51,0x51,0x4e,0x00,0x00,
0x00,0x3e,0x49,0x49,0x49,0x26,0x00,0x00,
0x00,0x40,0x40,0x40,0x4f,0x70,0x00,0x00,
0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00,
0x00,0x32,0x49,0x49,0x49,0x3e,0x00,0x00,
};
uchar Num_Index = 1,wei = 0,floor,i,mark,t;
void Delay()
{
uint x;
for( x = 0 ; x < 110 ; x++);
}
void LED_Init()
{
Delay();
t = _cror_(t,1);
P3 = t;
P0 = Table_OF_Digits[Num_Index * 8 +i];
if(++i == 8)
{
i = 0;
}
}
void LED_Screen_Display(int temp)
{
Delay();
t = _cror_(t,1);
P3 = t;
if( mark )
P0 = (Table_OF_Digits[Num_Index *8 +temp] >> wei) +
(Table_OF_Digits[(Num_Index - 1 )*8 +temp] << (8-wei)) ;
else
P0 = (Table_OF_Digits[Num_Index *8 +temp] << wei) +
(Table_OF_Digits[(Num_Index + 1 )*8 +temp] >> (8-wei)) ;
}
void Control_Move()
{
int temp1,temp2;
if(Num_Index > floor)
mark = 1;
else
mark = 0;
for( temp2 = 0 ;temp2 < 30 ; temp2 ++ )
{
for ( temp1 = 0 ;temp1 < 8 ; temp1 ++)
{
LED_Screen_Display(temp1);
}
}
if( ++wei == 8 )
{
wei =0;
if( mark )
if( (Num_Index --) == floor)
P1 = 0xFF;
else
P2 = 0xFF;
else
if( ++ Num_Index == floor)
P1 = 0xFF;
}
}
void ProcessKey()
{
switch(P1)
{
case 0xFE : P1 = 0xFE ; floor = 5;
if(Num_Index == floor)
P1 = 0xFF;
else
Control_Move();
break;
case 0xFD : P1 = 0xFD ; floor = 4;
if(Num_Index == floor)
P1 = 0xFF;
else
Control_Move();
break;
case 0xFB : P1 = 0xFB ; floor = 3;
if(Num_Index == floor)
P1 = 0xFF;
else
Control_Move();
break;
case 0xF7 : P1 = 0xF7 ; floor = 2;
if(Num_Index == floor)
P1 = 0xFF;
else
Control_Move();
break;
case 0xEF : P1 = 0xEF ; floor = 1;
if(Num_Index == floor)
P1 = 0xFF;
else
Control_Move();
break;
default : break;
}
}
void main()
{
t = 0x7F;
while(1)
{
if(P1 != 0xFF)
{
i = 0;
t = 0x7F;
ProcessKey();
}
else
{
LED_Init();
}
}
}
|