I've inserted comments where I added a few things. Let us know if this
version works.
Code:
;************************************************* ********
; Define statements.
' Now you know for sure what these are set for
@ device pic16F877A, hs_osc, wdt_off, lvp_off, protect_off
' Potential problem below unless you're disabling WDT in config fuse
' (like above) you do not want to use this define. PBP needs to insert
' CLRWDT commands throughout your code to make sure the WDT does
' not cause a device reset
define NO_CLRWDT 1 ;Don't insert CLRWDTs
define OSC 20 ;every MPU used is 20mhz
'Port operation configurations
CMCON0 = %00000111 'Port A all digital
VRCON = %00000000 'CVref turned off
' Added this to disable A/D. Now you can use ports A/E for digital I/O
ADCON1 = 7
OPTION_REG = %10000111 'Disable PORTA pullups, set TMR0 scaler to 1:256
; Program Variables
Loop VAR BYTE ;general loop counter for LED flashing
Outp CON 0
Inp CON 1
'Assign Ports to simple name
LowVoltage VAR PortA.0 'Battery low voltage detection port
ReedSwitchState var PORTA.1 'Reed Switch ON and OFF state line
LED VAR PORTA.2 'Turn LED ON and OFF
HoldTxON VAR PORTC.0 'Hold Tx ON when water contacts activated
Tx_Data VAR PORTC.1 'Transmit Data Line
Tx1_Enable VAR PORTC.2 'Transmit 121.5Mhz Line
Tx2_Enable VAR PORTC.3 'Tranmit 156MHz Line
MotorControl_1 VAR PORTC.4 'Activate Release Mechanism
MotorControl_2 VAR PORTC.5 'Activate Latch Mechanism
'Initialize port states
TrisA.0=Inp 'set batt low voltage detection to input
TrisA.1=Inp 'set Reed switch state to input
TrisA.2=Outp 'set led transmission to output
TrisC.0=Outp 'set Hold Tx Line ON to output
TrisC.1=Outp 'set Transmit data line to output
TrisC.2=Outp 'set Transmit @121.5 to output
TrisC.3=Outp 'set Transmit @156 to output
TrisC.4=Outp 'set Motorcontrol_1 to output
TrisC.5=Outp 'set Motorcontrol_2 to output
'Goto Main
;************************************************* ******************************
Main:
low HoldTxON ; Initialize by clearing all the outputs
low LED
low Tx_Data
Low Tx1_Enable
low Tx2_Enable
Low MotorControl_1
LOW MotorControl_2
GOSUB Lowvoltagecheck ' <-- problem area here. When program flow returns
' from Lowvoltagecheck, it lands on END and the PIC
' enters a continuous sleep loop
GOTO Main ' <-- this fixes the problem
end
;************************************************* ******************************
; Subroutine to check for battery voltage at the beginning and end of
; transmission flashing to signify low voltage or high voltage
LowVoltageCheck:
If lowVoltage = 1 then ; If the battery voltage is OK
high led ; turn on the LED for 5 seconds
pause 5000
LOw LEd
else
for loop = 1 to 10 ; If the battery voltage is low
high led ; Flash the LED 10 times
Pause 500 ; at a rate discernable from the
low led ; transmit LED flash rate
PAUSE 500 ' <-- added this pause so you can see the LED blink
next
endif
return
If this "doesn't" work, make sure you have a pull-up on /MCLR to Vcc, at least
a 0.1uF cap between PIC Vcc/GND pins, and a clean/stable power supply.
Bookmarks