I'm having a hard time again...
My interrupts seem to be taking over, and my main loop never gets executed. 
The project I'm working on controls a few simple outputs based on some user input , some machine inputs, and the real time from a DS1302.
The user input comes from the "touch sensors" available in the 16F727. The time (minutes and seconds only) and other numeric info are displayed on a 4 digit, 7-segment LED display.
The touch sensors use Interrupts based on TMR1 and TMR0.
I had much of my program working until I added the touch sensor routine, then everything went to hell....
I've trimmed my code back to just the touch sensor and RTC code trying to get it to work. The problem is that the interrupts seem to "take over the show" and my main loop never gets executed.
This bit of test code should display the "ones of minutes" and the tens and ones of seconds on a LED display.
When a sensor button is touched, the number of the button pressed should be momentarily displayed on the 4th digit of the display.
The problem is that while the touch sensors work fine and the appropriate number is displayed when touched, the time is *not* displayed because the main loop is never executed. If I disable the interrupts so that the touch sensors don't work, then the main loop is executed and the time is displayed just fine.
Why does the interrupt routine highjack the show and keep the main loop from executing?
Here's the bit of test code that I'm working with... any suggestions would be a appreciated.
It's a little too big, so I'll split it into 2 posts....
Code:
'****************************************************************
Include "MODEDEFS.BAS" ' Include Shiftin/out modes
INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
DEFINE LCD_DREG PORTD ' Set LCD Data port
DEFINE LCD_DBIT 4 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTC ' Set LCD Register Select port
DEFINE LCD_RSBIT 5 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTC ' Set LCD Enable port
DEFINE LCD_EBIT 6 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE ADC_BITS 8 ' Set number of bits in ADC result
DEFINE ADC_CLOCK 3 ' Set clock source for ADC (rc = 3)
DEFINE ADC_SAMPLEUS 100 ' Set ADC sampling time in microseconds
define I2C_SCLOUT 1 ' Set I2C Clock to drive high instead of needing pullup
DEFINE CCP2_REG PORTC 'Hpwm2 port
DEFINE CCP2_BIT 1 'Hpwm2 bit
DEFINE OSC 16 '16 MHz
OSCCON = %00110000 'set OSC to 16 mHz.
@ __config _CONFIG1, _DEBUG_OFF & _PLL_EN & _BORV_2_5 & _BOR_ON & _CP_OFF & _MCLRE_OFF & _PWRT_EN & _WDT_ON & _INTOSCIO
@ __config _CONFIG2, _VCAP_RA6
TRISA= %00000000 'Set 'em all to outputs
TRISB= %11111111 'all input
TRISC= %00011000 'Set portC all outputs except C.3 and C.4
TRISD= %00000000 'Set portD all outputs
TRISE= %00000000 'Set portE all outputs
ANSELA= %00000000 ' Set all pins to digital
ANSELB= %11111111 ' all analog
ANSELD= %00000000 ' Set all pins to digital
ANSELE= %00000000 ' Set all pins to digital
CPSCON0 = %10001101 'Cap sense on, high range oscillator
'---------VARIABLES-----------------------------------
'LED Driver (CAT4016) Variables-----------------------
LEDData var byte
numeral var byte
LEDCounter var byte
digit1 var byte : digit1=0
digit2 var byte : digit2=0
digit3 var byte : digit3=0
digit4 var byte : digit4=0
'DS1302 RTC Variables-----------------------
rtcyear var byte
rtcday var byte
rtcmonth var byte
rtcdate var byte
rtchr var byte
rtcmin var byte
rtcsec var byte
rtccontrol var byte
mathtemp var Byte 'For doing BCD to Decimal conversion
'Touch sensor related Variables----------------------
index var byte : index=0 'for the CSM buttons
timercount var word[6] : timercount = 0 ' raw count from TMR1, for each channel
timerave var word[6] : timerave = 0 ' long term average of timercount, for each channel
AvgCount var byte : AvgCount = 32 'number of samples to average
delay var word : delay = 0 ' to delay startup until the timers have stabilized.
'---------I/O PINS-----------------------------------
'Alias pins - DS1302---------------------------------
RST var PORTE.2 '1302 CS
IO var PORTE.1 '1302 I/O
SCLK var PORTE.0 '1302 Clock
'Alias pins - EEPROM---------------------------------
SDA var PORTC.4 'EEPROM data
SCL var PORTC.3 'EEPROM Clock
'Alias pins - LED display----------------------------
S_IN var PORTA.3 'CAT4016 data
LEDCLK var PORTA.2 'CAt4016 clock
BLANK var PORTC.1 'CAT4016 blanking line
LATCH VAR PORTA.0 'Cat4016 Latch
'Initialize variables--------------------------------
hpwm 2,100,1000 'set LED brightness
timerave = 2000 'preset the timer average to a "close" value
'-----------------------------------------------------------------
'Set initial time (this can be removed in final version)
'rtcyear = $09 'Set Year
'rtcday = $1 'Set Day
'rtcmonth = $1 'Set Month
'rtcdate = $1 'Set Date of month
'rtchr = $1 'Set Hour
'rtcmin = $1 'Set Minutes
'rtcsec = $1 'Set Seconds
'Gosub settime ' DO IT! - Set the time
'--------------------------------------------------------------------------------
'initialize the DS1302 and set the trickle charge rate
Low SCLK
low rst ' Reset RTC
high rst ' RTC Ready for transfer
Shiftout IO, SCLK, LSBFIRST, [$8e, 0] ' Enable write
low rst
high rst
Shiftout IO, SCLK, LSBFIRST, [$90, %10101011] ' Set charger on and to "2 diodes, 8Kohm"
Low RST ' Reset RTC
pause 5
' -----Grab the time out of the RTC and display it--------------------------
gosub gettime
gosub sortdigits
pause 1000
'-----Set up Interrrupts--------------------------------------------
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1GATE_INT, _CheckCount, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
@ INT_ENABLE TMR1GATE_INT ; enable Timer1 gate interrupt
'----- Timer Setup------------------------------------------------
OPTION_REG = %11010110 'setup source and prescaler for TMR0
INTCON.2 = 0; // clear TMR0 interrupt flag
INTCON.5 = 1; // enable TMR0 interrupt
T1CON = %11000101 'Timer clock source=CAPOSC, prescale=1:1, dedicated OSC disabled, no external clock synchronize, timer on
T1GCON = %11100001 'Timer1 gate init/ Toggle Mode
PIR1.7 = 0 'Clear Gate Interrupt Flag
'----------JUST GET IT GOING-------------------
GOTO Main 'skip the subroutines and get on with it.
Finish below....
Bookmarks