📄 单片机第二十课:中断系统.htm
字号:
face=宋体>-定时器</FONT><FONT lang=ZH-CN face=System>0</FONT><FONT lang=ZH-CN
face=宋体>中断允许</FONT></P>
<P align=justify><FONT lang=ZH-CN face=System>EX0</FONT><FONT lang=ZH-CN
face=宋体>-外中断</FONT><FONT lang=ZH-CN face=System>0</FONT><FONT lang=ZH-CN
face=宋体>中断允许。</FONT></P>
<P align=justify><FONT lang=ZH-CN face=宋体>如果我们要设置允许外中断</FONT><FONT lang=ZH-CN
face=System>1</FONT><FONT lang=ZH-CN face=宋体>,定时器</FONT><FONT lang=ZH-CN
face=System>1</FONT><FONT lang=ZH-CN face=宋体>中断允许,其它不允许,则</FONT><FONT lang=ZH-CN
face=System>IE</FONT><FONT lang=ZH-CN face=宋体>可以是</FONT></P>
<TABLE cellSpacing=1 cellPadding=7 width=607 border=1>
<TBODY>
<TR>
<TD vAlign=top width="13%"><FONT lang=ZH-CN face=System>
<P align=center>EA</FONT></P></TD>
<TD vAlign=top width="13%"><FONT lang=ZH-CN face=System>
<P align=center>X</FONT></P></TD>
<TD vAlign=top width="13%"><FONT lang=ZH-CN face=System>
<P align=center>X</FONT></P></TD>
<TD vAlign=top width="13%"><FONT lang=ZH-CN face=System>
<P align=center>ES</FONT></P></TD>
<TD vAlign=top width="13%"><FONT lang=ZH-CN face=System>
<P align=center>ET1</FONT></P></TD>
<TD vAlign=top width="13%"><FONT lang=ZH-CN face=System>
<P align=center>EX1</FONT></P></TD>
<TD vAlign=top width="13%"><FONT lang=ZH-CN face=System>
<P align=center>ET0</FONT></P></TD>
<TD vAlign=top width="13%"><FONT lang=ZH-CN face=System>
<P align=center>EX0</FONT></P></TD></TR>
<TR>
<TD vAlign=top width="13%"><FONT lang=ZH-CN face=System>
<P align=center>1</FONT></P></TD>
<TD vAlign=top width="13%"><FONT lang=ZH-CN face=System>
<P align=center>0</FONT></P></TD>
<TD vAlign=top width="13%"><FONT lang=ZH-CN face=System>
<P align=center>0</FONT></P></TD>
<TD vAlign=top width="13%"><FONT lang=ZH-CN face=System>
<P align=center>0</FONT></P></TD>
<TD vAlign=top width="13%"><FONT lang=ZH-CN face=System>
<P align=center>1</FONT></P></TD>
<TD vAlign=top width="13%"><FONT lang=ZH-CN face=System>
<P align=center>1</FONT></P></TD>
<TD vAlign=top width="13%"><FONT lang=ZH-CN face=System>
<P align=center>0</FONT></P></TD>
<TD vAlign=top width="13%"><FONT lang=ZH-CN face=System>
<P align=center>0</FONT></P></TD></TR></TBODY></TABLE>
<P align=justify><FONT lang=ZH-CN face=宋体>即</FONT><FONT lang=ZH-CN
face=System>8CH</FONT><FONT lang=ZH-CN face=宋体>,当然,我们也可以用位操作指令</FONT></P>
<P align=justify><FONT lang=ZH-CN face=System>SETB EA</FONT><FONT lang=ZH-CN
face=宋体><BR></FONT><FONT lang=ZH-CN face=System>SETB ET1</FONT></P><FONT
lang=ZH-CN face=System>
<P align=justify>SETB EX1</P></FONT><FONT lang=ZH-CN face=宋体>
<P align=justify>来实现它。</P></FONT>
<P align=justify><FONT lang=ZH-CN face=System>3</FONT><FONT lang=ZH-CN
face=宋体>、五个中断源的自然优先级与中断服务入口地址</FONT></P>
<DIR>
<P align=justify><FONT lang=ZH-CN face=宋体>外中断</FONT><FONT lang=ZH-CN
face=System>0</FONT><FONT lang=ZH-CN face=宋体>:</FONT><FONT lang=ZH-CN
face=System>0003H</FONT></P>
<P align=justify><FONT lang=ZH-CN face=宋体>定时器</FONT><FONT lang=ZH-CN
face=System>0</FONT><FONT lang=ZH-CN face=宋体>:</FONT><FONT lang=ZH-CN
face=System>000BH</FONT></P>
<P align=justify><FONT lang=ZH-CN face=宋体>外中断</FONT><FONT lang=ZH-CN
face=System>1</FONT><FONT lang=ZH-CN face=宋体>:</FONT><FONT lang=ZH-CN
face=System>0013H</FONT></P>
<P align=justify><FONT lang=ZH-CN face=宋体>定时器</FONT><FONT lang=ZH-CN
face=System>1</FONT><FONT lang=ZH-CN face=宋体>:</FONT><FONT lang=ZH-CN
face=System>001BH</FONT></P>
<P align=justify><FONT lang=ZH-CN face=宋体>串口</FONT> <FONT lang=ZH-CN
face=宋体>:</FONT><FONT lang=ZH-CN face=System>0023H</FONT></P><FONT lang=ZH-CN
face=宋体>
<P align=justify>它们的自然优先级由高到低排列。</P>
<P align=justify>写到这里,大家应当明白,为什么前面有一些程序一始我们这样写:</P></FONT><FONT lang=ZH-CN
face=System>
<P align=justify>ORG 0000H</P>
<P align=justify>LJMP START</P>
<P align=justify>ORG 0030H</P></FONT>
<P align=justify><FONT lang=ZH-CN face=System>START</FONT><FONT lang=ZH-CN
face=宋体>:</FONT></P><FONT lang=ZH-CN face=System>
<P align=justify>。</P></FONT><FONT lang=ZH-CN face=宋体>
<P align=justify>。</P>
<P align=justify>。</P></FONT>
<P align=justify><FONT lang=ZH-CN
face=宋体>这样写的目的,就是为了让出中断源所占用的向量地址。当然,在程序中没用中断时,直接从</FONT><FONT lang=ZH-CN
face=System>0000H</FONT><FONT lang=ZH-CN
face=宋体>开始写程序,在原理上并没有错,但在实际工作中最好不这样做。</FONT></P><FONT lang=ZH-CN face=宋体>
<P
align=justify>优先级:单片机采用了自然优先级和人工设置高、低优先级的策略,即可以由程序员设定那些中断是高优先级、哪些中断是低优先级,由于只有两级,必有一些中断处于同一级别,处于同一级别的,就由自然优先级确定。</P></FONT></DIR>
<P align=justify><FONT lang=ZH-CN
face=宋体>开机时,每个中断都处于低优先级,我们可以用指令对优先级进行设置。看表</FONT><FONT lang=ZH-CN
face=System>2</FONT></P>
<P align=justify><FONT lang=ZH-CN face=宋体>中断优先级中由中断优先级寄存器</FONT><FONT lang=ZH-CN
face=System>IP</FONT><FONT lang=ZH-CN face=宋体>来高置的,</FONT><FONT lang=ZH-CN
face=System>IP</FONT><FONT lang=ZH-CN face=宋体>中某位设为</FONT><FONT lang=ZH-CN
face=System>1</FONT><FONT lang=ZH-CN face=宋体>,相应的中断就是高优先级,否则就是低优先级。</FONT></P>
<P align=center>
<CENTER>
<TABLE cellSpacing=1 cellPadding=7 width=607 border=1>
<TBODY>
<TR>
<TD vAlign=top width="13%"><FONT lang=ZH-CN face=System>
<P align=center>X</FONT></P></TD>
<TD vAlign=top width="13%"><FONT lang=ZH-CN face=System>
<P align=center>X</FONT></P></TD>
<TD vAlign=top width="13%"><FONT lang=ZH-CN face=System>
<P align=center>X</FONT></P></TD>
<TD vAlign=top width="13%"><FONT lang=ZH-CN face=System>
<P align=center>PS</FONT></P></TD>
<TD vAlign=top width="13%"><FONT lang=ZH-CN face=System>
<P align=center>PT1</FONT></P></TD>
<TD vAlign=top width="13%"><FONT lang=ZH-CN face=System>
<P align=center>PX1</FONT></P></TD>
<TD vAlign=top width="13%"><FONT lang=ZH-CN face=System>
<P align=center>PT0</FONT></P></TD>
<TD vAlign=top width="13%"><FONT lang=ZH-CN face=System>
<P align=center>PX0</FONT></P></TD></TR></TBODY></TABLE></CENTER>
<P></P>
<DIR>
<P align=justify><FONT lang=ZH-CN face=宋体>例:设有如下要求,将</FONT><FONT lang=ZH-CN
face=System>T0</FONT><FONT lang=ZH-CN face=宋体>、外中断</FONT><FONT lang=ZH-CN
face=System>1</FONT><FONT lang=ZH-CN face=宋体>设为高优先级,其它为低优先级,求</FONT><FONT
lang=ZH-CN face=System>IP</FONT><FONT lang=ZH-CN face=宋体>的值。</FONT></P>
<P align=justify><FONT lang=ZH-CN face=System>IP</FONT><FONT lang=ZH-CN
face=宋体>的首</FONT><FONT lang=ZH-CN face=System>3</FONT><FONT lang=ZH-CN
face=宋体>位没用,可任意取值,设为</FONT><FONT lang=ZH-CN face=System>000</FONT><FONT
lang=ZH-CN face=宋体>,后面根据要求写就可以了</FONT></P></DIR>
<TABLE cellSpacing=1 cellPadding=7 width=1214 border=1>
<TBODY>
<TR>
<TD vAlign=top width="6%"><FONT lang=ZH-CN face=System>
<P align=center>X</FONT></P></TD>
<TD vAlign=top width="6%"><FONT lang=ZH-CN face=System>
<P align=center>X</FONT></P></TD>
<TD vAlign=top width="6%"><FONT lang=ZH-CN face=System>
<P align=center>X</FONT></P></TD>
<TD vAlign=top width="6%"><FONT lang=ZH-CN face=System>
<P align=center>PS</FONT></P></TD>
<TD vAlign=top width="6%"><FONT lang=ZH-CN face=System>
<P align=center>PT1</FONT></P></TD>
<TD vAlign=top width="6%"><FONT lang=ZH-CN face=System>
<P align=center>PX1</FONT></P></TD>
<TD vAlign=top width="6%"><FONT lang=ZH-CN face=System>
<P align=center>PT0</FONT></P></TD>
<TD vAlign=top width="6%"><FONT lang=ZH-CN face=System>
<P align=center>PX0</FONT></P></TD>
<TD vAlign=top width="6%"><FONT lang=ZH-CN face=System>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -