博客
关于我
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/

你可能感兴趣的文章
promise总结
查看>>
Propel项目改为基于TensorFlow.js
查看>>
PyTorch-Tutorials【pytorch官方教程中英文详解】- 6 Autograd
查看>>
properties出现中文乱码解决方法(万能)
查看>>
Property 'submit' of object #<HTMLFormElement> is not a function
查看>>
property--staticmethod--classmethod
查看>>
propertyGrid
查看>>
propertyPlaceholderConfigurer读取配置文件
查看>>
PyTorch-Tutorials【pytorch官方教程中英文详解】- 5 Build Model
查看>>
proteus三输入与非门名字_proteus 元件名称对照表
查看>>
Protobuf - 语法、字段使用规则、注意事项
查看>>
protobuf —— 快速上手
查看>>
protobuf —— 认识和安装
查看>>
Protobuf 三个关键字required、optional、repeated的理解
查看>>
ProtoBuf 原理详解
查看>>
Protobuf 实例(java)
查看>>
ProtoBuf 实际应用(java)
查看>>