📄 drv_rtc.c
字号:
/********************************************************************************************************
* *
* Copyright (C) SEIKO EPSON CORP. 2002 *
* *
* File name: Drv_RTC.c *
* This is RTC driver for c33 star. *
* *
* Revision history *
* 2002.06.4 Andrew Yin Start. *
* *
*******************************************************************************************************/
#include "common.h"
#include "ct.h"
#include "int.h"
// Prototype
void vInitRTC( unsigned char, unsigned char, unsigned short );
void vRTCStart( void );
void vRTCStop( void );
void vIntRTC( void );
unsigned char ucRTCReadSecond( void );
unsigned char ucRTCReadMinute( void );
unsigned char ucRTCReadHour( void );
unsigned short usRTCReadDay( void );
unsigned char gucSecond;
unsigned char gucMinute;
unsigned char gucHour;
unsigned short gusDay;
unsigned char gucRTCSecondFlag;
/*******************************************************************************
* vInitRTC
* Type : void
* Ret val : none
* Argument : unsigned char ,unsigned char, unsigned int.
* Function : Initialize RTC.
*******************************************************************************/
void vInitRTC( unsigned char ucMinute,unsigned char ucHour,unsigned short usDay )
{
// Setting clock timer interrupt disable
*( volatile unsigned char * )INT_EADE_ECTM_EP4_ADDR &= ~INT_ECTM;
// Setting clock timer stop
*( volatile unsigned char * )CT_TCRUN_ADDR &= 0x0FE;
// Reset the clock timer
*( volatile unsigned char * )CT_TCRUN_ADDR |= CT_TCRST_RST;
// Clock timer interrupt factor selection: rtc --> 1Hz, alarm --> none
*( volatile unsigned char * )CT_TCAF_ADDR = CT_TCISE_1HZ | CT_TCASE_NONE | CT_TCIF_RST | CT_TCAF_RST;
// Presetting the current day and time in the minute,hour,and day counters
*( volatile unsigned char * )CT_TCHD_ADDR = ucMinute;
*( volatile unsigned char * )CT_TCDD_ADDR = ucHour;
*( volatile unsigned char * )CT_TCNDL_ADDR = ( unsigned char )usDay;
*( volatile unsigned char * )CT_TCNDH_ADDR = ( unsigned char )( usDay >> 8 );
// Clear the Clock timer interrupt flag
*( volatile unsigned char * )INT_FADE_FCTM_FP4_ADDR |= INT_FCTM;
// Clock timer interrupt enable
*( volatile unsigned char * )INT_EADE_ECTM_EP4_ADDR |= INT_ECTM;
}
/*******************************************************************************
* vIntRTC
* Type : void
* Ret val : none
* Argument : void
* Function : 1 second interrupt
*******************************************************************************/
void vIntRTC( void )
{
asm("pushn %r15"); // save r1,r2...r15
asm("ld.w %r9,%psr"); // EI,enable interrupt
asm("or %r9,0x10");
asm("ld.w %psr,%r9");
gucSecond = ucRTCReadSecond( );
gucMinute = ucRTCReadMinute( );
gucHour = ucRTCReadHour( );
gusDay = usRTCReadDay( );
gucRTCSecondFlag = 1;
// Clear interrupt flag
*( volatile unsigned char * )INT_FADE_FCTM_FP4_ADDR |= INT_FCTM;
asm("popn %r15");
asm("reti");
}
/*******************************************************************************
* vRTCStart
* Type : void
* Ret val : none
* Argument : void
* Function : Run RTC
*******************************************************************************/
void vRTCStart( void )
{
gucSecond = 0;
*( volatile unsigned char * )CT_TCRUN_ADDR |= 0x01;
}
/*******************************************************************************
* vRTCStop
* Type : void
* Ret val : none
* Argument : void
* Function : Stop rtc.
*******************************************************************************/
void vRTCStop( void )
{
*( volatile unsigned char * )CT_TCRUN_ADDR = 0x0FE;
}
/*******************************************************************************
* ucRTCReadSecond
* Type : unsigned char
* Ret val : rtc value
* Argument : none
* Function : Read rtc value of second.
*******************************************************************************/
unsigned char ucRTCReadSecond( void )
{
return( *( volatile unsigned char * )CT_TCMD_ADDR);
}
/*******************************************************************************
* ucRTCReadMinute
* Type : unsigned char
* Ret val : rtc value
* Argument : none
* Function : Read rtc value of minute.
*******************************************************************************/
unsigned char ucRTCReadMinute( void )
{
return( *( volatile unsigned char * )CT_TCHD_ADDR);
}
/*******************************************************************************
* ucRTCReadHour
* Type : unsigned char
* Ret val : rtc value
* Argument : none
* Function : Read rtc value of hour.
*******************************************************************************/
unsigned char ucRTCReadHour( void )
{
return( *( volatile unsigned char * )CT_TCDD_ADDR);
}
/*******************************************************************************
* usRTCReadDay
* Type : unsigned char
* Ret val : rtc value
* Argument : none
* Function : Read rtc value of Day.
*******************************************************************************/
unsigned short usRTCReadDay( void )
{
unsigned short day;
day = *( volatile unsigned char * )CT_TCNDH_ADDR;
day <<= 8; //left shift 8 bit
day |= *( volatile unsigned char * )CT_TCNDL_ADDR;
return( day );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -