;******************************************************************
;* *
;* Filename: Ignition 10F200 v1.asm *
;* Author: Mike McLaren, K8LH (k8lh@arrl.net) *
;* Date: 30-Sep-09 *
;* *
;* *
;* 10F200 Ignition Switch Experiment *
;* *
;* *
;* MPLab: 8.14 (tabs=8) *
;* MPAsm: 5.21 *
;* *
;******************************************************************
include "p10f200.inc"
list st=off
__CONFIG _MCLRE_OFF & _CP_OFF & _WDT_OFF
radix dec
;--< hardware >----------------------------------------------------
#define ig_pin GPIO,0 ; GP0 = ignition relay
#define st_pin GPIO,1 ; GP1 = starter relay
#define spkr GPIO,2 ; GP2 = speaker
;--< variables >---------------------------------------------------
cblock 0x10
temp ; delay subsystem
swnew ;
swold ; switch state latch
tmr1sec ; 1 second timer
tmr25ms ; 25 msec timer
endc
;--< macros >------------------------------------------------------
clock equ 4 ; 4-MHz clock
usecs equ clock/4 ; cycles/usec multiplier
inDlyCy macro pCycles ; 0..1027 cycle range
local loop ;
if pCycles > 3
movlw pCycles/4 ;
loop movwf temp ; 4-cycle loop
decfsz temp,W ;
goto loop ;
endif
if pCycles%4 >= 2
goto $+1 ;
endif
if pCycles&1 == 1
nop ;
endif
endm
;******************************************************************
;
; main program
;
org 0x000
start
movwf OSCCAL ;
movlw b'10011110' ; 10011110
; 1-------, IOC off
; -0------, weak pullups on
; --0-----, T0CS source Fosc/4
; ---1----, T0SE edge hi>lo
; ----1---, PSA prescale WDT
; -----110, PS prescaler 64
option ;
movlw b'00001000' ;
tris GPIO ; GP3 input, all others outputs
clrf swold ; clear switch state latch
;
; swnew __---__---__---------__---__----------____
; swold ___---__---__---------__---__----------___
; gp0 _____-----_____________------------------- 'ignition'
; gp1 ________________________________------____ 'starter'
;
sample
movlw 25 ; prep 25-msec counter/timer
movwf tmr25ms ;
inDlyCy(1000*usecs-4) ; delay 1 msec minus 4 cycles
decfsz tmr25ms,W ; 25 msec sample interval?
goto sample+1 ; no, branch, else
comf GPIO,W ; sample active lo switches
movwf swnew ; save it
newpress
btfsc swnew,3 ; if swnew == 1
btfsc swold,3 ; if swold == 0
goto newrelease ;
bsf swold,3 ; update 'swold'
movlw 1000/25 ;
movwf tmr1sec ; start 1 second timer
newrelease
btfss swnew,3 ; if swnew == 0
btfss swold,3 ; if swold == 1
goto timeout ;
bcf swold,3 ; update 'swold'
movf GPIO,W ;
andlw b'11111101' ; turn GP1 'starter' off
movwf GPIO ;
movf tmr1sec,W ; a "long" press?
bz timeout ; yes, branch (done), else
clrf tmr1sec ; turn timer off and
movf GPIO,W ;
xorlw b'00000001' ; toggle GP0 'ignition' pin
movwf GPIO ;
timeout
movf tmr1sec,W ; 1 second timer running?
bz sample ; no, branch, else
decfsz tmr1sec,F ; is it timed out?
goto sample ; no, branch, else
movf GPIO,W ;
btfsc ig_pin ; ignition on? no, skip, else
iorlw b'00000010' ; turn GP1 'starter' pin on
movwf GPIO ;
goto sample ;
;******************************************************************
end