//------------------------------------------------------------------------
// CONVERSIONS IN BETWEEN HEX, BCD, ASCII.
//------------------------------------------------------------------------
void pk_unpk(volatile unsigned char pk,volatile unsigned char *unpk)
{
unpk[1] = ( (pk & 0x0F) | 0x30);
unpk[0] = (((pk & 0xF0) >> 4) | 0x30);
}
//------------------------------------------------------------------------
volatile unsigned char unpk_pk(volatile unsigned char *unpk)
{
return ( ((unpk[0] & 0x0F) << 4) | (unpk[1] & 0x0F) );
}
//------------------------------------------------------------------------
//volatile unsigned char hex_bcd(volatile unsigned char hex)
//{
// return ( ((hex / 16) * 10) + (hex % 16) );
//}
//------------------------------------------------------------------------
void hex_asc(volatile long hex, volatile unsigned char *asc, volatile unsigned char dig)
{
volatile unsigned char i;
asc[dig] = '\0';
for(i = dig ; i ; i--, hex /= 10)
{
asc[i-1] = (hex % 10) | 0x30;
}
}
//------------------------------------------------------------------------
volatile long asc_hex(volatile unsigned char *asc, volatile unsigned char dig)
{
volatile long hex;
volatile long j;
volatile unsigned char i;
for(i = dig, j = 1, hex = 0 ; i ; i--, j *= 10)
{
hex += (asc[i-1] & 0x0F) * j;
}
return (hex);
}
//------------------------------------------------------------------------
void rem_zeros(volatile unsigned char *asc, volatile unsigned char dig)
{
volatile unsigned char i;
for(i = 0 ; ((asc[i]=='0') && (i<dig)) ; i++)
{
asc[i] = ' ';
}
}
//------------------------------------------------------------------------