Specifications

mikroElektronika | Free Online Book | PIC Microcontrollers | Appendix B: Examples
movwf pclath_temp
banksel PORTB ; Selects bank containing PORTB
incf PORTB ; Increments register PORTB by 1
banksel INTCON ; Selects bank containing INTCON
bcf INTCON,TMR0IF ; Clears interrupt flag TMR0IF
movf pclath_temp,w ; PCLATH is given its original content
movwf PCLATH
movf status_temp,w ; STATUS is given its original content
movwf STATUS
swapf w_temp,f ; W is given its original content
swapf w_temp,w
bsf INTCON,GIE ; Global interrupt enabled
retfie ; Return from interrupt routine
;************************ MAIN PROGRAM **************************************
main ; Start of the main program
banksel ANSEL ; Bank containing register ANSEL
clrf ANSEL ; Clears registers ANSEL and ANSELH
clrf ANSELH ; All pins are digital
banksel TRISB ; Selects bank containing register TRISB
clrf TRISB ; All port B pins are configured as outputs
banksel OPTION_REG ; Bank containing register OPTION_REG
bcf OPTION_REG,T0CS ; TMR0 counts pulses from oscillator
bcf OPTION_REG,PSA ; Prescaler is assign to timer TMR0
bsf OPTION_REG,PS0 ; Prescaler rate is 1:256
bsf OPTION_REG,PS1
bsf OPTION_REG,PS2
banksel INTCON ; Bank containing register INTCON
bsf INTCON,TMR0IE ; TMR0 interrupt overflow enabled
bsf INTCON,GIE ; Global interrupt enabled
banksel PORTB ; Bank containing register PORTB
clrf PORTB ; Clears port B
loop
goto loop ; Remain here
end ; End of program
Example 5
Using subroutine, using push-buttons
In the previous examples the microcontroller executes the program without being influenced in any way its surrounding. In
practice, devices operating in this way are very rare (for example, simple neon signs). You guess, among other
components, input pins will also be used in this example. There is a schematic in the figure below, while the program is
on the next page. Everything is still very simple.
http://www.mikroe.com/en/books/picmcubook/appb/ (26 of 54)5/3/2009 11:36:02 AM