当前位置:网站首页>led闪烁
led闪烁
2022-07-30 05:46:00 【缘聚654】
首先开始的操作是与上个博客相同的,先在keil中创建一个新的项目,可以命名为led闪烁。

然后在main文件中输入如下代码
#include <REGX52.H>
#include <INTRINS.H>
void Delay500ms() //@11.0592MHz
{
unsigned char i, j, k;
_nop_();
i = 4;
j = 129;
k = 119;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
void main()
{
while(1)
{
P2=0xFE;
Delay500ms();
P2=0xFF;
Delay500ms();
}
}可以看到这与点亮led的代码相比长了许多,下面我来解释一下代码的作用。
首先main函数是主体,通过使用while循环以及P2=0xFE;P2=0xFF;来控制灯的亮灭;但因为代码运行速度很快,肉眼无法观察到懂得亮灭,只能看到灯的亮度减弱;这是需要在代码间加入一些其他函数来延长灯亮灭的间隔;这时我们需要使用stc,它提供了软件延时计算器来生成我们所要使用的代码。

在选项里选择自己需要的然后点击生成代码就OK了。
然后在stc中打开相应的文件,点击编程,并对单片机进行冷启动就可以看到指示灯以0.5秒为间隔亮灭。
同时stc显示操作成功。
边栏推荐
- 《C陷阱和缺陷》void (*signal(int , void(*)(int)))(int)的深刻解读
- sizeof和strlen最全区别,以及指针和数组运算解析
- xxx is not in the sudoers file.This incident will be reported error
- 工程师必看:常见的PCB检测方法有哪些?
- 【江科大自化协stm32F103c8t6】笔记之【入门32单片机及GPIO初始化参数配置】
- Kunlun State Screen Production (Serialization 5) --- Basics (serial port reception, text and light display)
- Three working modes of CPU: real mode, protected mode, long mode
- this的指向问题
- Explore the efficiency of make_shared
- ES6语法笔记(ES6~ES11)
猜你喜欢

SSH-RSA密钥
![[Quick MSP430f149] Notes on learning MSP430f149 during the game](/img/06/741c609b24be007718091b8348666c.png)
[Quick MSP430f149] Notes on learning MSP430f149 during the game

ES6 syntax notes (ES6~ES11)

QT serial port dynamically displays a large number of data waveform curves in real time (5) ======== "Final perfect solution version"

BLDC电机应用持续火爆,“网红神器”筋膜枪前景几何?

VsCode打开终端的方法
![[Jiangsu University of Science and Technology Automation Association stm32F103c8t6] Notes [Initial 32 MCU and TIM timing interrupt initialization parameter configuration]](/img/22/9c0dd4390a98fa2aa4e45164c078cc.png)
[Jiangsu University of Science and Technology Automation Association stm32F103c8t6] Notes [Initial 32 MCU and TIM timing interrupt initialization parameter configuration]

CPU缓存一致性问题

与所有 ARM 工具、软件兼容?韦斯佰瑞这款MCU内核值得关注!

二进制到汇编:进制,原码反码补码,位运算,通用寄存器,内存一套打通
随机推荐
QT连载2:基于QT和STM32H750的LORA试验平台(1)
关于map对key自定义排序
pdf和word等文档添加水印
The most complete difference between sizeof and strlen, as well as pointer and array operation analysis
Explore the efficiency of make_shared
[Common usage of markdown]
顺序二叉树---实现数组的二叉树前序遍历输出
openssl1.1.1ARM dual compilation
VsCode打开终端的方法
The IEEE under the specified journal search related papers
vs compile boost library script
QT Weekly Skills (1) ~~~~~~~~~ Running Icon
华秋电子成为开放原子开源基金会openDACS捐赠人,共建 openDACS开源生态
【江科大自化协stm32F103c8t6】笔记之【入门32单片机及利用TIM输出比较配置PWM】
HSPF model application
关于报错vscode
Vim查找字符
TCP建立连接的过程
爬2.12.6的Antd上传图片坑
昆仑通态屏幕制作(连载1)---接触篇