8051外部中断

发布于 2024-08-30 12:29:16 字数 21 浏览 4 评论 0原文

如何开启8051的外部中断?

how to enable external interrupt of 8051?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

℡寂寞咖啡 2024-09-06 12:29:16

每个 8051 中断在中断使能 (IE) 特殊功能寄存器 (SFR) 中都有自己的位,并通过设置相应位来使能。下面的代码示例采用 8051 汇编语言和 C 语言,以提供对正在发生的情况的总体了解。

要启用外部中断 0 (EX0),您需要设置 IE 的位 0。

SETB EX0ORL IE,#01MOV IE,#01

启用外部中断 1 (EX1)您需要设置IE的位3。

SETB EX1ORL IE,#08MOV IE,#08

然后需要通过设置 的位 7 来全局启用中断IE,全局中断启用/禁用位(EA)。如果需要,您可以通过中断优先级(IP)SFR 将外部中断的优先级设置为高。

SETB EAORL IE,#80

C 语言示例:

#define IE (*(volatile unsigned char *)0xA8)
#define BIT(x) (1 << (x))
...
IE &= ~BIT(7); /* clear bit 7 of IE (EA) to disable interrupts */
...
IE |= BIT(0);  /* set bit 0 of IE (EX0) to enable external interrupt 0 */
...
IE |= BIT(1);  /* set bit 3 of IE (EX1) to enable external interrupt 1 */
...
IE ^= BIT(7)   /* toggle bit 7 of IE (EA) to re-enable interrupts */

IE = 0x89;  /* enable both external interrupts and globally enable interrupts */

各个 8051 C 编译器供应商通常定义自己的设置中断函数的方法。您可能需要查阅特定编译器的文档。

使用 Keil C51 编译器定义中断函数(应用笔记的 pdf 链接) ,指定中断号和寄存器组,其中中断号对应于特定的中断向量地址。

void my_external_interrupt_0_routine(void) interrupt 0 using 2
{
/* do something */
}

使用 8051 IAR C/C++ 编译器 (icc8051) 定义中断函数 (pdf 链接参考指南),可以使用__interrupt关键字和#pragma vector指令。

#pragma vector=0x03
__interrupt void my_external_interrupt_0_routine(void)
{
/* do something */
}

如果您是 8051 的新手,可以在 www.8052.com 上获取大量信息。我还推荐8051/8052 微控制器:架构、汇编语言和硬件接口< /a> 由 8052.com 的网站管理员和作者 Craig Steiner 撰写。

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 of IE.

SETB EX0 or ORL IE,#01 or MOV IE,#01

To enable external interrupt 1 (EX1) you need to set bit 3 of IE.

SETB EX1 or ORL IE,#08 or MOV 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 or ORL IE,#80

Example in C:

#define IE (*(volatile unsigned char *)0xA8)
#define BIT(x) (1 << (x))
...
IE &= ~BIT(7); /* clear bit 7 of IE (EA) to disable interrupts */
...
IE |= BIT(0);  /* set bit 0 of IE (EX0) to enable external interrupt 0 */
...
IE |= BIT(1);  /* set bit 3 of IE (EX1) to enable external interrupt 1 */
...
IE ^= BIT(7)   /* toggle bit 7 of IE (EA) to re-enable interrupts */

or

IE = 0x89;  /* enable both external interrupts and globally enable interrupts */

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.

void my_external_interrupt_0_routine(void) interrupt 0 using 2
{
/* do something */
}

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.

#pragma vector=0x03
__interrupt void my_external_interrupt_0_routine(void)
{
/* do something */
}

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.

夏天碎花小短裙 2024-09-06 12:29:16

使能IE寄存器中外部中断的相应位。
如果是电平触发,只需编写该中断对应的子程序即可,否则使能边沿触发中断对应的TCON寄存器位——无论是INT0还是INT1。

Enable the corresponding bit of external interrupt in IE register.
If it is level triggering, just write the subroutine appropriate to this interrupt, or else enable the TCON register bit corresponding to the edge triggered interrupt – whether it is INT0 or INT1.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文