Microchip Technology DM164130-9 User Manual

Page of 101
Lessons
 2012 Microchip Technology Inc.
DS41628B-page 43
3.2.6
Assembly
3.2.6.1
ENHANCED MID-RANGE
EXAMPLE 3-4: 
This starts a comment. Any text on this line following the semicolon is ignored by the 
assembler. Be sure to place lots of these in your code for readability.
The p16F1829.inc defines all of the PIC device-specific SFRs as well as other 
memory addresses. This should always be the first line of your program after any 
header comments and before the __CONFIG directive.
This sets the processor’s Configuration bits. Before this directive is used, the processor 
must be declared! Refer to the PIC16F1829 data sheet for the description of each 
Configuration Word used here. The most important of these is the ‘MCLRE_OFF’, 
which turns off master clear on RA3.  
This suppresses the printing of the warning: “MESSAGE 302 – Operand not in Bank 0, 
check to ensure bank bits are correct”.
This sets the program origin for subsequent code at the address xx. If no org is 
specified, code generation will begin at address 0. 
This is a label. Labels are assigned the same memory address as the opcode immedi-
ately following the label. Labels can, and should be, used in your code to specify the 
destination for call, goto and branch instructions. 
#include <p16F1829.inc>
     __CONFIG _CONFIG1, (_FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & 
_CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF);
     __CONFIG _CONFIG2, (_WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _LVP_OFF);
    errorlevel -302   ;supress the 'not in bank0' warning
    ORG 0
Start:
     banksel TRISC     ; select bank1
     bcf     TRISC,0   ; make IO Pin C0 an output
     banksel LATC      ; select bank2
     clrf    LATC      ; init the LATCH by turning off everything
     bsf     LATC,0    ; turn on LED C0 (DS1)
     goto    $         ; sit here forever!
    end
;
;
#include <p16xxxx.inc>
__CONFIG
Errorlevel -302
Org xx
Start:
Banksel TRISC