;//PREPROCESSOR ===============================================|---|
LIST p=12F683
include "P12F683.INC"
__CONFIG _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT
errorlevel -302
errorlevel -312
EXTERN adc
EXTERN EEPROMRW
EXTERN Interrupt_on_change
delA equ 20h ;
delB equ 21h ;
temp1 equ 22h ;
temp2 equ 23h ;
pushes equ 24h
flashes equ 25h
Stat_sav equ 26h
W_sav equ 27h
;****************************************************************
;Equates
;****************************************************************
status equ 0x03
rp1 equ 0x06
rp0 equ 0x05
status equ 03h
option_reg equ 81h
;bits
rp0 equ 5 ;bit 5 of the status register
;****************************************************************
;Beginning of program
;****************************************************************
org 0x00
cblock 0x20
d1
d2
d3
d4
count1 ; for 5 minute delay
SW1 ; Switch #1
SW2 ; Switch #2
TMR ; timer value in minutes
endc
GOTO SetUp
nop
ORG 4 ;interrupts always vector to here
GOTO isr
nop
SetUp bsf status, rp0 ;Bank 1
movlw b'10010100' ;Set TRIS GP0,1,5 out GP2,4 input
movwf TRISIO ;
bcf option_reg,7 ;pull-ups enabled
MOVLW b'00000100' ;prescaler (1:32)
movwf option_reg ;TMR0 interrupts = 6 mS apart
BCF STATUS, RP0 ;bank 0
movlw 07h ;turn off Comparator ports
movwf CMCON0 ;must be placed in bank 0
Clrf TMR0 ;clear Timer0 register
clrf flashes
incf flashes
movlw 0xA0 ;set GIE <7> and T0IE <5>
movwf INTCON ;enable Interrupts
goto Main
isr MOVWF W_sav ;first save critical registers
SWAPF STATUS,W
BCF STATUS,RP0 ;change to bank 0
MOVWF Stat_sav
btfss GPIO,2 ;test switchA
call switchPressed
BCF INTCON,T0IF
BCF INTCON,INTF
SWAPF Stat_sav,W
MOVWF STATUS ; restore status
SWAPF W_sav,F
SWAPF W_sav,W ; restore w without changing status
RETFIE
;********************
;* Delays *
;********************
_10mS movlw 0Ah
movwf delB
nop
decfsz delA,f
goto $-2
decfsz delB,f
goto $-4
retlw 00
_250mS nop
decfsz delA,f
goto $-2
decfsz delB,f
goto $-4
retlw 00
; Delay = 300 seconds
; Clock frequency = 4 MHz
; Actual delay = 300 seconds = 300000000 cycles
; Error = 0 %
DelayW movwf count1
Delay5
;299999995 cycles
movlw 0x54
movwf d1
movlw 0xA1
movwf d2
movlw 0xFD
movwf d3
movlw 0x02
movwf d4
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto $+2
decfsz d4, f
goto Delay_0
decfsz count1 ,f
goto Delay5
retlw 0x00
;****************************
;* Sub Routines *
;****************************
switchPressed
movf flashes,W
movwf temp1
movlw 06
xorwf temp1 ;if flashes=6
btfss status,Z ;z=1 if flashes=6
goto $+4
movlw 1
movwf flashes
goto $-8
bsf GPIO,0 ;turn on LED
call _250mS
bcf GPIO,0 ;turn off LED
call _250mS
decfsz temp1,f
goto $-5
incf flashes,f
btfss GPIO,2 ;loop until SwA is released
goto $-1
retlw 00
;************************
;* Main *
;************************
Main
btfss GPIO,2 ;test switchA
call SwA_Pressed
btfss GPIO,3 ;test switchB
call SwB_Pressed
goto $-4
SwA_Pressed
return
goto Main
SwB_Pressed
return
goto Main
;************************
;*EEPROM *
;************************
org 2100h
END