查看: 347|回复: 0

[经验] 编程中DSP程序中断中使用XF管脚误区问题

[复制链接]

该用户从未签到

发表于 2021-1-20 14:02:10 | 显示全部楼层 |阅读模式
分享到:
在5509 DSP程序中断中使用XF管脚
使一个LED的闪亮是经常用的,但这其中有一个误区,现分析如下,以定时器控制LED灯为例:


  1. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">void main()</span>
  2. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">   {</span>
  3. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">    init_5509();</span>
  4. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">    init_timer();</span>
  5. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">    while(1) </span>
  6. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">         {</span>
  7. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">         asm(" NOP");</span>
  8. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">         }</span>
  9. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">   }</span>


  10. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">interrupt void int_timer0()</span>
  11. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">{</span>
  12. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">         Flag=Flag+1;</span>
  13. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">         if   (Flag>10)</span>


  14. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">              asm(" SSBX XF");</span>


  15. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">         else</span>


  16. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">              asm(" RSBX XF");</span>
  17. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">         if (Flag>20)</span>


  18. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">               Flag=0;</span>
  19. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">}</span>
复制代码

复制代码
这个程序不能实现控制的。使用XF的时候要注意一下,XF是ST1的一个bit,但是在中断中,首先把ST1压入堆栈,出中断前才弹出堆栈,所以在中断中改变XF没有实际的意义。所以在C/C++加如汇编要谨慎。修改后的程序如下:
  1. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">void main()</span>
  2. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">{</span>
  3. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">    init_5509();</span>
  4. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">    init_timer();</span>
  5. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">    while(1) </span>
  6. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">    {</span>
  7. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">           asm(" NOP");</span>
  8. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">           if (Flag>10)</span>


  9. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">              asm(" SSBX XF");</span>


  10. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">          else</span>


  11. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">             asm(" RSBX XF");</span>
  12. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">    }</span>
  13. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">}</span>


  14. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">interrupt void int_timer0()</span>
  15. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">{</span>
  16. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">       Flag=Flag+1; </span>
  17. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">       if (Flag>20)</span>


  18. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">       Flag=0;</span>
  19. <span style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">}</span>
复制代码

复制代码
这个程序就好使了。
回复

使用道具 举报

您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /4 下一条



手机版|小黑屋|与非网

GMT+8, 2024-11-27 16:37 , Processed in 0.115249 second(s), 15 queries , MemCache On.

ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

苏公网安备 32059002001037号

Powered by Discuz! X3.4

Copyright © 2001-2024, Tencent Cloud.