That mistake makes me feel really stupid. Thanks for catching it, Henrick.
However, I made both calls to the INCLUDE files GOSUB and made sure there was a RETURN at the end, and I still am seeing an interrupt from the INT2 every 3-4 seconds.
From previous discussions with Darrel Taylor he said users should not mess with the INTCON register because the DT_INTS takes care of it. But as was pointed out it appears that the continuous interrupts are occurring because evidently the interrupts are enabled during the subroutine being executed in the INCLUDE file.
Am attaching my most recent code in hopes someone can advise me what is causing the continuous interrupts from INT2. Will also attach applicable INCLUDE file in another following post.
Code:
'----------------[ Define Include Files & special DEFINES ]--------------
INCLUDE "DS1337_Setup.inc" ' Include subroutine that setsup DS1337
INCLUDE "DS1337_SRF02.inc" ' Include subroutine as ISR for Alarm handler
Include "Modedefs.Bas"
INCLUDE "DT_INTS-18.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ' Include if using PBP high priority interrupts
INCLUDE "ALLDIGITAL.pbp" ' Sets all registers for digital ops.
DEFINE OSC 16
DEFINE I2C_SLOW 1 ' Set i2c to the standard speed
DEFINE I2C_HOLD 1 ' Enable recieving i2c device to pause communication
'--------------[ Declare Variables, Aliases & Constants ]----------------
' Variables, Constants & Aliases for Pins
' Global variables, constants & aliases used in both Main program and
' INCLUDE files that are declared in INCLUDE files are commented out here
'Alarm1 VAR PORTB.2 ' Alarm1 input from DS1337 INTA (pin-3)
'Alarm2 VAR PORTB.3 ' Alarm2 input from DS1337 INTB (pin-7)
'ext_pwr VAR PORTC.6 ' Alias to control power to Ultrasonic sensor
'rng0 VAR w0.Byte0 ' LSB of range measurement when right justified
'rng1 VAR w0.byte1 ' MSB of range measurement when right justified
SCL VAR PORTB.1 ' I2C clock pin
SDA VAR PORTB.0 ' I2C data pin
'w0 var word ' W0 is the word value to store the range data
rtcdevice CON $D0 ' Device address for DS1337 Real-time-clock (RTC)
'srfdevice CON $E0 ' Device address for SRF02 ultrasonic range finder
' Alias of Clock register addresses
ContReg CON $0E ' CONTROL register address
StatusReg CON $0F ' STATUS register address
RTC_INT_FLG VAR INTCON3.1 'Alias for RB2 INTA interrupt flag from RTC
' RTC Address definitions
' Time/Date
'SecReg CON $00 ' seconds address (00 - 59)
' MSB of SecReg must be set to a 0 to enable RTC
'MinReg CON $01 ' minutes address (00 - 59)
'HrReg CON $02 ' hours address (01 - 12) or (00 - 23)
'DayReg CON $03 ' day address (1 - 7)
'DateReg CON $04 ' date address (01 - 28/29, 30, 31)
'MonReg CON $05 ' month address (01 - 12)
'YearReg CON $06 ' year address (00 - 99)
' Alarm 1 Address definitions
'Alm1sec CON $07 ' Alarm 1 seconds address (00 - 59)
'Alm1min CON $08 ' Alarm 1 minutes address (00 - 59)
'Alm1hr CON $09 ' Alarm 1 hours address (01 - 12) or (00 - 23)
'Alm1Day CON $0A ' Alarm 1 day address (1 - 7)
' Alarm 2 Address definitions
'Alm2min CON $0B ' Alarm 2 minutes address (00 - 59)
'Alm2hr CON $0C ' Alarm 2 hours address (01 - 12) or (00 - 23)
'Alm2Day CON $0D ' Alarm 2 day address (1 - 7)
' Clock Variables
'sec VAR BYTE ' seconds
'MINs VAR BYTE ' minutes
'hr VAR BYTE ' hours
'day VAR BYTE ' day
'date VAR BYTE ' date
'mon VAR BYTE ' month
'yr VAR BYTE ' year
' ALARM1 VARIABLES
'A1sec VAR BYTE ' seconds
'A1MINs VAR BYTE ' minutes
'A1hr VAR BYTE ' hours
'A1day VAR BYTE ' day
' ALARM2 VARIABLES
'A2MINs VAR BYTE ' minutes
'A2hr VAR BYTE ' hours
'A2day VAR BYTE ' day
GOSUB SetTimeAndDate ' Set current time & alarm settings by
' calling routine in INCLUDE file
'----------------------[ SETUP FOR INTERRUPTS ]-------------------------
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
;INT_Handler USB_Handler
INT_Handler INT2_INT, _AlarmHdlr, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
@ INT_ENABLE INT2_INT ; enable external (INT) interrupts
' Per DT, DT_INTS already takes care of setting INTCON and RCON registers
' but this doesn't work unles INTCON2 set per below:
'INTCON.7 = 1 ' Set Global Interrupt Enable bit
INTCON2 = %00000000 ' Set INT2 for falling edge (Bit4-low)
' on RTC's interrupt.
'INTCON3 = %10010000 ' Set INT2 high priority (Bit7-high), enable INT2
' (Bit4-high)
' Initialize Hardware
' ===================
'Set registers
'OSCCON.7 = 0 ' Clear IDLEN bit to allow SLEEP mode
TRISA = 0 ' PORTA all outputs for LCD use
TRISB =%00001100 ' RB2 & RB3 set as RTC Alarm1 & Alarm2 inputs
TRISC = 0
TRISD = 0
TRISE = 0
'--------------------[ Begin Main Program Loop ]------------------------
Main:
PAUSE 500 ' ?? For some reason this 100 millisec delay is required
' to keep RTC interrupts from happening every 3-4 secs ??
Low PORTC.0 ' Turn off Test LED while in Main loop
' Place code here to put MCU and Ultrasonic Ranger in SLEEP mode.
' while waiting for clock interrupt to wakeup from SLEEP mode.
GoTo Main ' Endless Loop waiting for interrupt
End ' Safety measure to insure program stops if reaches here
'-------------------[ Begin Interrupt Handlers }-----------------------
AlarmHdlr:
GoSUB Alarm ' Call Alarm handler subroutine in INCLUDE file
@ INT_RETURN
END
Bookmarks