list p=12f629, f=inhx32
#include <p12f629.inc>
__CONFIG _WDT_OFF&_INTRC_OSC_NOCLKOUT&_BODEN_ON&_CP_OFF&_PWRTE_ON
W_TEMP Equ 0x20
STATUS_TEMP Equ 0x21
Timebase3 Equ 0x22
Timebase23 Equ 0x23
ORG 0x000 ; processor reset vector
goto init ; go to beginning of program
ORG 0x004 ; interrupt vector location
;context save next.
MOVWF W_TEMP ;copy W to temp register,could be in either bank
SWAPF STATUS,W ;swap status to be saved into W
BCF STATUS,RP0 ;change to bank 0 regardless of current bank
MOVWF STATUS_TEMP ;save status to bank 0 register
bcf PIR1,0; clr Timer1 Int flag
movlw LOW(.51043)
movwf TMR1L
movlw HIGH(.51043)
movwf TMR1H
;do time base ticks
Incf Timebase3,f
Incf Timebase23,f
movlw .3 ; test for 1/3 of 69HZ (23Hz)
subwf Timebase23,w
skpz
goto Next_timebase
clrf Timebase23
movlw b'00100000'
xorwf GPIO,f ; toggle GPIO5 at 23Hz
Next_timebase;
movlw .23 ; test for 1/23 of 69Hz ( 3hz)
subwf Timebase3,w
skpz
goto ISRDONE
clrf Timebase3
movlw b'00010000'
xorwf GPIO,f; toggle GPIO4 at 3Hz
ISRDONE; restore context
SWAPF STATUS_TEMP,W;swap STATUS_TEMP register into W, sets bank to original state
MOVWF STATUS ;move W into STATUS register
SWAPF W_TEMP,F ;swap W_TEMP
SWAPF W_TEMP,W ;swap W_TEMP into W
retfie; return to main from interrupt
init:
call 0x3FF ; retrieve factory calibration value
bsf STATUS,RP0 ; set file register bank to 1
movwf OSCCAL ; update register with factory cal value
bcf STATUS,RP0 ; set file register bank to 0
CLRF GPIO ;Init GPIO
MOVLW 07h ;Set GP<2:0> to
MOVWF CMCON ;digital IO
BSF STATUS,RP0 ;Bank 1
;CLRF ANSEL ;Digital I/O
MOVLW b'00001111' ;Sets inputs and outputs
MOVWF TRISIO ;and set outputs
BCF STATUS,RP0 ;Bank 0
;Setup Tmr1 int
; 1000,000/ 69 = 14493 ticks req'd b4 interrupt for a 69Hz base.
; 65536-14493 = 51043 => preload this into TMR1L/H to cause 14493 ticks b4 interrupt.
movlw LOW(.51043)
movwf TMR1L
movlw HIGH(.51043)
movwf TMR1H
banksel PIE1
bsf PIE1,0 ; Timer1 interrupt enable
banksel INTCON
bsf INTCON,6 ;peripheral int. enable
bsf INTCON,7 ; gen. int enable.
movlw b'00000101' ; timer1 setup bits, with 1:1 prescale
movwf T1CON ; => start timer1 running on a 1,000,000 tick filling TMR1L, TMR1H (65536) b4 interrupt happens
Main;
goto Main; perpetual loop unless more functions needed.
END