[AVR单片机] 如何中断标志清除??

[复制链接]
5805|18
 楼主| glen_cao 发表于 2007-9-12 08:04 | 显示全部楼层 |阅读模式
TI, TE, ST, AN, IO
昨天看AVR-lib的资料上这样说:
Why are (many) interrupt flags cleared by writing a logical 1?
........
The solution is simple: writing a logical 1 to it requires only a single OUT instruction,
and it is clear that only this single interrupt request bit will be cleared. There is no need
to perform a read-modify-write cycle (like, an SBI instruction), since all bits in these
control registers are interrupt bits, and writing a logical 0 to the remaining bits (as it
is done by the simple OUT instruction) will not alter them, so there is no risk of any
race condition that might accidentally clear another interrupt request bit. So instead of
writing
TIFR |= _BV(TOV0); /* wrong! */
simply use
TIFR = _BV(TOV0);

用TIFR |= _BV(TOV0);是不是真的错???我一直这样用的!!!
 楼主| glen_cao 发表于 2007-9-12 08:21 | 显示全部楼层
BitFu 发表于 2007-9-12 08:45 | 显示全部楼层

没错就是这样清除

写1清或进入中断程序自动清除
要年不过要看具体器件对应的数据手册
 楼主| glen_cao 发表于 2007-9-12 10:38 | 显示全部楼层

附:

如果用了中断源T1_OVF和T0_OVF.
现在用软件清除T0_OVF而不影响T1的中断标志.
请问是用
    TIFR |= _BV(TOV0);
还是用
    TIFR = _BV(TOV0);

????
 楼主| glen_cao 发表于 2007-9-12 12:11 | 显示全部楼层
zhiwei 发表于 2007-9-12 12:17 | 显示全部楼层

当然用

前者了,用后者,其他位可能会受影响的。
 楼主| glen_cao 发表于 2007-9-12 13:32 | 显示全部楼层

看来楼上的是没有看Avr-lib-user-manual

 楼主| glen_cao 发表于 2007-9-12 14:28 | 显示全部楼层

M8的datasheet上是这么说的:

。。。。。。
也可以对其写入逻辑"1” 来清除该标志位。
 楼主| glen_cao 发表于 2007-9-12 17:41 | 显示全部楼层
 楼主| glen_cao 发表于 2007-9-13 15:53 | 显示全部楼层

没人理了

simon21ic 发表于 2007-9-14 01:55 | 显示全部楼层

TIFR |= _BV(TOV0);是对的

但没有必要这么写,编译器应该不会优化的(多了一次寄存器读取操作).
TIFR里的位都是中断Flag,可以用"TIFR = _BV(TOV0);",只会清除"1"对应的Flag,"0"对应的不变.

评分

参与人数 1威望 +6 收起 理由
qin552011373 + 6 赞一个!

查看全部评分

农民讲习所 发表于 2007-9-14 10:13 | 显示全部楼层

TIFR = _BV(TOV0);

 楼主| glen_cao 发表于 2007-9-17 16:45 | 显示全部楼层

知道了,谢谢各位的支持

一般首席 发表于 2013-3-19 12:55 | 显示全部楼层
不用管它为什么 只要知道这么用就行了 我是这么想的
qin552011373 发表于 2013-3-20 00:17 | 显示全部楼层
不错的讨论  
Socrazyman 发表于 2013-3-20 15:02 | 显示全部楼层
qin552011373 发表于 2013-3-21 21:59 | 显示全部楼层
Socrazyman 发表于 2013-3-20 15:02

yhhsky 发表于 2013-3-30 18:56 | 显示全部楼层
Socrazyman 发表于 2013-11-19 10:24 | 显示全部楼层
您需要登录后才可以回帖 登录 | 注册

本版积分规则

20

主题

61

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部