1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
;
; example.asm -- a simple LED flasher
;
;
; example source code for picasm by Timo Rossi
;
;
; define PIC device type
;
device pic16c84
;
; define config fuses
;
config CP=off,WDT=off,PWRT=off,OSC=hs
;
; include PIC register definitions, and some macros
;
include "pic16c84.h"
include "picmac.h"
;
; bit definitions for two LEDs connected to port A bits 0 and 1
; bit masks can be computed from bit numbers with the left shift operator.
;
A_LED1 equ 0
A_LED2 equ 1
;
; define some register file variables
;
org 0x0c
delay_cnt1 ds 1
delay_cnt2 ds 1
;
; code start
;
org 0
movlw 0xff
movwf PORTA ;initialize port A so that LEDs are off
bsf STATUS,RP0 ;register page 1
movlw ~((1<<A_LED1)|(1<<A_LED2)) ;LEDs as outputs,
movwf TRISA ;other PORTA pins as inputs
bcf STATUS,RP0 ;register page 0
main_loop
movlw 1<<A_LED1
xorwf PORTA,F ;toggle led1
clrw ;maximum delay length (256 counts)
call delay
clrw ;maximum delay length (256 counts)
call delay
movlw (1<<A_LED1)|(1<<A_LED2)
xorwf PORTA,F ;toggle both leds
clrw ;maximum delay length (256 counts)
call delay
goto main_loop
;
; delay subroutine
; input: delay count in W
;
; inner loop duration approx:
; 5*256+3 = 1283 cycles ->
; 1.28ms with 4MHz crystal (1MHz instruction time)
;
delay movwf delay_cnt1
clrf delay_cnt2
delay_a nop
nop
incfsz delay_cnt2,F
goto delay_a
decfsz delay_cnt1,F
goto delay_a
return
end
|