当前位置:网站首页>外部中断无法进入,删代码再还原就好......记录这个想不到的bug
外部中断无法进入,删代码再还原就好......记录这个想不到的bug
2022-07-02 05:52:00 【不知何人】
51单片机配置外部中断0/1无非就是以下几行代码。
IT0=1; //外部中断0下降沿触发
EX0=1; //允许中断0
IT1=1; //外部中断1下降沿触发
EX1=1;//允许中断1
EA=1; //开启总中断
但是本人调试了一整个晚上,还是无法通过按键(外部中断0/1的按键INT0/INT1)进入外部中断0/1。
最后我把主函数和外部中断0/1中所有的代码都删除,仅留了点灯代码在中断中,然后ctrl+z撤销删除,全部还原后,重新编译,一行代码都没改,但是发现按键(外部中断0/1的按键INT0/INT1)竟然可以触发外部中断了。
这种情况之前遇见过一次,但是不知道问题在哪,第二天改了改就可以用了,今天再次遇到,引起了我的注意。
我猜测是因为在keil中用C,每次编译时C语言优化有一些区别,导致的这种莫名奇妙的bug,如果使用汇编或者加上volatile关键字应该就不会遇见这种情况。
volatile关键字,由于内存访问速度是远不如CPU的,为了加速,在默认情况下,编译器会给你优化,例如本来该从内存单元里面取的数据,for循环取10次,为了方便,会将其优化放到寄存器里面,每次取寄存器即可,不用再一遍一遍的访问内存单元。而则这样的优化在有时候就会出现意想不到的错误。
边栏推荐
猜你喜欢

Importation de studio visuel

RGB infinite cube (advanced version)

Vscode paste image plugin saves image path settings

Minimum value ruler method for the length of continuous subsequences whose sum is not less than s

Appnuim environment configuration and basic knowledge

A collection of commonly used plug-ins for idea development tools
![[golang syntax] be careful with the copy of slices](/img/5e/1c82c58940939b94d03377ebdc03e3.jpg)
[golang syntax] be careful with the copy of slices

RNN recurrent neural network

Résumé de la collection de plug - ins couramment utilisée dans les outils de développement idea

Record sentry's path of stepping on the pit
随机推荐
软件测试答疑篇
1036 Boys vs Girls
Common protocols and download paths of NR
php父类(parent)
Matplotlib double Y axis + adjust legend position
Applet jumps to official account
数理统计与机器学习
Huawei Hongmeng OS, is it OK?
Go language web development is very simple: use templates to separate views from logic
【LeetCode】Day92-盛最多水的容器
Reading notes of cgnf: conditional graph neural fields
js判断移动端还是pc端
Generics and generic constraints of typescript
软件测试 - 概念篇
正则表达式总结
PHP array to XML
PHP parent
"Simple" infinite magic cube
深度学习分类网络 -- AlexNet
500. 键盘行