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
Binary to ASCII, 16 bit to 5 digits (1 at a time) no temp register
Author: Rich Leggitt
This code was originally located @ http://www.piclist.com


Follow this link to go back

; given 16 bit data in HI and LO, extract decimal digits
; requires one Output register called temp, HI and LO are destroyed.
; 42 instructions and less than 269 (or 252 with known_zero) instructions executed
clrf temp
goto $+2 ;[NG] was: skip
sub10k incf temp,f
movlw 10000 & 255
subwf LO,f

;Scott Dattalo says:
;If you have a ram location that's known to be zero, then
;the following [the IF] can be replaced with [the ELSE]
IFNDEF known_zero
movlw 10000 >> 8
skpc
movlw (10000>>8)+1 ;[NG] was: addlw 1 ; this sucks
subwf HI,f
ELSE
rlf known_zero,W
sublw (10000>>8)+1 ;bugfix by Dmitry Kiryashov and Nikolai Golovchenko
subwf Hi,F
ENDIF
bc sub10k ;9*7=63/8*7=56 inst in loop for 60900 (worst)
output(temp);

movlw 10
movwf temp
add1K decf temp,f
movlw 1000 & 255
addwf LO,f

;Scott Dattalo says:
;If you have a ram location that's known to be zero, then
;the following [the IF] can be replaced with [the ELSE]
IFNDEF known_zero
movlw 1000 >> 8
skpnc
movlw (1000>>8)+1 ;[NG] was: addlw 1
addwf HI,f
ELSE
rlf known_zero,w
addlw 1000 >> 8
addwf HI,f
ENDIF
bnc add1k ;9*10=90/8*10=80 inst in loop for 60900
output(temp);

;Scott takes over here
clrf temp
movlw 100
goto $+2 ;[NG] was: skip
sub100
incf temp,f
subwf LO,f
skpnc ;[NG] was: skpc
goto sub100

decf HI,f
btfss HI,7 ;Check msb instead of carry for underflow.
goto sub100 ;4 inst per loop to 200 then 7 per loop to 900.
;Total 64(?) in loop for worst case

;at this point, HI = 0xff, and 0 <= LO <= 99

output(temp)

movlw 10
movwf temp
add10 decf temp,f
addwf LO,f
bnc add10 ;40 inst in loop for worst case.
output(temp);
output(LO);
return

Follow this link to go back






delicious
digg
reddit this Reddit this
Faves



 HOT in heaven!