新闻中心

EEPW首页>嵌入式系统>设计应用> 单片机精华之利用内置定时器对外部按键进行计数

单片机精华之利用内置定时器对外部按键进行计数

作者: 时间:2016-11-21 来源:网络 收藏
问题描述:

前面焊好的板子,按键按下10次以后,点亮led

本文引用地址://m.amcfsurvey.com/article/201611/319250.htm

上代码:

#include

sbit led = P1^0;

unsigned int counter = 0;

void init(void)
{
led = 0;
TMOD = 0x06;// counter and 8-bit auto-reload
TH0 = 256 - 1;
TL0 = 256 - 1;
ET0 = 1;
EA = 1;
TR0 = 1;
}

void key_counter()interrupt1
{
counter ++;
if(counter >= 3)
{
led = 1;
}
if(counter >=6)
{
counter = 0;
}

}


void main()
{
init();
while(1);
}

注意此时外部脉冲输入的界限是P3.4口



评论


技术专区

关闭