View previous topic :: View next topic |
Author |
Message |
future
Joined: 14 May 2004 Posts: 330
|
Setting multiple interrupt bits and global at same time. |
Posted: Sat Jun 26, 2004 11:43 am |
|
|
Is there any problem?
like:
enable_interrupts(int_ext|int_timer0|global); |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Jun 26, 2004 12:02 pm |
|
|
Quote: | enable_interrupts(int_ext|int_timer0|global); |
It won't work. If you look at the .H file for your PIC,
you'll see that the INT_xxx definitions consist of the
register address in the high byte and a bitmask in
the lower byte.
If you OR together different constants, you could
destroy the register address. If you OR together
different bitmasks, the compiler will only use the
first '1' bit that it finds. It will ignore the others.
In short, the compiler is not designed to allow
multiple INT_xxx constants to be OR'ed together. |
|
|
future
Joined: 14 May 2004 Posts: 330
|
|
Posted: Sat Jun 26, 2004 12:43 pm |
|
|
I tried that with a 18f452.
#byte INTCON = 0xFF2
enable_interrupts(int_ext|int_timer0|global);
Generated code:
....................enable_interrupts(int_ext|int_timer0|global);
084A: MOVLW F0
084C: IORWF FF2,F
F0=11110000 // sets GIE,PIE,TMR0IE,INT0IE
And works
But I dont know if I should set GIE and another int at the same. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Jun 26, 2004 2:54 pm |
|
|
Before I posted, I did a test with the 16F877 and PCM 3.190
and it didn't work. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sat Jun 26, 2004 4:02 pm |
|
|
I guess Future was lucky in choosing his combination of interrupts.
For the 18F452:
Code: | #define GLOBAL 0xF2C0
#define INT_RTCC 0xF220
#define INT_TIMER0 0xF220
#define INT_TIMER1 0x9D01
#define INT_TIMER2 0x9D02
#define INT_TIMER3 0xA002
#define INT_EXT 0xF210
.
.
.
|
It only works because GLOBAL, RTCC and INT_EXT are all in the same register. Replacing INT_TIMER0 by INT_TIMER1 would have resulted in disaster.
I personally disagree off using undocumented features like this because it might result to hard to find bugs in the future, for example when upgrading to a new compiler version or other chip. You have to consider if this future trouble is worth the 4 bytes you save now. |
|
|
|