📄 pic16f87x单片机中断系统应用须关注的问题.htm
字号:
<DIV align=center>寄存器内容</DIV></TD></TR>
<TR>
<TD width="8%">
<DIV align=center>Bit7</DIV></TD>
<TD width="7%">
<DIV align=center>Bit6</DIV></TD>
<TD width="5%">
<DIV align=center>Bit5</DIV></TD>
<TD width="5%">
<DIV align=center>Bit4</DIV></TD>
<TD width="6%">
<DIV align=center>Bit3</DIV></TD>
<TD width="7%">
<DIV align=center>Bit2</DIV></TD>
<TD width="7%">
<DIV align=center>Bit1</DIV></TD>
<TD width="9%">
<DIV align=center>Bit0</DIV></TD></TR>
<TR>
<TD width="18%">
<DIV align=left>选项寄存器</DIV></TD>
<TD width="15%">
<DIV align=center>OPTION-REG</DIV></TD>
<TD width="13%">
<DIV align=center>81H/181H</DIV></TD>
<TD bgColor=#cccccc width="8%">
<DIV align=center>/RBPU</DIV></TD>
<TD width="7%">
<DIV align=center>INTEDG</DIV></TD>
<TD bgColor=#cccccc width="5%">
<DIV align=center>T0CS</DIV></TD>
<TD bgColor=#cccccc width="5%">
<DIV align=center>T0SE</DIV></TD>
<TD bgColor=#cccccc width="6%">
<DIV align=center>PSA</DIV></TD>
<TD bgColor=#cccccc width="7%">
<DIV align=center>PS2</DIV></TD>
<TD bgColor=#cccccc width="7%">
<DIV align=center>PS1</DIV></TD>
<TD bgColor=#cccccc width="9%">
<DIV align=center>PS0</DIV></TD></TR>
<TR>
<TD width="18%">
<DIV align=left>中断控制寄存器</DIV></TD>
<TD width="15%">
<DIV align=center>INTCON</DIV></TD>
<TD width="13%">
<DIV align=center>0BH/8B/<BR>10BH/18BH</DIV></TD>
<TD width="8%">
<DIV align=center>GIE</DIV></TD>
<TD width="7%">
<DIV align=center>PEIE</DIV></TD>
<TD width="5%">
<DIV align=center>T0IE</DIV></TD>
<TD width="5%">
<DIV align=center>INTE</DIV></TD>
<TD width="6%">
<DIV align=center>RBIE</DIV></TD>
<TD width="7%">
<DIV align=center>T0IF</DIV></TD>
<TD width="7%">
<DIV align=center>INTF</DIV></TD>
<TD width="9%">
<DIV align=center>RBIF</DIV></TD></TR>
<TR>
<TD width="18%">
<DIV align=left>第1外设中断标志寄存器</DIV></TD>
<TD width="15%">
<DIV align=center>PIR1</DIV></TD>
<TD width="13%">
<DIV align=center>0CH</DIV></TD>
<TD bgColor=#cccccc width="8%">
<DIV align=center>PSPIF</DIV></TD>
<TD width="7%">
<DIV align=center>ADIF</DIV></TD>
<TD width="5%">
<DIV align=center>RCIF</DIV></TD>
<TD width="5%">
<DIV align=center>TXIF</DIV></TD>
<TD width="6%">
<DIV align=center>SSPIF</DIV></TD>
<TD width="7%">
<DIV align=center>CCP1IF</DIV></TD>
<TD width="7%">
<DIV align=center>TMR2IF</DIV></TD>
<TD width="9%">
<DIV align=center>TMR1IF</DIV></TD></TR>
<TR>
<TD width="18%">
<DIV align=left>第1外设中断屏蔽寄存器</DIV></TD>
<TD width="15%">
<DIV align=center>PIE1</DIV></TD>
<TD width="13%">
<DIV align=center>8CH</DIV></TD>
<TD bgColor=#cccccc width="8%">
<DIV align=center>PSPIE</DIV></TD>
<TD width="7%">
<DIV align=center>ADIE</DIV></TD>
<TD width="5%">
<DIV align=center>RCIE</DIV></TD>
<TD width="5%">
<DIV align=center>TXIE</DIV></TD>
<TD width="6%">
<DIV align=center>SSPIE</DIV></TD>
<TD width="7%">
<DIV align=center>CCP1IE</DIV></TD>
<TD width="7%">
<DIV align=center>TMR2IE</DIV></TD>
<TD width="9%">
<DIV align=center>TMR1IE</DIV></TD></TR>
<TR>
<TD width="18%">
<DIV align=left>第2外设中断标志寄存器</DIV></TD>
<TD width="15%">
<DIV align=center>PIR2</DIV></TD>
<TD width="13%">
<DIV align=center>0DH</DIV></TD>
<TD bgColor=#cccccc width="8%">
<DIV align=center>-</DIV></TD>
<TD bgColor=#cccccc width="7%">
<DIV align=center>-</DIV></TD>
<TD bgColor=#cccccc width="5%">
<DIV align=center>-</DIV></TD>
<TD width="5%">
<DIV align=center>REIF</DIV></TD>
<TD width="6%">
<DIV align=center>BCLIF</DIV></TD>
<TD bgColor=#cccccc width="7%">
<DIV align=center>-</DIV></TD>
<TD bgColor=#cccccc width="7%">
<DIV align=center>-</DIV></TD>
<TD width="9%">
<DIV align=center>CCP2IF</DIV></TD></TR>
<TR>
<TD width="18%">
<DIV align=left>第2外设中断屏蔽寄存器</DIV></TD>
<TD width="15%">
<DIV align=center>PIE2</DIV></TD>
<TD width="13%">
<DIV align=center>8DH</DIV></TD>
<TD bgColor=#cccccc width="8%">
<DIV align=center>-</DIV></TD>
<TD bgColor=#cccccc width="7%">
<DIV align=center>-</DIV></TD>
<TD bgColor=#cccccc width="5%">
<DIV align=center>-</DIV></TD>
<TD width="5%">
<DIV align=center>EEIE</DIV></TD>
<TD width="6%">
<DIV align=center>BCLIE</DIV></TD>
<TD bgColor=#cccccc width="7%">
<DIV align=center>-</DIV></TD>
<TD bgColor=#cccccc width="7%">
<DIV align=center>-</DIV></TD>
<TD width="9%">
<DIV align=center>CCP2IE</DIV></TD></TR></TBODY></TABLE>
<P align=left></P>
<P align=center><B>四、 中断的处理</B></P>
<P
align=left> 单片机复位后,由硬件自动对全局中断屏蔽位进行设置GIE=0,将屏蔽所有的中断源。中断返回指令“RETFIE”执行后,也由硬件自动对总屏蔽位进行设置GIE=1,重新开放所有的中断源。不论各种中断屏蔽位和全局中断屏蔽位GIE处于何种状态(是开放还是禁止),当某一中断源的中断条件满足时,都会发出中断请求,相应的中断标志位都会被置位(=1)。但是,是否能够得到CPU的响应,则要根据该中断源所涉及到的中断屏蔽位的状态而定。CPU响应中断后,由硬件自动对全局中断屏蔽位进行清零(GIE=0),屏蔽所有的中断源,以免发生重复中断响应,然后,由硬件自动把当前的程序计数器PC值(即程序断点地址)压入堆栈(实际为硬件堆栈),并且把PC寄存器置以中断向量地址(0004H),从而转向并开始执行中断服务程序。进入中断服务程序后,程序中必须安排指令,检查发出请求的中断源(如果同时开放多个中断源的话)。这可以通过检查各个中断源的标志位来实现。一旦确定出发出申请的中断源,就用软件把该中断源的标志位人为地清零,否则,执行中断返回指令“RETFIE”。重开中断后,由于中断标志位仍为“1”而引起CPU重复响应同一个中断请求。中断服务程序的末尾必须放置1条中断返回指令“RETFIE”。执行该条指令后,不仅可以重开中断,而且还可以由硬件自动将保留在堆栈顶部的断点地址弹出,并放回到程序计数器PC中,使CPU返回和继续执行被中断的主程序。
<BR> <B>1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -