Each of the 8051s interrupts has its own bit in a special interrupt function register ( IE ) (SFR) and is activated by setting the corresponding bit. The code examples below are given in assembly 8051, as well as in C, to give a general idea of ββwhat is going on.
To enable external interrupt 0 ( EX0 ), you need to set IE bit 0.
SETB EX0 or ORL IE,#01 or MOV IE,#01
To enable external interrupt 1 ( EX1 ), you need to set bit 3 from IE .
SETB EX1 or ORL IE,#08 or MOV IE,#08
Then interrupts should be enabled worldwide by setting bit 7 from IE , which is the global enable / disable permission ( EA ) bit. If necessary, you can set the priority of external interrupts to a high level using the Interrupt Priority ( IP ) SFR.
SETB EA or ORL IE,#80
Example in C:
#define IE (*(volatile unsigned char *)0xA8) #define BIT(x) (1 << (x)) ... IE &= ~BIT(7); ... IE |= BIT(0); ... IE |= BIT(1); ... IE ^= BIT(7)
or
IE = 0x89; /* enable both external interrupts and globally enable interrupts */
Various 8051 C compiler vendors often define their own methods for setting interrupt functions. You may need to consult the documentation for your specific compiler.
To determine the interrupt function using the Keil C51 compiler ( pdf link to the appendix note ), the interrupt number and register bank are indicated, where the interrupt number corresponds to a specific address of the interrupt vector.
void my_external_interrupt_0_routine(void) interrupt 0 using 2 { }
To define the interrupt function using the 8051 IAR C / C ++ compiler (icc8051) ( pdf link to the reference manual ), __interrupt keyword and you can use the #pragma vector .
#pragma vector=0x03 __interrupt void my_external_interrupt_0_routine(void) { }
If you are new to 8051, there is a lot of information available at www.8052.com . I would also recommend the 8051/8052 Microcontroller: architecture, assembly language and hardware , written by Craig Steiner, webmaster and author of 8052.com.