可实现位闪烁,无效零是否显示功能。
#define SMG_LAST_TIME 10
#define SMG_FLASH_TIME 100
typedef struct Smg_Ele
{
unsigned Bit0_Flash :1;
unsigned Bit1_Flash :1;
unsigned Bit2_Flash :1;
unsigned Bit3_Flash :1;
unsigned InvalidZero_NoDis :1;
unsigned int *Num ;
}Smg_Element;
Smg_Element Smg1={1,1,0,0,0,&Smg_Num};
void SmgDisplay(Smg_Element Smg_Temp)
{
static unsigned char Turn_Scan=0,Num_Scan=0,Temp[4];
static bit Zero_Valid;
switch(Turn_Scan)
{
case 0*SMG_LAST_TIME:
PORTD=0;
U5A=0;
U5B=0;
U5C=0;
if(Smg_Temp.Bit3_Flash==0)
Temp[3]=LED[*Smg_Temp.Num/1000];
else
{
if((Num_Scan%SMG_FLASH_TIME==0)&&(Num_Scan!=0))
{
if(Temp[3]!=0)
Temp[3]=0;
else
Temp[3]=LED[*Smg_Temp.Num/1000];
}
}
if(Smg_Temp.InvalidZero_NoDis)
{
Zero_Valid=0;
if(Temp[3]==LED[0])
{
Temp[3]=0;
}
else
{
Zero_Valid=1;
}
}
PORTD=Temp[3];
Turn_Scan++;
break;
case 1*SMG_LAST_TIME:
PORTD=0;
U5A=1;
U5B=0;
U5C=0;
if(Smg_Temp.Bit2_Flash==0)
Temp[2]=LED[*Smg_Temp.Num%1000/100];
else
{
if((Num_Scan%SMG_FLASH_TIME==0)&&(Num_Scan!=0))
{
if(Temp[2]!=0)
Temp[2]=0;
else
Temp[2]=LED[*Smg_Temp.Num%1000/100];
}
}
if(Smg_Temp.InvalidZero_NoDis)
{
if(Temp[2]==LED[0])
{
if(Zero_Valid)
{
Temp[2]=LED[0];
}
else
{
Temp[2]=0;
}
}
else
{
Zero_Valid=1;
}
}
PORTD=Temp[2];
Turn_Scan++;
break;
case 2*SMG_LAST_TIME:
PORTD=0;
U5A=0;
U5B=1;
U5C=0;
if(Smg_Temp.Bit1_Flash==0)
Temp[1]=LED[*Smg_Temp.Num%100/10];
else
{
if((Num_Scan%SMG_FLASH_TIME==0)&&(Num_Scan!=0))
{
if(Temp[1]!=0)
Temp[1]=0;
else
Temp[1]=LED[*Smg_Temp.Num%100/10];
}
}
if(Smg_Temp.InvalidZero_NoDis)
{
if(Temp[1]==LED[0])
{
if(Zero_Valid)
{
Temp[1]=LED[0];
}
else
{
Temp[1]=0;
}
}
else
{
Zero_Valid=1;
}
}
PORTD=Temp[1];
Turn_Scan++;
break;
case 3*SMG_LAST_TIME:
PORTD=0;
U5A=1;
U5B=1;
U5C=0;
if(Smg_Temp.Bit0_Flash==0)
Temp[0]=LED[*Smg_Temp.Num%10];
else
{
if((Num_Scan%SMG_FLASH_TIME==0)&&(Num_Scan!=0))
{
if(Temp[0]!=0)
Temp[0]=0;
else
Temp[0]=LED[*Smg_Temp.Num%10];
}
}
if(Smg_Temp.InvalidZero_NoDis)
{
if(Temp[0]==LED[0])
{
if(Zero_Valid)
{
Temp[0]=LED[0];
}
else
{
Temp[0]=0;
}
}
else
{
Zero_Valid=1;
}
}
PORTD=Temp[0];
Turn_Scan++;
break;
default:
Turn_Scan++;
if(Turn_Scan==4*SMG_LAST_TIME)
{
Num_Scan++;
Turn_Scan=0;
}
break;
}
} |