You are on page 1of 3

__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _RC_OSC

;
'__CONFIG' directive is used to embed configuration data within .asm file.
;
The lables following the directive are located in the respective .inc file.
;
See respective data sheet for additional information on configuration
word.

VARIABLE DEFINITIONS

w_temp
status_temp

EQU
EQU

mark30
post80
sec5

0x0C
0x0D

; variable used for context saving


; variable used for context saving

equ
equ
equ

0x10
0x11
0x12

Start Place
ORG
goto
ORG

0x000
start
0x004

; processor reset vector


; go to beginning of program
; interrupt vector location

;**********************************************************************
;SubRoutine
Init

CLRF STATUS
; Bank0
CLRF PORTA
; Initialize PORTB by clearing
output
CLRF PORTB
; data latches
BSF STATUS, RP0
; Select Bank1
MOVLW
b'00000'
; Select PortA Ports
MOVWF
TRISA
;
MOVLW
b'00000000'
; Select PortB Ports
MOVWF
TRISB
;
BCF STATUS, RP0
; Bank0
CLRWDT
; Clear WDT and prescaler
BSF STATUS, RP0
; Bank1
MOVLW
b'00000111'
; Select TMR0, new prescale
MOVWF
OPTION_REG
; value and clock source
BCF STATUS, RP0
; Bank0
movlw
movwf

d'30'
mark30

; sets up marker
;

movlw

d'80'

; sets up first postscaler

movwf

post80

movlw
movwf

d'5'
sec5

;
; sets up five second counter
;

retlw 0 ;Skips Init Second Time


;**********************************************************************
;Program Start
start call

Init

main movfw
subwf
number in

mark30
TMR0, w

; takes the number out of Mark30


; subtracts this number from the
; TMR0, leaving the result

in the working
; register (and leaving
TMR0 unchanged)
btfss
the result

STATUS, Z

; tests the Zero Flag - skip if set, i.e. if


; is zero it will skip the next

instruction
goto

main

; if the result isn't zero, it loops back to

'Loop'
;***
movlw
into the working
addwf
decfsz

d'30'

; moves the decimal number 30

mark30, f

; register and then adds it to 'Mark30'

post80, f

; decrements 'Post80', and skips the next


; instruction if the result is

zero
goto

main

; if the result isn't zero, it loops back to

'Loop'
; one second has now passed
;***
movlw
movwf

d'80'
post80

; resets postscaler
;

;***
comf

PORTA, f

; toggles LED state

decfsz
goto

sec5, f
main

; has five seconds passed?


; no, loop back

;***
movlw
movwf
goto

END

d'5'
sec5
main

; resets 5 second counter


;
; loops back to start

You might also like