|
char BCD2SevenSeg(char BCD)
{if(BCD==0)return zero;
if(BCD==1)return one;
if(BCD==2)return two;
if(BCD==3)return three;
if(BCD==4)return four;
if(BCD==5)return five;
if(BCD==6)return six;
if(BCD==7)return seven;
if(BCD==8)return eight;
if(BCD==9)return nine;
return 128;
}
void Bin2BCD(unsigned char *Ptr, unsigned int Data)
{// Begin of Bin2Dec
char Counter;
union { unsigned long ALL; int Half_ALL[2];
struct { unsigned int Shifter :16;
unsigned int Numeral_1:4;
unsigned int Numeral_2:4;
unsigned int Numeral_3:4;
unsigned int Numeral_4:4;
} NUMERALS;
} COMMON;
// Action
Counter=16;
COMMON.Half_ALL[0]=Data;
COMMON.Half_ALL[1]=0;
while (Counter)
{Counter--;
if (COMMON.NUMERALS.Numeral_1 > 4) COMMON.Half_ALL[1] += 3;
if (COMMON.NUMERALS.Numeral_2 > 4) COMMON.Half_ALL[1] += 48;
if (COMMON.NUMERALS.Numeral_3 > 4) COMMON.Half_ALL[1] += 768;
if (COMMON.NUMERALS.Numeral_4 > 4) COMMON.Half_ALL[1] +=12288;
COMMON.ALL <<=1;
}
// End of Bin2Dec
*Ptr=BCD2SevenSeg(COMMON.NUMERALS.Numeral_1);
Ptr++; *Ptr=BCD2SevenSeg(COMMON.NUMERALS.Numeral_2);
Ptr++; *Ptr=BCD2SevenSeg(COMMON.NUMERALS.Numeral_3);
Ptr++; *Ptr=BCD2SevenSeg(COMMON.NUMERALS.Numeral_4);
return;
}
E-mail: info@telesys.ru