|
在5509 DSP程序中断中使用XF管脚
使一个LED的闪亮是经常用的,但这其中有一个误区,现分析如下,以定时器控制LED灯为例:
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">void main()</span>
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> {</span>
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> init_5509();</span>
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> init_timer();</span>
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> while(1) </span>
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> {</span>
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> asm(" NOP");</span>
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> }</span>
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> }</span>
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">interrupt void int_timer0()</span>
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">{</span>
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> Flag=Flag+1;</span>
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> if (Flag>10)</span>
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> asm(" SSBX XF");</span>
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> else</span>
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> asm(" RSBX XF");</span>
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> if (Flag>20)</span>
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> Flag=0;</span>
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">}</span>
复制代码
复制代码
这个程序不能实现控制的。使用XF的时候要注意一下,XF是ST1的一个bit,但是在中断中,首先把ST1压入堆栈,出中断前才弹出堆栈,所以在中断中改变XF没有实际的意义。所以在C/C++加如汇编要谨慎。修改后的程序如下:
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">void main()</span>
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">{</span>
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> init_5509();</span>
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> init_timer();</span>
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> while(1) </span>
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> {</span>
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> asm(" NOP");</span>
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> if (Flag>10)</span>
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> asm(" SSBX XF");</span>
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> else</span>
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> asm(" RSBX XF");</span>
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> }</span>
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">}</span>
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">interrupt void int_timer0()</span>
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">{</span>
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> Flag=Flag+1; </span>
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> if (Flag>20)</span>
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> Flag=0;</span>
- <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">}</span>
复制代码
复制代码
这个程序就好使了。
|
|