当前位置:网站首页>外部中断无法进入,删代码再还原就好......记录这个想不到的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次,为了方便,会将其优化放到寄存器里面,每次取寄存器即可,不用再一遍一遍的访问内存单元。而则这样的优化在有时候就会出现意想不到的错误。
边栏推荐
- PHP array to XML
- Zzuli: maximum Convention and minimum common multiple
- Addchild() and addattribute() functions in PHP
- 492.构造矩形
- Grbl software: basic knowledge of simple explanation
- php内类名称与类内方法名相同
- Fundamentals of software testing
- Zzuli:1066 character classification statistics
- [Chongqing Guangdong education] selected reading reference materials of British and American literature of Nanyang Normal University
- 我所理解的DRM显示框架
猜你喜欢

《CGNF: CONDITIONAL GRAPH NEURAL FIELDS》阅读笔记

15 C language advanced dynamic memory management
![[technical notes-08]](/img/52/0aff21b01ba7adbfcdb597d1aa85f9.png)
[technical notes-08]

Record sentry's path of stepping on the pit

vite如何兼容低版本浏览器

在线音乐播放器app

Balsamiq wireframes free installation
![[golang syntax] be careful with the copy of slices](/img/5e/1c82c58940939b94d03377ebdc03e3.jpg)
[golang syntax] be careful with the copy of slices

Gcnet: non - local Networks meet Squeeze excitation Networks and Beyond

Software testing - concept
随机推荐
php继承(extends)
3D 打印机 G 代码命令:完整列表和教程
Cambrian was reduced by Paleozoic venture capital and Zhike shengxun: a total of more than 700million cash
《CGNF: CONDITIONAL GRAPH NEURAL FIELDS》阅读笔记
PHP inner class name is the same as the inner class method name
PHP gets CPU usage, hard disk usage, and memory usage
php内的addChild()、addAttribute()函数
Stick to the big screen UI, finereport development diary
all3dp.com网站中全部Arduino项目(2022.7.1)
Conglin environmental protection rushes to the scientific and Technological Innovation Board: it plans to raise 2billion yuan, with an annual profit of more than 200million yuan
idea開發工具常用的插件合集匯總
PHP array to XML
Zzuli:1061 sequential output of digits
Regular expression summary
1036 Boys vs Girls
“简单”的无限魔方
PHP read file (read the specified line containing a string in the file)
Uva548 tree
Zzuli:1062 greatest common divisor
Reading notes of cgnf: conditional graph neural fields