Hi! I would like to release an external interrupt at the XC167 by Infineon, over Port 2, pin 8 (EX0IN). I mean to have set actually all registers, different priorities tried out, and also different reactions in the interrupt service routine (LED blinks,Text on display). The manual polling of the Port works. Only the interrupt does not release. The source code of the InterruptIni() and the ISR: void InterruptIni(void) { DP2 =0x00; EXICON = 0x0015; EXISEL0 = 0x0000; CC1_CC8IC = 0x017F; PSW_IEN = 1; } void InterruptA() interrupt 0x18 //Pin 2.8 { P9^4=0; //Yellow LED } It would be great if someone could help me! Thank you and greeting Nils
I don't know what
P9^4=0; //Yellow LED
void InterruptA() interrupt 0x18 //Pin 2.8 { P9 ^= 4; /* toggle Yellow LED on rising edge */ }
P9 |= 4; /* Yellow LED pin is configured as an output */
Sorry, I completely screwed that one up. If you want P9.4 then you need...
P9 |= 0x10 /* bit 4 of the port */ P9 ^= 0x10
Hi Chris! Thank you for your answer! Port 9 is bit-adressable. It also works to activate the LED via P9^4=0; But that's not my problem. The problem is, that the uC doesn't react on the external interrupt. Regards Nils
Does this really work:
I missed that you were writing to protected registers. Please find the enclosed example which should work for you ;) As a side comment to using a bit XOR of the port that is bit addressable. I would recommend that you XOR the whole port when using the "C" compiler directly (assembly different story). Here is what the compiler will generate for the two code sequences. P9_P4 ^= 1; /* toggle using bit addressing */ Assembly listing… 00C0009A 0FF4 BSET R4.0 00C0009C 7AF48B04 BXOR SDA2,R4.0 P9 ^= 0x10; /* toggle Yellow LED on rising edge of Pin 2.8 */ Assembly listing... 00C00094 568B1000 XOR P9,#0x0010 -Chris
#include <xc167.h> unsigned long counter; volatile unsigned int data; void UnlockProtecReg(void) { /* Sequence to change the security level */ SCUSLC = 0xAAAA; /* Command0 */ SCUSLC = 0x5554; /* Command1 */ SCUSLC = 0x96FF; /* Command2: current password = 00H */ SCUSLC = 0x08ED; /* Command3: level = 01, new password = EDH */ /* Access sequence in secured mode */ SCUSLC = 0x8E12; /* Command4: current password = EDH */ /* Access enabled by the preceding Command4 */ } void InterruptIni(void) { UnlockProtecReg(); EXICON = 0x0001; /* Interrupt on positive edge (rising) */ UnlockProtecReg(); EXISEL0 = 0x0000; /* Input from associated EXxIN pin */ CC1_CC8IC = 0x017F; /* Interrupt enabled, (ILVL)= 15, (GLVL)= 3, (GPX)= 1 */ } void InterruptA() interrupt 0x18 { P9 ^= 0x10; /* toggle Yellow LED on rising edge of Pin 2.8 */ } void main (void) { DP2 =0x0200; /* P2.8 externally tied to P2.8 for testing */ DP9 |= 0x10; /* make the LED pin an output*/ InterruptIni(); PSW_IEN = 1; /* globally enable interrupts */ for(;;) { if (counter++ > 0x50000) { counter = 0; P2 ^= 0x0200; } } }
Thank you very much for your answer. I'll try it out. Sorry, I forgot a line. If I define
sbit LED = P9^4; // Yellow LED
LED ^= 1;
Yes, it works! I've tried out and it was successfull. Thank you very mutch, Chris! I didn't recognize the note about security level in the datasheet. Greetings - Nils