| 
 All about PIC microcontrollers
 
 Within these pages, you can find many useful pieces of code mostly in assembly for the Microchip PIC micro controller family. A lot of people have spend many hours trying to put the bits and bytes together. If the code is NOT written by a member of the PCB Heaven community, then a link will be added above the code with the original website that this code was found.
 Because the code is copied to our servers, you should know that:
 
 
 
The responsible web master of the website that the code is taken, has been informed and he has agreed to copy the codeAll emails from the above contact have been kept as records but due to personal privacy cannot be shown in public. The author of the code is always clearly indicated above the code. In some cases the author is unknown. If you happen to be the author of the code or you know the person who wrote it, please inform us by email and it will be added ASAP. We would personally like to send the credits to all the people that managed to write some very interesting code and publish it, and special thanx to the people that originally hosted those code snippets and gave us the permission to copy them.
 
 
 View code
 Binary to BCD unpacked 17 bit to 5 full digits
 Author: Mike Mansheim of Graco, Inc.
 This code was originally located @ http://www.piclist.com
 
 
 Follow this link to go back
 
 
 | unsigned int  TenK, Thou, Hund, Tens, Ones; unsigned int  num[3];
 
 void BIN2DEC(void)
 {
 // operates on global variables:
 // set num[0]-[3] (lo-hi) before calling
 // returns with TenK...Ones set from 0-9
 
 unsigned int a0, a1, a2, a3, a4;
 unsigned int t1, t2, t3;			// scratchpad variables
 
 // isolate the 4 bit nibbles
 // for the purposes of this routine, a4 can be only 0 or 1
 a4 = num[2];
 a3 = num[1] / 16;
 a2 = num[1] & 0b00001111;
 a1 = num[0] / 16;
 a0 = num[0] & 0b00001111;
 
 // calculate the decimal digits (the b_i's are expressed here
 // as TenK...Ones, as in the original)
 // all are negative, except TenK
 t1 = 4 * a4;
 Ones = a0 - t1 - 20;
 t2 = 2 * a1;
 Tens = t1 + t2 - 198;
 t3 = 2 * a2;
 Hund = a3 + t3 - 140;
 t3 = t3 * 2;              // now = 4 * a2
 t2 = t2 * 2;              // now = 4 * a1
 Ones = Ones - t3 - t2;
 t3 = t3 + a2 + a2;        // now = 6 * a2
 Tens = Tens + t3;         // Tens done
 t1 = t1 + a4;             // now = 5 * a4
 Hund = Hund + t1;
 t3 = 4 * a3;
 Thou = t1 + t3 - 144;     // Thou done
 Ones = Ones - t3;         // Ones done
 TenK = t1 + a4 + 16;      // Tenk done
 
 // "normalize" the digits - this asm code was
 // copied directly from the original
 #asm
 movlw   0x0A
 Lb1:
 addwf   Ones,f
 decf    Tens,f
 btfss   3,0
 goto   Lb1
 Lb2:
 addwf   Tens,f
 decf    Hund,f
 btfss   3,0
 goto   Lb2
 Lb3:
 addwf   Hund,f
 decf    Thou,f
 btfss   3,0
 goto   Lb3
 Lb4:
 addwf   Thou,f
 decf    TenK,f
 btfss   3,0
 goto   Lb4
 #endasm
 }
 | 
 Follow this link to go back
 
 
 
 
 
 
 | 
 
 
 
 |  HOT in heaven! 
 
   | 
 
 |