Weight_Bed/Timer_Init.c

73 lines
1.6 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}
}