Specifications

mikroElektronika | Free Online Book | PIC Microcontrollers | Appendix A: Programming a Microcontroller
EXAMPLE OF HOW TO WRITE A PROGRAM
The following example illustrates what a simple program written in assembly language looks like.
Apart from the regular rules of assembly language, there are also some unwritten rules which should be observed during
program writing. One of them is to write in a few words at the beginning of a program what the program’s name is, what it
is used for, version, release date, type of the microcontroller it is written for and the name of the programmer. Since this
information is not of importance for the assembler, it is written as a comment which always starts with semicolon ‘;’ and
can be written in a new line or immediately after a command.
After writing this general comment, it is time to select the microcontroller by using directive PROCESSOR. This directive is
followed by another one used to include all the definitions of the PIC16F887 microcontroller’s internal registers in the
program. These definitions are nothing but the ability to address port B and other registers as PORTB instead of 06h, which
makes the program clearer and more legible.
In order that the microcontroller will operate properly, a several parameters such as the type of oscillator, state of the
watch-dog and internal reset circuit must be defined. It is done by utilizing the following directive:
_CONFIG _CP_OFF&_WDT_OFF&PWRTE_ON&XT_OSC
When all necessary elements are defined, the process of program writing can start. First and foremost, it is necessary to
specify the address from which the microcontroller starts when the power goes on (org 0x00) as well as the address from
which the program proceeds with execution if an interrupt occurs (org 0x04). Since this program is very simple, it is
http://www.mikroe.com/en/books/picmcubook/appa/ (6 of 21)5/3/2009 11:35:35 AM