Specifications

mikroElektronika | Free Online Book | PIC Microcontrollers | Appendix B: Examples
16-bit timer TMR1 is used in this example. By occupying its registers TMR1L and TMR1H, an interrupt occurs and the
number on port B is incremented. This has already been seen in the previous examples. The difference is in the program
delay which is a bit longer this time because the prescaler rate is 1:8.
Example 8:
;*************************** Header *****************************************
;************* DEFINING VARIABLES *******************************************
cblock 0x20 ; Block of variables starts at address 20h
w_temp ; Variable at address 20h
pclath_temp ; Variable at address 21h
status_temp ; Variable at address 22h
endc
;************************ PROGRAM START ************************
org 0x0000 ; Address of the first program instruction
goto main ; Jump to label "main"
;************************ INTERRUPT ROUTINE **********************************
org 0x0004 ; Interrupt vector
movwf w_temp ; Save register W
movf STATUS ; Save register STATUS
movwf status_temp
movf PCLATH ; Save register PCLATH
movwf pclath_temp
banksel PORTB ; Selects bank containing PORTB
incf PORTB ; Register PORTB is incremented by 1
movf pclath_temp,w ; PCLATH is given its original content
movwf PCLATH
http://www.mikroe.com/en/books/picmcubook/appb/ (33 of 54)5/3/2009 11:36:02 AM