标题: 单片机C语言程序设计:定时器控制单只LED [打印本页]

作者: tpkeeper    时间: 2016-12-14 18:44
标题: 单片机C语言程序设计:定时器控制单只LED

  名称:定时器控制单只 LED

说明:LED 在定时器的中断例程控制下不断闪烁。

*/

#include<reg51.h>

#define uchar unsigned char

#define uint unsigned int

sbit LED=P0^0;

uchar T_Count=0;

//主程序

void main()

{



TMOD=0x00;

//定时器 0 工作方式 0



TH0=(8192-5000)/32; //5ms 定时

TL0=(8192-5000)%32;

                IE=0x82;       //允许 T0 中断

                     TR0=1;

             while(1);




}



//T0 中断函数

void LED_Flash() interrupt 1

{

TH0=(8192-5000)/32; //恢复初值

TL0=(8192-5000)%32;

if(++T_Count==100)//0.5s 开关一次 LED

{

LED=~LED;

T_Count=0;

}

}




作者: 朱玉荣    时间: 2016-12-14 19:14
好棒啊




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1