了解中断/中断处理程序、PIC
我了解中断是什么,但不知道它是如何工作的或如何实现的。 我使用的是 PIC16F886,并将开关连接到 TRISB 上的位 5。 这样,我意识到在中断发生之前我需要做一些设置。 RB0-3 是 LED,RB4-7 用于中断/开关。
这样,我知道我需要通过以下方式启用 INTCON 中的中断: 设置位 GIE、INTF,我相信 RBIE 而不是 INTE,因为 RB0 正在被 LED 使用?但我不确定。
我主要关心的是:中断如何触发?另外,诸如 org 0x04 之类的东西。这在中断中有什么意义呢?这些是我无法理解的重要细节,但没有它们我就无法继续。任何帮助将不胜感激。
I understand WHAT an interrupt is, just not how it works or how it is implemented.
I am using a PIC16F886 and have my switch connected to bit 5 on TRISB.
With this, I realize that I need to do a bit of setup before an interrupt can occur.
RB0-3 are the LEDS, and RB4-7 are for the interrupts/switch.
With that, I know that I need to enable interrupts in INTCON by
setting bits GIE, INTF, and I believe RBIE and not INTE because RB0 is being used by an LED? But I am not sure.
My main concern is: how does an interrupt trigger? Also, things like org 0x04. What is the significance of that in an interrupt? These are the important details that just elude me, but without them I cannot proceed. Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
快速浏览一下数据表,0x4是中断向量。因此,您应该将发生中断时要跳转到的代码的地址放在地址 0x4 处,就像您可能已经将复位时要跳转到的代码的地址放在 0x0 处一样。
如果设置了 RBIE 位和 IOCB 中的相关位,则 PORTB 输入的任何变化都可能触发中断。您需要读取或写入 PORTB(实际上,您可能需要读取它,并检查位 5 的值以确保它是更改的开关),或者清除 RBIF 以结束中断。
因此:如果您启用了相关中断,那么当发现开关中的值发生变化时就会触发该中断。此时,CPU跳转到位于0x4的地址。
From a quick look at the datasheet, 0x4 is the interrupt vector. So you should put the address of the code you want to jump to when an interrupt occurs at address 0x4, just like you've presumably already put the address of the code you want to jump to upon reset at 0x0.
Any change on the input to PORTB can trigger an interrupt, if you have the RBIE bit set and the relevant bit in IOCB. You need to read or write PORTB (in practice, you'll probably want to read it, and check the value of bit 5 to make sure it's the switch that changed), or clear RBIF in order to end the interrupt.
So: if you've enabled the relevant interrupt, it's triggered when the value from your switch is spotted to have changed. At that point, the CPU jumps to the address located from 0x4.