Specifications
mikroElektronika | Free Online Book | PIC Microcontrollers | Appendix B: Examples
At the beginning of the program, immediately upon defining variables, the microcontroller pins* are configured by using
registers TRISA and TRISB.
In the main program, one bit on port B is set first. Then the contents of this register is constantly moved by one place to
the left (instruction rlf PORTB). It gives us the impression that the lit LED diodes is moving. To make it visible, the whole
process must be slow enough. Press on the push-button "STOP" stops the movement and the program remains in loop3.
Delay is provided by means of a nested loop. This time, it is placed in a short subroutine "DELAY".
* It is not necessary for PORTA pins since they are automatically configured as inputs after every reset.
Example 5:
;****************************************************************************
; Header
;****************************************************************************
;************* DEFINING VARIABLES *******************************************
cblock 0x20 ; Block of variables starts at address 20h
counter1 ; Variable "counter1" at address 20h
counter2 ; Variable "counter2" at address 21h
endc ; Block of variables ends
;************************ MAIN PROGRAM **************************************
org 0x0000 ; Address of the first program instruction
banksel ANSEL ; Selects bank containing register ANSEL
clrf ANSEL ; Clears registers ANSEL and ANSELH to
clrf ANSELH ; configure all inputs as digital
banksel TRISB ; Selects bank containing register TRISB
clrf TRISB ; All port B pins are configured as outputs
movlw B'00000010'
http://www.mikroe.com/en/books/picmcubook/appb/ (27 of 54)5/3/2009 11:36:02 AM