I'm not having any luck using the ACD of a 16F877A.
Maybe I should have given the thing a better output than a flashing light,
but I'm pretty sure I'm getting a zero reading every time.
The circuit always waits for the timeout to stop the starter motor.
if anyone likes to take a look...
Cheers, Art.Code:' Remote start controller ' for '92 Toyota Surf ' DEFINE OSC 04 'hardware is using a 4MHz crystal DEFINE ADC_BITS 10 '10 bit ADC for 16F877A ' adcon1.0 = 1 : adcon1.3 = 1 'set porte pins digital trise.0 = 1 : trise.2 = 1 'set porte pins as inputs trisb.1 = 1 : trisb.2 = 1 'set portb pins as inputs trisd.2 = 1 : trisd.3 = 1 'set portd pin as input trisa.0 = 1 : trisa.1 = 1 'set all analogue channels as inputs trisa.2 = 1 : trisa.3 = 1 ' ADCON1 = 0 'set analogue inputs ADCON1.7 = 1 'right justified for 10 bit ADC ' seq var byte 'run sequence flag timea var byte 'time lsd timeb var byte 'time msd timec var byte 'timer timed var byte 'timer timee var byte 'timer xtimed var byte 'timer xtimee var byte 'timer debouncea var byte 'input a debounce counter debounceb var byte 'input b debounce counter debouncec var byte 'input c debounce counter srelay var byte 'starter relay status irelay var byte 'ignition relay status bvoltage var word 'battery voltage value avoltage var word 'running voltage value ttiimmee var byte 'timer held var bit 'button held flags xheld var bit ' rlock var bit ' gosub reset ' ' ' main: if timeb > $04 then ' ' if srelay = 0 then ' high portb.5 'led on else ' low portb.5 'led off endif endif ' pauseus 500 'delay if irelay = 0 then ' low portb.5 'led off endif ' ' timea = timea + 1 'increment timer if timea = $FF then ' timeb = timeb + 1 ' timea = 0 ' endif ' ' if timeb = $06 then 'check timer if timec < $F0 then ' timec = timec + 1 ' endif ' timeb = 0 'reset timer endif ' ' ' ' if debouncea < $F9 then 'increment debounce a timer debouncea = debouncea + 1 ' endif ' if debounceb < $F9 then 'increment debounce b timer debounceb = debounceb + 1 ' endif ' if debouncec < $F9 then 'increment debounce c timer debouncec = debouncec + 1 ' endif ' if debouncea = $F9 then ' if portb.1 = 0 then 'ignition off button, yellow wire seq = 0 'end sequence irelay = 0 'turn relays off srelay = 0 ' gosub reset ' endif ' endif ' ' if debounceb = $F9 then ' if portb.2 = 0 then 'violet wire... unlock button debounceb = $F8 ' held = 1 ' timed = timed + 1 ' if timed = $FE then ' timed = 0 ' timee = timee + 1 ' endif ' endif ' if portb.2 = 1 then ' held = 0 ' timed = 0 ' timee = 0 ' debounceb = 0 ' endif ' if timee > $09 then 'unlock button held delay define here timed = 0 ' timee = 0 ' debounceb = 0 ' held = 0 ' seq = 1 'activate sequence timec = 0 ' endif ' endif ' ' if debouncec = $F9 then ' if portd.2 = 0 then 'blue wire... lock button debouncec = $F8 ' xheld = 1 ' xtimed = xtimed + 1 ' if xtimed = $FE then ' xtimed = 0 ' xtimee = xtimee + 1 ' endif ' endif ' if portd.2 = 1 then ' xheld = 0 ' xtimed = 0 ' xtimee = 0 ' debouncec = 0 ' endif ' if xtimee > $09 then 'lock button held delay define here xtimed = 0 ' xtimee = 0 ' debouncec = 0 ' seq = 0 'end sequence rlock = 0 ' irelay = 0 'turn relays off srelay = 0 ' gosub reset ' endif ' endif ' ' if seq = 1 then ' irelay = 1 'turn on ignition power relay if timec = 02 then ' srelay = 1 'turn on starter motor relay endif ' ' if srelay = 1 then ' ' ttiimmee = ttiimmee + 1 'increment timer if ttiimmee = 70 then 'time between samples is set here ADCIN 0, avoltage 'read running voltage if avoltage > bvoltage + 1 then 'detect vehicle start srelay = 0 'turn off starter motor endif ' ttiimmee = 0 ' bvoltage = avoltage 'remember old voltage reading endif ' ' if portb.2 = 0 then ' timec = $03 ' timeb = $02 ' rlock = 0 ' srelay = 0 ' low portd.1 ' pause 1000 ' endif ' endif ' ' if timec = $03 then 'starter motor on time defined here if timeb = $03 then ' rlock = 0 ' srelay = 0 'turn off starter motor endif ' endif ' ' endif ' ' if seq = 0 then irelay = 0 'turn off ignition power relay ' ' if srelay = 0 then 'set starter relay state to starter relay flag rlock = 0 ' low portd.1 else high portd.1 endif ' if irelay = 0 then 'set ignition relay state to ignition relay flag low portd.0 else high portd.0 endif ' goto main 'repeat main loop ' ' reset: srelay = 0 : irelay = 0 'reset relay status for start program timea = 0 : timeb = 0 'reset timer variables for start program timec = 0 : timed = 0 ' timee = 0 : ttiimmee = 0 ' xtimed = 0 : xtimee = 0 ' debouncea = 0 : debounceb = 0 'reset debounce timers debouncec = 0 ' held = 0 : xheld = 0 'reset flag avoltage = 0 : rlock = 0 ' bvoltage = 65533 ' low portd.1 : low portd.0 'start with relays off hardware controlled seq = 0 ' return ' ' ' ' ' '




Bookmarks