I use the BANK option when declaring variables to ensure that the entire variable is in a known bank. Here is a sample.
Code:
'Variables
aflag var byte 'individual bits are used as flags.
bflag var byte BANK0'individual bits are used as flags.
cflag var byte ' individual bits are used as flags.
adval2 var word 'Value of pot on AN2
adval3 var word 'Value of pot on AN3
i var word BANK0'general purpose variable
pc var word BANK0 'pack counter
TMR0CNT var word BANK0 'number of times TMR0 has overflowed. used to update AD and LCD.
delay var word 'how long we wait to fire valve.
bc var word 'bad count. how many bad barcodes scanned
pct var word 'the percentage of bad scans to packages.
As for clearing the interrupt, I am using assembly language to do that.
Code:
BCF 0x0B,2 ;CLEAR INT FLAG
The BCF command is bit clear and 0B is the register that contains the interrupt while the ",2" is the actual bit. I clear the interrupt in the ISR so that there is no chance that it will cause a false trip by being read twice.
Please also look at how I set up registers and define aliases to register bits.
Code:
ADCON1 = %10000111 ' Set PORTA and PORTE digital and right justify result
TRISA = %11101100 '
TRISB = %11111001
TRISC = %10001000
OPTION_REG = %10100100 ' Set which edge RB0 int on (falling set).
INTCON = %11110000 ' Enable interrupt for Timer0 AND peripherals
PIE1 = %00100001 'Allow Timer1 & serial in to cause a periheral interrupt.
T1CON = %00000000 'Set Timer1 prescaler to 1
'Aliases for registers
INTF VAR INTCON.1 ' Alias INTF (RB0/INT external interrupt flag) This is RTS!!!
TMR0_EN VAR OPTION_REG.5' CLEAR TO START TIMER0 SET TO STOP.
TMR0IF VAR INTCON.2 ' TIMER0 INTERRUPT FLAG BIT.
TMR1_ON VAR T1CON.0 ' SET TO START TIIMER1 CLEAR TO STOP
TMR1IF VAR PIR1.0 ' TIMER1 INTERRUPT FLAG
RCIF VAR PIR1.5 ' Alias RCIF (USART Receive Interrupt Flag)
OERR VAR RCSTA.1 ' Alias OERR (USART Overrun Error Flag)
CREN VAR RCSTA.4 ' Alias CREN (USART Continuous Receive Enable)
I hope this is helpful. It really isn't that difficult to increment a variable in assemble that is what my original post showed with the TMR0CNT. I know that you can call a basic subroutine from inside your ISR but I question whether it defeats the purpose of the ISR. Perhaps not but I like to keep my interrupts as short as possible.
Have you considered turning off the interrupts and polling the interrupt bit. Do this in your basic loop and if it is set, clear it and increment your counters. If the loop is small enough you should be able to this almost as quickly as with an iterrupt. Just a thought as this will make for some simple code.
Regards,
Joe
Bookmarks