📄 timer.c
字号:
#include "iom8515v.h"
#include "macros.h"
#include "MAIN.h"
#pragma interrupt_handler Timer0OverInter:8
uint LightCount=0;
uchar KeyTime=0;
uchar Key1,Key2,Key3;
uchar KeyStatus=0;
/*****************************************
读按键输入口子程序
******************************************/
uchar KeyInput(uchar BitData)
{
uchar KeyData;
KeyData=(PIND &= (1 << BitData ));
if(KeyData == 0)
return(1);
else
return(0);
}
void Timer0Ini(void)
{
TCCR0 = 0x00;
TCNT0 = 0xC2; //定时1ms
TCCR0 = 0x04; //256分频
TIMSK = 0x02; //开定时器0溢出中断
}
void Timer0OverInter(void)
{
TCNT0 = 0xC2; //恢复定时器初值
KeyTime++; //按键间隔时间计数器累加
LightCount++;
if(KeyTime == 6) //取6ms的时间间隔
{
KeyTime=0;
if((Key1 == 0) && (Key2 == 1) && (Key3 == 1))
//如果按键的前后三次状态分别是0、1、1的话,则认为有键按下
KeyStatus=1; //置位状态标志
else
KeyStatus=0; //否则清0状态标志
Key1=Key2;
Key2=Key3;
}
/*************************************************
if(UartOverTime>0)
{
UartOverTime--;
if(UartOverTime==0)
UartStatus=0;
}
*************************************************/
if(LightCount == 1000) //状态灯控制
{
PORTD ^= BIT(4);
LightCount=0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -