博客
关于我
STC89C52单片机 使用定时器使LED灯闪烁
阅读量:541 次
发布时间:2019-03-07

本文共 644 字,大约阅读时间需要 2 分钟。

#include 
#include
#define uint unsigned int#define uchar unsigned charLED1 = P1^0; // LED1void timer1Init() { TR1 = 1; // 启动定时器1 TMOD |= 0X10; // 定时器1工作模式1,16位定时模式 TH1 = 0x4b; TL1 = 0xfd; // 定时50ms}void main() { uchar mSec; // 毫秒储存变量 timer1Init(); // 定时器1初始化 while(1) { if(TF1 == 1) { // 判断是否溢出 TF1 = 0; // 软件清零溢出标志位 TH1 = 0x4b; TL1 = 0xfd; // 定时50ms mSec++; if(mSec == 10) { // 定时50毫秒到 mSec = 0; LED1 = ~LED1; // 产生方波 } } }}

以上代码经过优化,已去除不必要的空格和注释,同时保持了代码的可读性和功能性。建议在使用前请结合实际开发环境进行测试和调整。

转载地址:http://fqccz.baihongyu.com/

你可能感兴趣的文章
python中argparse模块关于 parse_args() 函数详解(全)
查看>>
python中base64编码与解码
查看>>
python中break怎么用_详解Python中break语句的用法
查看>>
python中del函数的垃圾回收
查看>>
Python中DrissionPage的详细解析与实战
查看>>
python中enumerate、变量类型转换
查看>>
python中execute是啥_python – 为什么“c.execute(…)”打破循环?
查看>>
python中exit和break区别_Python中exit()和sys.exit()之间的区别
查看>>
python中h5的用法
查看>>
python中http协议编程_HTTP编程
查看>>
python中if的效率_python中关于if-else使用性能的一点感悟
查看>>
python中import os_Python:相对导入与绝对导入(import)、os.path、__file__
查看>>
python中is和==操作符
查看>>
Python中range对象的使用以及打印九九乘法表
查看>>
Python中set.discard和set.remove方法之间的运行时差异?
查看>>
python中tkinter中value_输入字段中的python Tkinter get()值
查看>>
Python中wx.FlexGridSizer
查看>>
Python中xPath技术和BeautifulSoup的使用
查看>>
python中yield的用法详解——最简单,最清晰的解释
查看>>
python中‘set.intersection()‘的算法是什么?
查看>>