C program - interrupt问题
时间:2014-05-13
来源:互联网
我的情况是用类似8051的micro-controller
其中一个port是连接去infra-red sensor
我想要的效果是:如果infra-red sensor有感应 (ie. P2^2 = 1)
原本在运行的主程式就会立即被interrupt, 运行一个更优先的程式 (因为sensor感应到东西)
除了每一句指令之间都加if, 例如
(...)
if (interrupt == 1)
{...............}
(...)
if (interrupt == 1)
{...............}
(...)
if (interrupt == 1)
{...............}
还有别的方法吗?
[ 本帖最后由 Dragon619 於 2014-4-26 02:22 AM 编辑 ]
作者: Dragon619 发布时间: 2014-05-13
*非Timer interrupt
我的情况是用类似8051的micro-controller
其中一个port是连接去infra-red sensor
我想要的效果是:如果infra-red sensor有感应 (ie. P2^2 = 1)
原本在运行的主程式就会立即被interrupt, 运 ...
如: http://www.keil.com/support/man/docs/c51/c51_le_interruptfuncs.htm
作者: xianrenb 发布时间: 2014-05-13
估计会有特别的写法。
如: http://www.keil.com/support/man/docs/c51/c51_le_interruptfuncs.htm

作者: Dragon619 发布时间: 2014-05-13
看不懂

基本上这些果西我无什么印象了。
不过看 http://www.keil.com/dd/docs/datashts/atmel/at89s51_ds.pdf ,见到 interrupt pin 是 p3.2 及 p3.3 的。
用法亦好像是要 0 或 falling edge 。
花时间阅读 datasheet 与 user guide 一类资料是必须的。
如果是普通 input ,就算不上是 interrupt 。
作者: xianrenb 发布时间: 2014-05-13
无留意到你采用的 pin 应该不是 interrupt pin 。
基本上这些果西我无什么印象了。
不过看 http://www.keil.com/dd/docs/datashts/atmel/at89s51_ds.pdf ,见到 interrupt pin 是 p3.2 及 p3.3 的。
用法亦 ...
其实我想知道的是C有没有方法做到interrupt的效果 (我的做法好像怪怪的XD?
作者: Dragon619 发布时间: 2014-05-13
If there is not such thing, then "interrupt" is just one of the way to "wake-up" the suspending/sleeping hardware.
As seen from your code, you're already doing the right thing.......
Could you explain what can't you do currently? Or what is the problem? (apart from perfectionalism)
可能我表达方式有点问题...
其实我想知道的是C有没有方法做到interrupt的效果 (我的做法好像怪怪的XD?
作者: a8d7e8 发布时间: 2014-05-13
I think 8051 like hardware has no interrupt vector table/register?
If there is not such thing, then "interrupt" is just one of the way to "wake-up" the suspending/sleeping hardware.
As seen from ...
My program is not really complicated, it does every action with a delay loop.
So what I have to do is add a condition (by using "if") in the delay loop. (which is equal to adding "if" between all actions)
And actually I am not really familiar with 8051, what I did was just using 2 sensors + 2 motors to design 2 functions, which are avoiding obstacles and detecting fire
The "interrupt" I want to use is "STOP" when fire is detected even though the some actions are being done.
If I just design the program with "avoiding" and "stop when fire is detected" separately, my program wiil not execute "stop" until "avoiding" is finished.
作者: Dragon619 发布时间: 2014-05-13
"If I just design the program with "avoiding" and "stop when fire is detected" separately, my program wiil not execute "stop" until "avoiding" is finished." ?
So it seems that there are 2 problems:
1. The already solved problem about termination on fire;
2. The instant termination on fire - no matter if any subroutine is being processed in a timely manner (eg. it may needs 1s to finish the avoiding logic).
Is it possible to connect the fire sensor signal pin(if it is just a pin) to a reset pin(if there is any)?
Such that after POR if the fire pin is still true, u know there is fire so just do nothing.
My problem is already solved, but actually I didn't get answer from my question.
My program is not really complicated, it does every action with a delay loop.
So what I have to do is add a conditi ...
作者: a8d7e8 发布时间: 2014-05-13
So to summarize:
1. Go check the exact mpu model you're using, whether it has the interrupt vector table that can be hooked with the fire sensor(IR sensor in your case).
2. Declare an Interrupt Service Routine for that interrupt as in the example in the link of comment #2.
3. Verify that the ISR take control when the IR sensor change its signal (eg. change from 0 to 1)
4. Wo-ha your device stop instantly when an extremely high amount of IR is detected!
作者: a8d7e8 发布时间: 2014-05-13
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28