73 lines
1.6 KiB
C
73 lines
1.6 KiB
C
#include "H/Function_Init.H"
|
||
|
||
void Timer_Init(void);
|
||
|
||
uint Time_Key0_Press;//按键0保持时间
|
||
uint Time_Key1_Press;//按键1保持时间
|
||
|
||
/*****************************************************
|
||
*函数名称:void Timer_Test(void);
|
||
*函数功能:T0/T1/T2测试
|
||
*入口参数:void
|
||
*出口参数:void
|
||
*****************************************************/
|
||
void Timer_Test(void)
|
||
{
|
||
Timer_Init();
|
||
Time_Key0_Press = 0;
|
||
Time_Key1_Press = 0;
|
||
}
|
||
/*****************************************************
|
||
*函数名称:void Timer_Init(void)
|
||
*函数功能:T0/T1/T2初始化
|
||
*入口参数:void
|
||
*出口参数:void
|
||
*****************************************************/
|
||
void Timer_Init(void)
|
||
{
|
||
TMCON = 0X01; //------111 ;Timer0、Tiemr1和Tiemr2选择时钟Fsys
|
||
|
||
//T0设置,现象:P02输出频率为1K的方波(主频:32M)
|
||
TMOD |= 0x01; //0000 0001;Timer0设置工作方式1
|
||
TL0 = (65536 - 32000)%256; //时钟为Fsys,则溢出时间=16000*(1/Fsys);
|
||
TH0 = (65536 - 32000)/256;
|
||
TR0 = 0;
|
||
ET0 = 1;//定时器0允许
|
||
TR0 = 1;//打开定时器0
|
||
}
|
||
|
||
/**************************************************
|
||
*函数名称:void timer0/1/2/3/4() interrupt 1/3/5/13/14
|
||
*函数功能:定时器中断产生方波
|
||
*入口参数:void
|
||
*出口参数:void
|
||
**************************************************/
|
||
void timer0() interrupt 1
|
||
{
|
||
TL0 = (65536 - 32000)%256; //手动重装载值低8位
|
||
TH0 = (65536 - 32000)/256; //手动重装载值高8位
|
||
if(!Key0)
|
||
Time_Key0_Press++;
|
||
else
|
||
Time_Key0_Press=0;
|
||
|
||
if(Time_Key0_Press>=3000)//等三秒让数据收拢
|
||
{
|
||
Time_Key0_Press = 0;
|
||
Key0_flag = 1;
|
||
}
|
||
|
||
if(!Key1)
|
||
Time_Key1_Press++;
|
||
else
|
||
Time_Key1_Press=0;
|
||
|
||
if(Time_Key1_Press>=3000)
|
||
{
|
||
Time_Key1_Press = 0;
|
||
Key1_flag = 1;
|
||
}
|
||
|
||
}
|
||
|