Home     Contact     Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science     RSS     Terms of services     Privacy policy  
   
 Home      Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science   



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
14 bit integer using a fixed point divisor and result
Author: Nikolai Golovchenko
This code was originally located @ http://www.piclist.com


Follow this link to go back

;-----------------------------------------------------------------------------
; Input:
; a1:a0 - 14 bit dividend (a0 - lower byte)
; b1:b0 - 15 bit divisor in 7Q8 format (b1 is integer, b0 is
; fractional)
; Output:
; c1:c0 - 15 bit quotient in 7Q8 format
;
; Size: 27 words
; Time: 2+3+3+15*(2+3+7+5)-1+2=264 instruction cycles
;
; March 13, 2001 by Nikolai Golovchenko
; March 14, 2001 optimized by Scott Dattalo
;-----------------------------------------------------------------------------
div_uint14_fxp7q8_fxp7q8

;left align the dividend
; (shift accumulator left 1 bit to get the first result bit weight
; equal to 128)
clrc
rlf a0, f
rlf a1, f ;carry is cleared here
;initialize registers
clrf c0 ;clear result - it will be used
clrf c1 ;to shift zeroes to dividend
bsf c0, 1 ;15 iterations
div_loop
rlf a0, f ;and shift out next bit of dividend
rlf a1, f ;to remainder

movf b0, w ;load w with lower divisor byte
skpnc ;if remainder positive - subtract,
goto div_add ;if negative - add
;subract
subwf a0, f
movf b1, w
skpc
incfsz b1, w
subwf a1, f
goto div_next
div_add
;add
addwf a0, f
movf b1, w
skpnc
incfsz b1, w
addwf a1, f
div_next
;here carry has a new result bit
rlf c0, f ;shift in next result bit
rlf c1, f
skpc
goto div_loop
return
;-----------------------------------------------------------------------------

Follow this link to go back






delicious
digg
reddit this Reddit this
Faves



 HOT in heaven!