Quote Originally Posted by Bruce View Post
"Make sure your path statement includes information on where you have MPLAB installed, or modify the 16F690.INC file to point directly to it."
I guess when I upgraded to PB Pro and installed it, MPLAB must have ended up in a different place. Thanks for catching this...I could have spent a long time looking and not thinking of this.
Now I have a different problem. Although I was going to try to do the counting with a NonInterrupt version of using the TMR0 overflow counter as you described above, I discovered as I progressed on my app design that I really need to do the counting with an interrupt and also another interrupt for checking on an external switch closure. I therefore am trying to use the below code where I have the interrupt handler doing two IF..THEN checks of the flag bits to handle either the TMR0 overflow while using RA2 input to TMR0 as switch for counting, or the RABIE on-change-interrupt for the RA3 input from a switch closure to ground. The TMR0 interrupt works in this code, however, the RABIE on-change-interrupt does not. I can't figure out why. Can you see whay the RABIE isn't working??
Code:
' -----[ Device Declaration ]----------------------------------------------
'
@ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF
 
' -----[ Variables & Aliases Intitialization ]-----------------------------
'
led1  VAR PORTC.0   ' Set RC0 as LED indicator of valve open..water flowing
led2  VAR PORTC.1   ' Set RC1 as LED indicator of low battery
valve VAR PORTC.3   ' Set RC3 as valve solenoid open/close command
low_bat VAR PortA.0 ' Set RA0 as battery low power monitor
meter VAR PORTA.2   ' Set RA2 as input for Hall Sensor meter pulse Interrupt
flush VAR PORTA.3   ' Set RA3 as input for sensing flush switch closure Int
bat_mon VAR Byte    ' bat_mon value when Vtrh multiplied by low_bat


' -----[ Constants Initialization ]----------------------------------------
'
 k             CON 10   ' Calibration factor for flow meter...# pulses per gal
 i             VAR Byte ' Index used in Gallon counter loop
 Vthr          CON 4    ' Low Battery Monitor threshold
 
' -----[ Initialization ]--------------------------------------------------
'
'EEPROM PRESETS
'DATA @0,0

'OSC DEFINE
'DEFINE OSC 4

' Setup Timer0 as an 8-bit counter with the clock input on RA2.
' 1:1 TMR0 prescaler
' TMR0 counts on high-to-low transitions
  OPTION_REG = %00111000
  
'Register Settings
Init:
TRISA = %11111111   ' Set all PORTA pins to inputs...RA0, RA2 & RA3 are used
TRISB = %00000000   ' Set all PORTB and PORTC pins to outputs
TRISC = %00000000
PORTC = %00000000	' Pre-set PORTC pins low, turning LEDs off
TMR0 = 256-K        ' Preload TMR0 to overflow after k counts

'A/D & Comparators disabled
  ADCON0 = %01110000  ' Set PORTA to digital I/O & FRC (clock derived from a 
  ADCON1 = %00000000  ' dedicated internal oscillator)
  ANSEL=0           ' Set PortA to digital I/O
  ANSELH=0          ' Analog module disabled
  CM1CON0=0
  CM2CON0=0
TRISC.3 = 0       ' Set RC3 as output port for valve latching solenoid control
Low Valve         ' Initialize RC3 (valve) at Low value
TRISA.2 = 1       ' Set RA2 as input port for clock to TMR0
TRISA.3 = 1       ' Set RA3 as input port for sensing METER switch closure
High meter        ' Initialize RA2 (meter) at High value for METER pulse inputs
                  ' RA2 = TMR0 clock input for simulated meter pulse inputs
High flush        ' Initialize RA3 (flush) at High value for flush interrupt  
  
'Interrupts Settings
FLUSH_INT_FLAG VAR INTCON.0  ' RA3 (FLUSH) On-change-interrupt flag bit
TMRO_INT_FLAG VAR INTCON.2   ' Timer0 overflow flag bit 
INTCON = %10101000           ' Enable global, TMR0 & RABIE (RA3 on-change-INT)
IOCA = %00000000             ' Enable RA3 as on-change-INT

' -----[ Main Code ]-------------------------------------------------------
'Set INT Handler
ON INTERRUPT GOTO Int_handler   

'Start...normal code here
MAIN:
    PORTC = %00000000   ' Turn all LEDs off
    PAUSE 1
    'SLEEP = 65,535     ' Put MC in Sleep state at power up 
    ' Microcontroller is in Sleep State waiting for external FLUSH Interrupt
  GOTO Main        ' Loop to Main to wait for next Flush interrupt

  DISABLE 
Int_handler:
  IF FLUSH_INT_FLAG = 1 Then  ' Interrupt was from RA3 on change    
    DEFINE WRITE_INT 1
    write  9, flush     ' Write RA3 (FLUSH) value during testing
    PULSOUT valve,1000  ' Generate required 10 msec pulse to RC3 to open valve
    High led1           ' Light indicator that valve is open & water flowing
    Low low_bat         ' Simulate battery monitor input is low  
    'Put code here to Wakeup the Microcontroller
    
    ' Put code here to start a timer to run for 50 secs as a fail safe 
    ' to prevent overflow of toilet tank in case of sensor failure.
        'Goto Shutvalve
    High flush             ' Clear the interrupt
    FLUSH_INT_FLAG = 0     ' Clear interrupt flag
  Endif
  IF TMRO_INT_FLAG = 1 then  ' Interrupt was a TMR0 overflow..volume reached
    PULSOUT valve,6000  ' Generate required 20 msec pulse to RC3..close valve  
    WRITE 5, TMR0      ' Write TMR0 value..remove comment for test only
    bat_mon = low_bat * Vthr
    Write 7, bat_mon    ' Remove comment for test only  
    If bat_mon < Vthr Then
        'Light the low battery monitor light
        HIGH led2
    ENDIF
    TMR0 = 256-k              ' Reload TMR0 to overflow after k counts
    TMRO_INT_FLAG = 0         ' Clear overflow flag
  ENDIF
  LOW led1
  Low led2
  RESUME
  ENABLE   

    ' If the user program ends by getting to the last statement of the program
    ' at an END instruction, the MCU will SLEEP and await a wakeup.
END