📄 clock.c
字号:
//###########################################################################
//
// FILE: Clock.c
//
// TITLE: DS12C887 Clock Initialization & Support Functions.
//
//###########################################################################
//
// Ver | dd mmm yyyy | Who | Description of changes
// =====|=============|======|===============================================
// 1.0 | 20 May 2005 | CY.L.| Release
//###########################################################################
#include "DSP28_Device.h"
#include "DSP28_Globalprototypes.h"
//===========================================================================
// followed routines to Clock 12C887
//===========================================================================
void Time_on(void)
/*函数功能:启动实时时钟,并设置数据格式为BCD码,24小时方式*/
{
Uint16 *pRt_Acs_Addr,*pRt_Dcs_Addr;
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x0a; //latch the address of register A
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
(*pRt_Dcs_Addr)=0x20;
//
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x0b; //latch the address of register B
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
(*pRt_Dcs_Addr)=0x82;
delay_loop( );
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x0b; //latch the address of register B
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
(*pRt_Dcs_Addr)=0x02; //start clock
}
void SetClockDefault(void)
{
Uint16 *pRt_Acs_Addr,*pRt_Dcs_Addr;
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x0b; //latch the address of register B
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
(*pRt_Dcs_Addr)=(*pRt_Dcs_Addr)| 0x80; //write a data to register B
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x0e; //latch the address of register A
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
(*pRt_Dcs_Addr)=0x20; //set yearh
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x09; //latch the address of year
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
(*pRt_Dcs_Addr)=0x02; //set yearl;
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x08; //latch the address of year
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
(*pRt_Dcs_Addr)=0x10; //set Month;
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x07; //latch the address of year
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
(*pRt_Dcs_Addr)=0x13; //set Day;
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x04; //latch the address of year
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
(*pRt_Dcs_Addr)=0x15; //set Hour;
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x02; //latch the address of year
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
(*pRt_Dcs_Addr)=0x43; //set Miunte;
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x00; //latch the address of year
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
(*pRt_Dcs_Addr)=0x00; //set Second;
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x0b; //latch the address of register B
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
(*pRt_Dcs_Addr)=(*pRt_Dcs_Addr) & 0x7f; //write a data to register B
}
void SetClock(void)
{
Uint16 *pRt_Acs_Addr,*pRt_Dcs_Addr;
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x0b; //latch the address of register B
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
(*pRt_Dcs_Addr)=(*pRt_Dcs_Addr)| 0x80; //write a data to register B
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x0e; //latch the address of register A
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
(*pRt_Dcs_Addr)=Clock.Yearh; //set yearh
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x09; //latch the address of year
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
(*pRt_Dcs_Addr)=Clock.Yearl; //set yearl;
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x08; //latch the address of year
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
(*pRt_Dcs_Addr)=Clock.Month; //set Month;
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x07; //latch the address of year
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
(*pRt_Dcs_Addr)=Clock.Day; //set Day;
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x04; //latch the address of year
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
(*pRt_Dcs_Addr)=Clock.Hour; //set Hour;
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x02; //latch the address of year
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
(*pRt_Dcs_Addr)=Clock.Minute; //set Miunte;
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x00; //latch the address of year
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
(*pRt_Dcs_Addr)=Clock.Second; //set Second;
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x0b; //latch the address of register B
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
(*pRt_Dcs_Addr)=(*pRt_Dcs_Addr) & 0x7f; //write a data to register B
}
void ReadClock(void)
{
Uint16 *pRt_Acs_Addr,*pRt_Dcs_Addr;
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x0e; //latch the address of century
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
Clock.Yearh=((*pRt_Dcs_Addr) & 0x0ff); //read Yearh
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x09; //latch the address of year
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
Clock.Yearl=((*pRt_Dcs_Addr) & 0x0ff); //read Yearl; //set Yearl;
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x08; //latch the address of year
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
Clock.Month=((*pRt_Dcs_Addr) & 0x0ff); //set Month;
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x07; //latch the address of year
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
Clock.Day=((*pRt_Dcs_Addr) & 0x0ff); //set Day;
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x04; //latch the address of year
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
Clock.Hour=((*pRt_Dcs_Addr) & 0x0ff); //set Hour;
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x02; //latch the address of year
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
Clock.Minute=((*pRt_Dcs_Addr) & 0x0ff); //set Miunte;
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x00; //latch the address of year
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
Clock.Second=((*pRt_Dcs_Addr) & 0x0ff); //set Second;
}
void set_century(Uint16 _data)
/*函数功能:设置世纪*/
/*参 数:_data:世纪:0--99*/
{
Uint16 *pRt_Acs_Addr,*pRt_Dcs_Addr;
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x0b; //latch the address of register B
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
(*pRt_Dcs_Addr)=(*pRt_Dcs_Addr)| 0x80; //write a data to register B
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x0e; //latch the address of register A
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
(*pRt_Dcs_Addr)=_data; //write the _data to register century
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x0b; //latch the address of register B
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
(*pRt_Dcs_Addr)=(*pRt_Dcs_Addr) & 0x7f; //write a data to register B
}
void set_year(Uint16 _data)
/*函数功能:设置年*/
/*参 数:_data:年:0--99*/
{
Uint16 *pRt_Acs_Addr,*pRt_Dcs_Addr;
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x0b; //latch the address of register B
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
(*pRt_Dcs_Addr)=(*pRt_Dcs_Addr)| 0x80; //write a data to register B
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x09; //latch the address of year
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
(*pRt_Dcs_Addr)=_data; //write the _data to year
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x0b; //latch the address of register B
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
(*pRt_Dcs_Addr)=(*pRt_Dcs_Addr)& 0x7f; //write a data to register B
}
void set_month(Uint16 _data)
/*函数功能:设置月*/
/*参 数:_data:月:1--12*/
{
Uint16 *pRt_Acs_Addr,*pRt_Dcs_Addr;
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x0e; //latch the address of register B
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
(*pRt_Dcs_Addr)=(*pRt_Dcs_Addr)| 0x80; //write a data to register B
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x08; //latch the address of month
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
(*pRt_Dcs_Addr)=_data; //write the _data to month
pRt_Acs_Addr =(Uint16 *)ADD_RT_ACS;
(*pRt_Acs_Addr)=0x0b; //latch the address of register B
pRt_Dcs_Addr =(Uint16 *)ADD_RT_DCS;
(*pRt_Dcs_Addr)=(*pRt_Dcs_Addr)& 0x7f; //write a data to register B
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -