当前位置:网站首页>外部中断无法进入,删代码再还原就好......记录这个想不到的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次,为了方便,会将其优化放到寄存器里面,每次取寄存器即可,不用再一遍一遍的访问内存单元。而则这样的优化在有时候就会出现意想不到的错误。
边栏推荐
- Vscode paste image plugin saves image path settings
- “简单”的无限魔方
- Practice C language advanced address book design
- Here comes a new chapter in the series of data conversion when exporting with easyexcel!
- Minimum value ruler method for the length of continuous subsequences whose sum is not less than s
- PHP inner class name is the same as the inner class method name
- Software testing - concept
- 2022-2-14 learning xiangniuke project - section 23, section 5, development login and exit functions
- RGB 无限立方体(高级版)
- token过期自动续费方案和实现
猜你喜欢

Opencv LBP features

OLED12864 液晶屏

Pytorch Basics

idea开发工具常用的插件合集汇总

3D printer G code command: complete list and tutorial

Alibaba: open source and self-developed liquid cooling data center technology

Practice C language advanced address book design

【论文翻译】GCNet: Non-local Networks Meet Squeeze-Excitation Networks and Beyond

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

深度学习分类网络--Network in Network
随机推荐
460. LFU 缓存 双向链表
Go language web development is very simple: use templates to separate views from logic
Summary of MySQL constraints
2022-2-14 learning xiangniuke project - Section 7 account setting
数据库学习总结5
Can't the dist packaged by vite be opened directly in the browser
5g market trend in 2020
Online music player app
Brew install * failed, solution
1037 Magic Coupon
《CGNF: CONDITIONAL GRAPH NEURAL FIELDS》阅读笔记
Thread pool overview
页面打印插件print.js
Zzuli:1060 numbers in reverse order
[PHP是否安装了 SOAP 扩]对于php实现soap代理的一个常见问题:Class ‘SoapClient‘ not found in PHP的处理方法
2022-2-15 learning xiangniuke project - Section 8 check login status
How to change the IP address of computer mobile phone simulator
Software testing - concept
servlet的web.xml配置详解(3.0)
Regular expression summary