본문내용
f [0] & 0xF0) >> 4) * 10) + (rtbuf [0] & 0x0F);
rtc->secs = (((rtbuf [1] & 0x70) >> 4) * 10) + (rtbuf [1] & 0x0F);
rtc->minutes = (((rtbuf [2] & 0x70) >> 4) * 10) + (rtbuf [2] & 0x0F);
rtc->hours = (((rtbuf [3] & 0x30) >> 4) * 10) + (rtbuf [3] & 0x0F);
rtc->day = (rtbuf [4] & 0x07);
rtc->date = (((rtbuf [5] & 0x30) >> 4) * 10) + (rtbuf [5] & 0x0F);
rtc->month = (((rtbuf [6] & 0x10) >> 4) * 10) + (rtbuf [6] & 0x0F);
rtc->year = (((rtbuf [7] & 0xF0) >> 4) * 10) + (rtbuf [7] & 0x0F);
/*------------------------------------------------------------------------
------------------------------------------------------------------------*/
void rtclock_set (
struct rtclock_st *rtc)
{
unsigned char rtbuf [8];
register unsigned char i;
/*-----------------------------------------------
-----------------------------------------------*/
rtbuf [0] = (((rtc->hsecs / 10) & 0x0F) << 4) | (rtc->hsecs % 10);
rtbuf [1] = (((rtc->secs / 10) & 0x07) << 4) | (rtc->secs % 10);
rtbuf [2] = (((rtc->minutes / 10) & 0x07) << 4) | (rtc->minutes % 10);
rtbuf [3] = (((rtc->hours / 10) & 0x03) << 4) | (rtc->hours % 10);
rtbuf [4] = (rtc->day & 7);
rtbuf [5] = (((rtc->date / 10) & 0x03) << 4) | (rtc->date % 10);
rtbuf [6] = (((rtc->month / 10) & 0x01) << 4) | (rtc->month % 10);
rtbuf [7] = (((rtc->year / 10) & 0x0F) << 4) | (rtc->year % 10);
/*-----------------------------------------------
-----------------------------------------------*/
INT_SAVE;
INT_DISABLE;
rtc_reset ();
INT_RESTORE;
/*-----------------------------------------------
-----------------------------------------------*/
INT_SAVE;
INT_DISABLE;
rtc_init ();
for (i = 0; i < 8; i++)
{
rtc_write_byte (rtbuf [i]);
}
INT_RESTORE;
/*-----------------------------------------------
-----------------------------------------------*/
INT_SAVE;
INT_DISABLE;
rtc_reset ();
INT_RESTORE;
}
/*------------------------------------------------------------------------
------------------------------------------------------------------------*/
Rtclock.h Source
/*------------------------------------------------------------------------
RTCLOCK.C
real-time clock routines.
------------------------------------------------------------------------*/
/*------------------------------------------------
RTCLOCK.C
Routines to start, stop, read, and write the
internal real-time clock.
------------------------------------------------*/
struct rtclock_st
{
unsigned char hsecs; /* hundredths of seconds (00-99) */
unsigned char secs; /* seconds (00-59) */
unsigned char minutes; /* minutes (00-59) */
unsigned char hours; /* hours (00-23) */
unsigned char day; /* day of week (0-7) */
unsigned char date; /* date (00-31) */
unsigned char month; /* month (00-12) */
unsigned char year; /* year (00-99) */
};
extern code char *day_of_week [];
unsigned char rtc_read_byte (void);
void rtc_write_byte (
unsigned char val);
void rtclock_initialize (void);
void rtclock_stop (void);
void rtclock_get (
struct rtclock_st *rtc);
void rtclock_set (
struct rtclock_st *rtc);
rtc->secs = (((rtbuf [1] & 0x70) >> 4) * 10) + (rtbuf [1] & 0x0F);
rtc->minutes = (((rtbuf [2] & 0x70) >> 4) * 10) + (rtbuf [2] & 0x0F);
rtc->hours = (((rtbuf [3] & 0x30) >> 4) * 10) + (rtbuf [3] & 0x0F);
rtc->day = (rtbuf [4] & 0x07);
rtc->date = (((rtbuf [5] & 0x30) >> 4) * 10) + (rtbuf [5] & 0x0F);
rtc->month = (((rtbuf [6] & 0x10) >> 4) * 10) + (rtbuf [6] & 0x0F);
rtc->year = (((rtbuf [7] & 0xF0) >> 4) * 10) + (rtbuf [7] & 0x0F);
/*------------------------------------------------------------------------
------------------------------------------------------------------------*/
void rtclock_set (
struct rtclock_st *rtc)
{
unsigned char rtbuf [8];
register unsigned char i;
/*-----------------------------------------------
-----------------------------------------------*/
rtbuf [0] = (((rtc->hsecs / 10) & 0x0F) << 4) | (rtc->hsecs % 10);
rtbuf [1] = (((rtc->secs / 10) & 0x07) << 4) | (rtc->secs % 10);
rtbuf [2] = (((rtc->minutes / 10) & 0x07) << 4) | (rtc->minutes % 10);
rtbuf [3] = (((rtc->hours / 10) & 0x03) << 4) | (rtc->hours % 10);
rtbuf [4] = (rtc->day & 7);
rtbuf [5] = (((rtc->date / 10) & 0x03) << 4) | (rtc->date % 10);
rtbuf [6] = (((rtc->month / 10) & 0x01) << 4) | (rtc->month % 10);
rtbuf [7] = (((rtc->year / 10) & 0x0F) << 4) | (rtc->year % 10);
/*-----------------------------------------------
-----------------------------------------------*/
INT_SAVE;
INT_DISABLE;
rtc_reset ();
INT_RESTORE;
/*-----------------------------------------------
-----------------------------------------------*/
INT_SAVE;
INT_DISABLE;
rtc_init ();
for (i = 0; i < 8; i++)
{
rtc_write_byte (rtbuf [i]);
}
INT_RESTORE;
/*-----------------------------------------------
-----------------------------------------------*/
INT_SAVE;
INT_DISABLE;
rtc_reset ();
INT_RESTORE;
}
/*------------------------------------------------------------------------
------------------------------------------------------------------------*/
Rtclock.h Source
/*------------------------------------------------------------------------
RTCLOCK.C
real-time clock routines.
------------------------------------------------------------------------*/
/*------------------------------------------------
RTCLOCK.C
Routines to start, stop, read, and write the
internal real-time clock.
------------------------------------------------*/
struct rtclock_st
{
unsigned char hsecs; /* hundredths of seconds (00-99) */
unsigned char secs; /* seconds (00-59) */
unsigned char minutes; /* minutes (00-59) */
unsigned char hours; /* hours (00-23) */
unsigned char day; /* day of week (0-7) */
unsigned char date; /* date (00-31) */
unsigned char month; /* month (00-12) */
unsigned char year; /* year (00-99) */
};
extern code char *day_of_week [];
unsigned char rtc_read_byte (void);
void rtc_write_byte (
unsigned char val);
void rtclock_initialize (void);
void rtclock_stop (void);
void rtclock_get (
struct rtclock_st *rtc);
void rtclock_set (
struct rtclock_st *rtc);
소개글