本文实例为大家分享了C语言实现定时器控制LED灯闪烁的具体代码,供大家参考,具体内容如下
实现效果如图:

周期:2s;

LED引脚为P2口。
?| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
#include<reg52.h>
void Delay_1s(void)
{
unsigned char i;
for(i=0;i<20;i++)
{
//2的6次方=655136
TH1=0x3C;//655136-50000=155146==>0x3CB0
TL1=0xB0;
TR1=1;//启动定时器,开始计时
while(!TF1);//判断定时器是否溢出
TF1=0; //溢出时清0,进行下次计时
}
}
int main(void)
{
unsigned int LED;
TMOD=0x10;
LED=0x00;
P2=LED;
Delay_1s();
P2=~(LED);
Delay_1s();
return 0;
}
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/weixin_53391957/article/details/115471667








发表评论
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。