24 September - 30 September 2012
Assembly
Programming using MPLAB development tools
(1) Setting
Hardware (PIC) and configuration
Example:
;////////////////////////////////////////////////////////////////////////////////////////
;Set PIC =
16F877
;Set PIC
configuration Setting
;////////////////////////////////////////////////////////////////////////////////////////
list p=pic16f877a ;MUST SET TO PIC MODEL IN USED
include p16f877a.inc
__config 0x1E72 ;CONFIGURATION
VALUE SETTING – refer to
;MPLAB
menu, configure and configuration
;bits
(value change on different setting)
errorlevel -302 ;Suppress bank warning
(2) Variable
Declaration
Example:
;////////////////////////////////////////////////////////////////////////////////////////
;Variable
declaration -- any variable to be use must be declared here before it can be
use in the main program
;////////////////////////////////////////////////////////////////////////////////////////
CBlock 0x20 ; Declaration
started at this address
N ; Delay registers.
Can be any name as long it’s not conflict with ; internal variable used in PIC
ROM memory.
N1
count1
counta
countb
countc
M0
ENDC ;By using CBlock function, we must
end it with ENDC
(3) Program
Start – Initialization Process
Example:
;////////////////////////////////////////////////////////////////////////////////////////
;Set IO
;Initialize LCD
;Display start up message to LCD for
intro
;Set default variable value
;////////////////////////////////////////////////////////////////////////////////////////
start call initports ; call subroutine
to initialize Input & Output setting
;(refer sample 3a)
call
INITLCD ; call subroutine
to initialize LCD (refer sample 3b)
call
clrscreen ; call subroutine
to Clear LCD SCREEN
call
DisReady ; call subroutine Display message to LCD during
;hardware
boot up.
call
visualdelay ;Delay routine use
to hold display on LCD
call
SECOND_1 ;2s delay before proceed
to the next instruction
call
SECOND_1
movlw
d'20' ;Set Default value
inside variable (depend on project
;function)
movwf
TSPD1
movlw
d'100'
movwf
TSPD2
bcf
PORTD,2 ;Turn
Off Motor
bcf
PORTD,3
bcf
PORTC,4




