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
32 bit and detect zero Author: Dmitry Kiryashov, Rich Leggitt, Andrew Warren, Scott Dattalo This code was originally located @ http://www.piclist.com
Follow this link to go back
; given address of 32 bit little-endian counter in W,
; increment or decrement the counter and return Z set if zero
;Inc32z
;From Dmitry Kiryashov
inc32z:
movwf FSR
clrz
incfsz INDF,F
return
incfsz FSR,F
incfsz INDF,F
return
incfsz FSR,F
incfsz INDF,F
return
incfsz FSR,F
incf INDF,F
return
;Dec32z
;From Rich Leggitt, Andrew Warren, and Dmitry Kiryashov
; 99.2% of the time, this takes 10 cycles w/call
dec32z:
movwf FSR
decfsz INDF,F
goto dec32nz
incf FSR,F
movfw INDF
incf FSR,F
iorwf INDF,W
incf FSR,F
iorwf INDF,W ;get _Z finally
return
dec32nz:
clrz ;set _Z=0
incfsz INDF,W
return
incfsz FSR,F ;doesn't corrupt _Z
decfsz INDF,F
incfsz INDF,W
return
incfsz FSR,F ;...
decfsz INDF,F
incfsz INDF,W
return
incfsz FSR,F ;...
decfsz INDF,F
return
return
;for the 18cxxx instruction set.
;From Scott Dattalo
; 10-16 cycles
dec32:
movwf FSR0L ; the fsr's (three of them) on the 18cxxx
clrf FSR0H ; are 16bits wide
decf POSTINC0,F,1 ;Indirect access that increments the fsr.
bnz dec32nz ;this was bz
;The lsbyte is zero , so we don't need to propogate the borrow
;but we need to see if the higher bytes are zero.
movf POSTINC0,w,1 ;The first byte is zero
iorwf POSTINC0,w,1 ;check the next three
iorwf POSTINC0,w,1
return
dec32nz
;decf on the 18cxxx parts affects C
skpnc
return
decf POSINC0,F,1
skpc
decf POSTINC0,F,1
skpc
decf POSTINC0,F,1
clrz ;was setz
return |
Follow this link to go back
|
HOT in heaven!
|
|