📄 timer.c
字号:
/*************************************************************
WPD800 时钟处理
修改历史 2007-10-9 zaken create version 1.0
*************************************************************/
#include "config.h"
#include "target.h"
#include "main.h"
#include "timer.h"
volatile TDATE g_tDate;//系统时间
//初始化时钟
void Timer_Init(void)
{
DWORD time,date;
PREINT = Fpclk / 32768 - 1; // 设置基准时钟分频器
PREFRAC = Fpclk - (Fpclk / 32768) * 32768;
CIIR =0;//不使用中断
ILR=0x03;//清除中断标志
//读出时间
time=CTIME0;
date=CTIME1;
g_tDate.ms=(time&0x3f)*1000;
g_tDate.min=((time>>8)&0x3f);
g_tDate.hour=((time>>16)&0x3f);
// g_tDate.week=((time>>24)&0x3f);
g_tDate.day=(date&0x3f);
g_tDate.month=((date>>8)&0x3f);
g_tDate.year=((date>>16)&0x3f);
CCR=0x01;//启动时间计数器
}
void Timer_Read(TDATE *pDate)
{
DWORD time,date;
time=CTIME0;
date=CTIME1;
pDate->ms=(time&0x3f)*1000;
pDate->min=((time>>8)&0x3f);
pDate->hour=((time>>16)&0x3f);
// pDate->week=((time>>24)&0x3f);
pDate->day=(date&0x3f);
pDate->month=((date>>8)&0x3f);
pDate->year=((date>>16)&0x3f);
}
int Timer_Write(TDATE *pDate)
{
//合法性判断
if(pDate->year>2050 || pDate->year <1950)
{
return ERROR;
}
if(pDate->month>12 || pDate->month==0)
{
return ERROR;
}
if(pDate->day>31 || pDate->day==0)
{
return ERROR;
}
if(pDate->hour>23)
{
return ERROR;
}
if(pDate->min>59)
{
return ERROR;
}
if(pDate->ms>59999)
{
return ERROR;
}
CCR=0x02;//复位RTC 禁止时钟计数器
//写入时间
g_tDate=*pDate;
YEAR=pDate->year;
MONTH=pDate->month;
DOM=pDate->day;
HOUR=pDate->hour;
MIN=pDate->min;
SEC=pDate->ms/1000;
CCR=0x01;//启动时间计数器
return OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -