how to enable external interrupt of 8051?
相关问题
- Multiple sockets for clients to connect to
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- Index of single bit in long integer (in C) [duplic
- Equivalent of std::pair in C
Each of the 8051s interrupts has its own bit in the interrupt enable (
IE
) special function register (SFR) and is enabled by setting the corresponding bit. The code examples below are in 8051 assembly as well as C to provide a general idea of what is taking place.To enable external interrupt 0 (
EX0
) you need to set bit 0 ofIE
.SETB EX0
orORL IE,#01
orMOV IE,#01
To enable external interrupt 1 (
EX1
) you need to set bit 3 ofIE
.SETB EX1
orORL IE,#08
orMOV IE,#08
Interrupts then need to be globally enabled by setting bit 7 of
IE
, which is the global interupt enable/disable bit (EA
). If necessary, you can set the priority of the external interrupts to high via the interrupt priority (IP
) SFR.SETB EA
orORL IE,#80
Example in C:
or
The various 8051 C compiler vendors often define their own methods of setting up interrupt functions. You may need to consult the documentation for your specific compiler.
To define an interrupt function using the Keil C51 Compiler (pdf link to application note), an interrupt number and register bank is specified where the interrupt number corresponds to a specific interrupt vector address.
To define an interrupt function using the 8051 IAR C/C++ Compiler (icc8051) (pdf link to reference guide), the
__interrupt
keyword and the#pragma vector
directive can be used.If you are new to the 8051, there is a wealth of information available at www.8052.com. I would also recommend The 8051/8052 Microcontroller: Architecture, Assembly Language, and Hardware Interfacing written by Craig Steiner, the webmaster and author of 8052.com.
very good tutorial, it helped me a lot. http://www.8052.com/tutint.phtml