Hello, I am Working on a project (I call it Fusebox) and I have hit a brick programming wall. The device has a fairly simple function, but correct operation still eludes me. Being unable to find anything but the most basic documentation for this, I am at my wits end. (I have never attempted anything like this before) the device (a PIC16F684) is supposed to run off of the internal clock, wait for input from the OnOff pin, when it turns on, all of the 4 device pins should turn on also, when off, turn them off (Possibly with a delay), the pic is supposed to constantly measure the voltage on a pin (a car battery with a voltage divider) and sound a piezo buzzer if it drops below a value other specifics are commented in the code. If you are able, please help, this is my final project and I need to finish the software (to a functional point) ASAP so I can move on to designing the final project. Any help is appreciated! (BTW I have access to Picbasic pro and am coding in microcode studio) Here is the code:

'************************************************* *****************
'* Name : Fusebox.BAS *
'* Author : Jeff Munk *
'* Notice : Copyright (c) 2006 Jeff Munk *
'* : All Rights Reserved *
'* Date : 11/30/2006(started)-12/12/2006 *
'* Version : 1.0 *
'* Notes : This code should work with chips ohter than the *
'* : 16F684, but this is the chip originaly developed for*
'* : Hope this works... *
'************************************************* *****************

INCLUDE "modedefs.bas" ' Sets up serial communication for debugging

' Defines for setting up the ADC
DEFINE ADC_BITS 10 ' Sets the resolution of the ADC (10 Bits)
DEFINE ADC_CLOCK 3 ' Sets the clock to the internal R/C clock
DEFINE ADC_SAMPLEUS 50 ' Sets number of ms to allow clock to stabilize

' Sets ports to ADC
TRISA = %00000100 ' sets port0 as an input
ADCON0 = %00001001 ' sets port0 as an analog input (bit 4-2)
ANSEl = %00000100 ' sets porta.0 as an analog input
'-------------------------------------------------------------------------------

' Variables and constants
Serial var porta.0 ' Serial Port (for debugging)
Battery var porta.2 ' This is the ADC to be hooked to the referance voltage
Dev1 var porta.3 ' These Controlled
Dev2 var portc.5 ' Are Be
Dev3 var portc.4 ' The To
Dev4 var portc.3 ' Devices
Buzzer var portc.2 ' Warning buzzer
OnOff var portc.1 ' Input from Ignition (needs to be digital!!!!)
Cancel var portc.0 ' Gives the user ability to override lights-off
' command (Fusebox will continue to watch the
' voltage, upon voltage low, lights will be shut-down)
Btn var byte ' Button debounce var
Minimum con 1200 ' Min battery voltage (times 100 needs a 1/3
' voltage divider)
Voltage var word ' Variable to measure voltage
Delay var byte ' Variable to preform delay for certain events
'(like low voltage event)

'--------------------------------Prerequsites-----------------------------------

if onoff = 0 then
goto standby ' Checks for ignition status before boot
endif
' sets all circuts to on and reports via serial
High Dev1
serout serial, 0, ["1ST DEVICE ACTIVE"]
high Dev2
serout serial, 0, ["2ND DEVICE ACTIVE"]
high Dev3
serout serial, 0, ["3RD DEVICE ACTIVE"]
high Dev4
serout serial, 0, ["4TH DEVICE ACTIVE"]

'---------------------------------Main Program----------------------------------

Start:
if onoff = 0 then standby ' Checks for ignition status before program executes
gosub vm 'Measures voltage
if voltage < Minimum then
gosub battlow 'Battery low subroutine
endif
Vok: ' Voltage ok
goto start

'------------------------------Subroutines--------------------------------------
'------------------------------Voltage Measure------------------------------
' Measure voltage subroutine
VM:
adcin battery, Voltage ' Measures voltage
voltage = voltage * 300 ' Removes decimal
serout serial, 0, ["Battery voltage:", Voltage] 'Reports Voltage to computer
return
'================================================= ==============================
'------------------------------Battery Low--------------------------------------
' Action for a battery low event and engine crank handling
Battlow:
for Delay = 1 to 10 ' Delays warning for a time (for vehicle starting)
serout serial, 0, ["Battery Low! (possible alternator problem):", Voltage]
gosub vm
if voltage >= Minimum then vok 'If voltage is acceptable, move on
pause 500 'Wait for half a second
next Delay
SOUND buzzer,[100,10,50,10] ' Send 2 sounds consecutively to Buzzer
pause 1000 ' Wait for 1 second
SOUND Buzzer,[100,10,50,10] ' Send 2 sounds consecutively to Buzzer
return
'================================================= ==============================
'-----------------------------Silent Start--------------------------------------
' Activate lights without startup event
Startup:
serout serial, 0, ["Starting up!"]
high dev1
high Dev2
high dev3
high dev4
goto watch
'================================================= ==============================
'-----------------------------Shutdown-----------------------------------------
' Shutdown after battery low event (also used to deactivate override)
Shutdown:
SOUND buzzer,[200,10,10,10]
For Delay = 1 to 100
button cancel, 0, 255,0 , btn, 1, Watch
next
pause 30000
ImmediateShutdown:
serout serial, 0, ["Shutting down!"]
low dev1
low Dev2
low dev3
low dev4
goto standby
'================================================= ==============================
'-----------------------------Battery Monitor-----------------------------------
'Watches battery voltage, if it drops to a certain point, the devices are disconnected
Watch:
button cancel, 0, 255, 0, btn, 1, ImmediateShutdown
gosub VM ' Measures voltage
if voltage < Minimum then
low dev1
low Dev2
low dev3
low dev4
goto standby
endif
goto watch
'================================================= ==============================
'---------------------------------Standby---------------------------------------
' Waits for Ignition/Manual on event
Standby:
serout serial, 0, ["Standby!"]
button cancel, 0, 255,0 , btn, 1, Startup
if onoff = 1 then
high dev1
high Dev2
high dev3
high dev4
goto start
endif
nap 6
goto standby
'================================================= ==============================
'-------------------------------------End----------------------------------------