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: Nikolai Golovchenko
This code was originally located @ http://www.piclist.com


Follow this link to go back

;Total execution time:
;worst case: 47 + 66 + 58 + 39 + 2 = 213 cycles(with known zero)
;worst case: 53 + 73 + 58 + 39 + 2 = 226 cycles(without known zero)

;Code size: 68

clrf temp
sub30k
movlw 3
addwf temp, f
movlw low(30000)
subwf Lo, f

IFNDEF known_zero
movlw high(30000)
skpc
movlw high(30000) + 1
subwf Hi, f
ELSE
rlf known_zero, w
sublw high(30000) + 1
subwf Hi, f
ENDIF
skpnc
goto sub30k

add10k
decf temp, f
movlw low(10000)
addwf Lo, f

IFNDEF known_zero
movlw high(10000)
skpnc
movlw high(10000) + 1
addwf Hi, f
ELSE
rlf known_zero, w
addlw high(10000)
addwf Hi, f
ENDIF
skpc
goto add10k
; Output(temp) ;output temp = TenK
;worst case: 10 * 3 + 9 * 3 - 1 = 47 (with known zero)
;worst case: 11 * 3 + 10 * 3 - 1 = 53 (without known zero)

clrf temp
sub3k
movlw 3
addwf temp, f
movlw low(3000)
subwf Lo, f
IFNDEF known_zero
movlw high(3000)
skpc
movlw high(3000) + 1
subwf Hi, f
ELSE
rlf known_zero, w
sublw high(3000) + 1
subwf Hi, f
ENDIF
skpnc
goto sub3k
add1k
decf temp, f
movlw low(1000)
addwf Lo, f

IFNDEF known_zero
movlw high(1000)
skpnc
movlw high(1000) + 1
addwf Hi, f
ELSE
rlf known_zero, w
addlw high(1000)
addwf Hi, f
ENDIF
skpc
goto add1k
; Output(temp) ;output temp = Thou
;worst case: 10 * 4 + 9 * 3 - 1 = 66 (with known zero)
;worst case: 11 * 4 + 10 * 3 - 1 = 73 (without known zero)

clrf temp
sub300
movlw 3
addwf temp, f
movlw low(300)
subwf Lo, f
IFNDEF known_zero
movlw high(300)
skpc
movlw high(300) + 1
subwf Hi, f
ELSE
rlf known_zero, w
sublw high(300) + 1
subwf Hi, f
ENDIF
skpnc
goto sub300
movlw 100
add100
decf temp, f
addwf Lo, f
skpc
goto add100
incf Hi, f
btfsc Hi, 7
goto add100
; Output(temp) ;output temp = Hund
;worst case: 10 * 4 + 5 * 3 + 3 = 59

clrf temp
movlw 30
sub30
incf temp, f
subwf Lo, f
skpnc
goto sub30
movfw temp
rlf temp, f
addwf temp, f
movlw 10
add10
decf temp, f
addwf Lo, f
skpc
goto add10
; Output(temp) ;output temp = Tens
;worst case: 5 * 4 + 5 * 3 + 4 = 39

; Output(Lo) ;output temp = Ones

Follow this link to go back






delicious
digg
reddit this Reddit this
Faves



 HOT in heaven!