?? timer._c
字號:
#include "iom8515v.h"
#include "macros.h"
#include "MAIN.h"
#include "UART.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 + -