View previous topic :: View next topic |
Author |
Message |
hmmpic
Joined: 09 Mar 2010 Posts: 314 Location: Denmark
|
interrupt_active and INT_RA0... |
Posted: Sun Apr 12, 2015 1:04 pm |
|
|
Hi
Compiler 5.044 / PIC:16F1825
When using interrupt on change, and use more then one, I test for the right one in the interrupt. The interrupt_active(INT_RA0); return wrong.
Is it me or the compiler?
Test code:
Code: |
#include "16F1825.h"
/*All is test code for understand what is going on*/
#INT_RA
void intra(void){
int1 bit;
bit=interrupt_active(INT_RA0); //LOOK in lst
bit=interrupt_active(INT_RA1); //LOOK in lst.
}
void main(void){
enable_interrupts(INT_RA0);
enable_interrupts(INT_RA0_L2H);
enable_interrupts(INT_RA0_H2L);
enable_interrupts(INT_RA1);
enable_interrupts(INT_RA1_L2H);
enable_interrupts(INT_RA1_H2L);
}
|
List file MAIN section (Look OK):
Code: |
.................... enable_interrupts(INT_RA0);
0034: BSF INTCON.IOCIE
0035: MOVLB 07
0036: BSF IOCAP.0
0037: BSF IOCAN.0
.................... enable_interrupts(INT_RA0_L2H);
0038: BSF INTCON.IOCIE
0039: BSF IOCAP.0
003A: BCF IOCAN.0
.................... enable_interrupts(INT_RA0_H2L);
003B: BSF INTCON.IOCIE
003C: BSF IOCAN.0
003D: BCF IOCAP.0
....................
.................... enable_interrupts(INT_RA1);
003E: BSF INTCON.IOCIE
003F: BSF IOCAP.1
0040: BSF IOCAN.1
.................... enable_interrupts(INT_RA1_L2H);
0041: BSF INTCON.IOCIE
0042: BSF IOCAP.1
0043: BCF IOCAN.1
.................... enable_interrupts(INT_RA1_H2L);
0044: BSF INTCON.IOCIE
0045: BSF IOCAN.1
0046: BCF IOCAP.1
|
List interrupt:
Code: |
.................... #INT_RA
.................... void intra(void){
.................... int1 bit;
....................
.................... bit=interrupt_active(INT_RA0);
001E: BCF 24.0
001F: BTFSC INTCON.IOCIF --> I expect IOCAF0
0020: BSF bit
....................
.................... bit=interrupt_active(INT_RA1);
0021: BCF 24.0
0022: BTFSC INTCON.IOCIF --> I expect IOCAF1
0023: BSF bit
-----
0024: MOVLW FF
0025: MOVLB 07
0026: XORWF IOCAF,W
0027: ANDWF IOCAF,F
0028: BCF INTCON.IOCIF
0029: MOVLP 00
002A: MOVLB 00
002B: GOTO 013
.................... }
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Sun Apr 12, 2015 2:29 pm |
|
|
Interrupt_active, only tests physical interrupts. The physical interrupt is INT_RA. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Apr 12, 2015 2:38 pm |
|
|
Here is something you could use. Add this little macro above your isr.
Code: |
#byte IOCAF = getenv("SFR:IOCAF")
#define ioca_active(x) (IOCAF & make8(x, 2))
#INT_RA
void intra(void){
int1 bit;
bit = ioca_active(INT_RA0);
bit= ioca_active(INT_RA1);
}
|
It generates this code:
Code: |
.................... bit = ioca_active(INT_RA0);
001E: MOVLB 07
001F: MOVF IOCAF,W // Read IOCAF
0020: ANDLW 01 // Mask it with 0x01 to test IOCAF0 bit
0021: MOVWF @78 // Save result in temp reg (ram)
0022: MOVLB 00
0023: BCF 25.0 // Initialize bit = 0
0024: BTFSC @78.0 // Test state of ioc flag bit.
0025: BSF bit // If ioc flag = 1, set bit = 1
....................
.................... bit= ioca_active(INT_RA1);
0026: MOVLB 07
0027: MOVF IOCAF,W
0028: ANDLW 02 // Mask is 0x02 for int_ra1
0029: MOVWF @78
002A: MOVLB 00
002B: BCF 25.0
002C: BTFSC @78.0
002D: BSF bit |
|
|
|
hmmpic
Joined: 09 Mar 2010 Posts: 314 Location: Denmark
|
|
Posted: Sun Apr 12, 2015 2:56 pm |
|
|
Hi
Many CCS special features are not that easy to figure, without testing them first ...
Thanks both of you. |
|
|
|