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 code
- All 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
8 bit to a percentage Author: Scott Dattalo - Nikolai Golovchenko This code was originally located @ http://www.piclist.com
Follow this link to go back
;*******************************************************************
;scale_hex2dec
; The purpose of this routine is to scale a hexadecimal byte to a
;decimal byte. In other words, if 'h' is a hexadecimal byte then
;the scaled decimal equivalent 'd' is:
; d = h * 100/256.
;Note that this can be simplified:
; d = h * 25 / 64 = h * 0x19 / 0x40
;Multiplication and division can be expressed in terms of shift lefts
;and shift rights:
; d = [ (h<<4) + (h<<3) + h ] >> 6
;The program divides the shifting as follows so that carries are
automatically
;taken care of:
; d = (h + (h + (h>>3)) >> 1) >> 2
;
;Inputs: W - should contain 'h', the hexadecimal value to be scaled
;Outputs: W - The scaled hexadecimal value is returned in W
;Memory: temp
;Calls: none
scale_hex2dec
MOVWF temp ;Hex value is in W.
CLRC ;Clear the Carry bit so it doesn't affect RRF
;Nikolai Golovchenko says: For better precision (especially for higher
;values of input byte), one more term should be added, so that
;d = (((h >> 3 + h) >> 3 + h) >> 1 + h) >> 2 = h * (1/4 + 1/8 + 1/64 + 1/512)
;
;This adds only 6 cycles, and reduces errors from 51 to 11 cases per
;all combinations of input (in both routines absolute errors are small,+-1).
;
; RRF temp,F
; CLRC
; RRF temp,F
; CLRC
; RRF temp,F
; ADDWF temp, F
RRF temp,F
CLRC
RRF temp,F
CLRC
RRF temp,F ;temp = h>>3
ADDWF temp,F ;temp = h + (h>>3)
RRF temp,F ;temp = (h + (h>>3)) >> 1
ADDWF temp,F ;temp = h + ((h + (h>>3)) >> 1)
RRF temp,F
CLRC
RRF temp,W ;d = W = (h + (h + (h>>3)) >> 1) >> 2
RETURN |
Follow this link to go back
|
HOT in heaven!
|
|