Specifications
mikroElektronika | Free Online Book | PIC Microcontrollers | Appendix B: Examples
HIcnt
LOcnt
LOOPcnt
cnt
endc ; End of block of variables
;**********************************************************************
ORG 0x000 ; Reset vector
nop
goto main ; Go to program start (label "main")
;**********************************************************************
include "pause.inc"
include "button.inc"
;**********************************************************************
main
banksel ANSEL ; Selects bank containing ANSEL
clrf ANSEL ; All pins are digital
clrf ANSELH
banksel TRISB
bsf TRISA, 0
bsf TRISA, 1
clrf TRISB
banksel PORTB
clrf cnt
Loop
button PORT,0,0,Increment
button PORT,1,0,Decrement
goto Loop
Increment
incf cnt, f
movf cnt, w
movwf PORTB
goto Loop
Decrement
decf cnt, f
movf cnt, w
movwf PORTB
goto Loop
end ; End of program
Macro "pausems"
;**********************************************************************
pausems MACRO arg1
local Loop1
local dechi
local Delay1ms
local Loop2
local End
movlw High(arg1) ; Higher byte of argument is moved
; to HIcnt
movwf HIcnt
movlw Low(arg1) ; Lower byte of argument is moved
; to LOcnt
movwf LOcnt
Loop1
movf LOcnt, f ; Decrements HIcnt and LOcnt while
btfsc STATUS, Z ; needed and calls subroutine Delay1ms
goto dechi
call Delay1ms
decf LOcnt, f
goto Loop1
dechi
movf HIcnt, f
http://www.mikroe.com/en/books/picmcubook/appb/ (31 of 54)5/3/2009 11:36:02 AM