w2drz
Joined: 27 Dec 2006 Posts: 55 Location: Western New York - USA
|
16bit bin to BCD routine including combining to a 2 byte out |
Posted: Fri Dec 29, 2006 8:00 am |
|
|
Hi,
Here is a corrected rtn,
I forgot to clean up the listing before I sent it out.
Just so there is no confusion, works just as I needed for my program.
Using CCS 3.249
This version work great,
at this time have not seen problems that are in prior versions.
Thank you for the help to finish the project here.
tom
long Dig_0, Dig_1, Dig_2, Dig_3, Dig_4;
void bin_to_Dig(long bin_inp)
{ // This is for VK3UM program
long temp; // 16 bit binary to BCD 5 byte
int nibh;
int nibl;
temp = bin_inp / 18.2041667; // make into binary degrees value
Dig_4 = temp/10000;
temp = temp - (Dig_4 * 10000);
Dig_3 = temp/1000;
temp = temp - (Dig_3 * 1000);
Dig_2 = temp/100;
temp = temp - (Dig_2 * 100);
Dig_1 = temp/10;
temp = temp - (Dig_1 * 10);
Dig_0 = temp;
nibh = Dig_1; // MSB BYTE make ready to send out This is the 2nd digit
nibl = Dig_2; // LSB BYTE make ready to send out This is the 1st digit
CountMSB = (nibl|(nibh<<4));
nibh = Dig_3; // MSB BYTE make ready to send out This is the 3rd digit
nibl = Dig_0; // LSB BYTE make ready to send out is .1 value
CountLSB = (nibl|(nibh<<4));
}
|
|