Specifications
mikroElektronika | Free Online Book | PIC Microcontrollers | Appendix B: Examples
Example 6:
;****************************************************************************
; Header
;****************************************************************************
;************* DEFINING VARIABLES *******************************************
TEST equ B'00000101' ; Binary number 00000101 = TEST
#define RELAY PORTD,3 ; Pin PORTD,3 = RELAY
;************************ MAIN PROGRAM **************************************
org 0x0000 ; Address of the first program instruction
banksel TRISB ; Selects bank containing register TRISB
clrf TRISB ; All port B pins are configured as outputs
clrf TRISD ; All port D pins are configured as outputs
movlw B'00010000' ; This number is written to W register
movwf TRISA ; Only the forth pin of port A is input
banksel OPTION_REG ; Bank containing OPTION_REG register
bsf OPTION_REG,T0CS ; Pin RA4 is supplied with pulses
bsf OPTION_REG,PSA ; Prescaler rate is 1:1
banksel PORTB ; Selects bank containing PORTB register
clrf TMR0 ; Clears timer register
bcf PORTD,3 ; Pin PORTD,3 = 0
loop
movfw TMR0 ; Timer register is moved to W register
movwf PORTB ; W register is moved to PORTB
xorlw TEST ; Operation exclusive OR between
http://www.mikroe.com/en/books/picmcubook/appb/ (29 of 54)5/3/2009 11:36:02 AM