#include <p12F683.inc>
	bsf STATUS,RP0		;Select register bank 1
	clrf ANSEL		;Clear analog control register
	movlw 77h
	movwf OSCCON		;Oscillator config
	clrf PCON		;Power config	
	movlw 1fh
	movwf TRISIO		;Pin I/O config
	clrf WPU		;Disable input pullups
	bcf STATUS,RP0		;Select register bank 0
WATCH
	btfsc GPIO,3		;Check status of injector
	goto WATCH		;Go check again if injector is off
	bsf GPIO,5		;Injector is on, turn on Output to MPG computer
	clrf 20h		;Clear counter low byte
	movlw 1h		
	movwf 21h		;Preload counter high byte with 1  
OPEN				
	addwf 20h,1		;Add 1 to counter low byte
	btfsc STATUS,C		;Check counter low byte for overflow
	incf 21h,1		;Add 1 to counter high byte if low byte has overflowed
	btfss GPIO,3		;Check status of injector
	goto OPEN		;Go back to top of loop if injector is still open
	movlw 7h		;Load working register with counter decrement value
CLOSED	
	subwf 20h,1		;Subtract decrement value from counter
	btfss STATUS,C		;Check counter low byte for underflow
	decfsz 21h,1		;Subtract 1 from counter high byte if low byte has underflowed 
	goto CLOSED		;Return to top of loop if high byte isn't zero  
	bcf GPIO,5		;Turn off output to MPG computer
	goto WATCH		;Go to the beginning and wait for another injector pulse
	end

