📄 12c887.c
字号:
//*************************************************************************************************
// Module Name : 12C887.C
// CreateDate : 2005-01-09
// ModifData : 2005-05-05
// Description :
// Author : 李远正
// Version : V1.0
//*************************************************************************************************
#include <absacc.h>
#include "12C887.H"
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
// 设置系统时间
void Setup12C887( unsigned char *p )
{
unsigned char i;
for ( i=0; i<20; i++ ) { temp = RTC_REGA; if ( (temp&0x80) == 0 ) break; } // Wait for ...
RTC_REGA = 0x70;
RTC_REGB = 0xa2;
RTC_SEC = *p++;
RTC_SEC_ALM = 0xff;
RTC_MIN = *p++;
RTC_MIN_ALM = 0xff;
RTC_HOU = *p++;
RTC_HOU_ALM = 0xff;
RTC_DAY_WEK = *p++;
RTC_DAY_MON = *p++;
RTC_MON = *p++;
RTC_YEAR = *p++;
RTC_REGB = 0x26;
RTC_REGA = 0x20;
}
//-------------------------------------------------------------------------------------------------
// 读取系统时间
void Read12C887( unsigned char *p )
{
unsigned char i;
for ( i=0; i<20; i++ ) { temp = RTC_REGA; if ( (temp&0x80) == 0 ) break; } // Wait for ...
*p++ = RTC_SEC;
*p++ = RTC_MIN;
*p++ = RTC_HOU;
*p++ = RTC_DAY_WEK;
*p++ = RTC_DAY_MON;
*p++ = RTC_MON;
*p++ = RTC_YEAR;
}
//-------------------------------------------------------------------------------------------------
// 启动时钟
void Start12C887( void )
{
RTC_REGA = 0x70; // 开启晶体振荡器
RTC_REGB = 0xa2; // 禁止芯片更新,允许闹钟中断,二进制输出,设置为24小时制
RTC_SEC_ALM = 0xff; // 清闹钟
RTC_MIN_ALM = 0xff;
RTC_HOU_ALM = 0xff;
RTC_REGB = 0x26; // 允许更新
RTC_REGA = 0x20; // 晶体振荡器开启并保持时钟运行
}
//=================================================================================================
// 将一个字节写入12c887的RAM
void Write12C887RAM( unsigned int address,unsigned char datum )
{
unsigned char xdata *p;
unsigned char i;
for ( i=0; i<20; i++ ) { temp = RTC_REGA; if ( (temp&0x80) == 0 ) break; } // Wait for ...
p = (unsigned char xdata *)address;
*p = datum;
}
//-------------------------------------------------------------------------------------------------
// 从RAM中读出一个字节
unsigned char Read12C887RAM( unsigned int address )
{
unsigned char xdata *p;
unsigned char i;
for ( i=0; i<20; i++ ) { temp = RTC_REGA; if ( (temp&0x80) == 0 ) break; } // Wait for ...
p = (unsigned char xdata *)address;
temp = *p;
return ( temp );
}
//=================================================================================================
// Select one of the 13 taps on the 15–stage divider
// or disable the divider output.
// Generate an output square wave (SQW)
void SetSQW( unsigned char frequency )
{
temp = RTC_REGA;
temp &= 0xF0;
temp |= frequency;
RTC_REGA = temp;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -