Specifications

mikroElektronika | Free Online Book | PIC Microcontrollers | Appendix A: Programming a Microcontroller
Click "Blink" to include the document Blink.asm into the project.
Program writing example
The program writing procedure cannot start until all previous operations have been performed. Program written below is a
simple illustration of project-making.
;Program to set port B pins to logic one (1).
;Version: 1.0 Date: April 25,2007 MCU: PIC16F887 Programmer: John Smith
;***** Declaration and configuration of the microcontroller *****
PROCESSOR 16f887
#include "p16f887.inc"
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
;***** Variable declaration *****
Cblock 0x20 ; First free RAM location
endc ; No variables
;;***** Program memory structure *****
ORG 0x00 ; Reset vector
goto Main ; After reset jump to this location
ORG 0x04 ; Interrupt vector
goto Main ; No interrupt routine
Main ; Start the program
banksel TRISB ; Select bank containing TRISB
clrf TRISB ; Port B is configured as output
banksel PORTB ; Select bank containing PORTB
movlw 0xff ; W=FF
movwf PORTB ; Move W to port B
Loop goto Loop ; Jump to label Loop
End
The program should be written to the ‘Blink.asm’ window or copied from disc by means of options copy/paste. When
copied, the program should be compiled into executable HEX format by using option PROJECT -> BUILD ALL. A new window
appears. The last sentence is the most important because it tells us whether compiling has succeeded or not. Clearly,
BUILD SUCCEEDED’ message means that no error occurred and compiling has been successfully done.
In case an error occurs, it is necessary to click twice on the message referring to it in the ‘Output’ window, which
automatically switch you over to assembly program, directly to the line where the error has occurred.
http://www.mikroe.com/en/books/picmcubook/appa/ (18 of 21)5/3/2009 11:35:35 AM