Header file for using the MC68HC68T1 Real Time Clock on the 68HC11 EVBU connected to the HC11 through the SPI.


/****************************************************************************
 *                      rtc.h 
 *
 *  Header file for using the MC68HC68T1 Real Time Clock on the 68HC11 EVBU
 *  connected to the HC11 through the SPI.
 ****************************************************************************/
/*
 * Addresses of registers in the RTC
 */
#define RTC_SEC_READ          0x20
#define RTC_MIN_READ          0x21
#define RTC_HOUR_READ         0x22
#define RTC_DOW_READ          0x23
#define RTC_DOM_READ          0x24
#define RTC_MONTH_READ        0x25
#define RTC_YEAR_READ         0x26
#define RTC_STATUS_READ       0x30
#define RTC_CLK_CONTROL_READ  0x31
#define RTC_INT_CONTROL_READ  0x32
#define RTC_SEC_WRITE         0xa0
#define RTC_MIN_WRITE         0xa1
#define RTC_HOUR_WRITE        0xa2
#define RTC_DOW_WRITE         0xa3
#define RTC_DOM_WRITE         0xa4
#define RTC_MONTH_WRITE       0xa5
#define RTC_YEAR_WRITE        0xa6
#define RTC_ALARM_SEC_WRITE   0xa8
#define RTC_ALARM_MIN_WRITE   0xa9
#define RTC_ALARM_HOUR_WRITE  0xaa
#define RTC_CLK_CONTROL_WRITE 0xb1
#define RTC_INT_CONTROL_WRITE 0xb2

/* Definition of bits in RTC Clock Control Register */
#define RTC_CLOCKON           0x80
#define RTC_LINE              0x40
#define RTC_XTAL_4MHZ         0x00
#define RTC_XTAL_2MHZ         0x10
#define RTC_XTAL_1MHZ         0x20
#define RTC_XTAL_32KHZ        0x30
#define RTC_LINE_50HZ         0x08
#define RTC_CLKOUT_XTAL       0x00
#define RTC_CLKOUT_XTAL_DIV2  0x01
#define RTC_CLKOUT_XTAL_DIV4  0x02
#define RTC_CLKOUT_XTAL_DIV8  0x03
#define RTC_CLKOUT_DISABLE    0x04
#define RTC_CLKOUT_1HZ        0x05
#define RTC_CLKOUT_2HZ        0x06
#define RTC_CLKOUT_LINE_HZ    0x07
#define RTC_CLKOUT_64_HZ      0x07

/* Definition of bits in RTC Interrupt Control Register */
#define RTC_INT_WATCHDOG      0x80
#define RTC_INT_POWER_DOWN    0x40
#define RTC_INT_POWER_SENSE   0x20
#define RTC_INT_POWER_ALARM   0x10
#define RTC_PERIODIC_DISABLE  0x00
#define RTC_PERIODIC_2048HZ   0x01
#define RTC_PERIODIC_1024HZ   0x02
#define RTC_PERIODIC_512HZ    0x03
#define RTC_PERIODIC_256HZ    0x04
#define RTC_PERIODIC_128HZ    0x05
#define RTC_PERIODIC_64HZ     0x06
#define RTC_PERIODIC_LINE_HZ  0x06
#define RTC_PERIODIC_32HZ     0x07
#define RTC_PERIODIC_16HZ     0x08
#define RTC_PERIODIC_8HZ      0x09
#define RTC_PERIODIC_4HZ      0x0a
#define RTC_PERIODIC_2HZ      0x0b
#define RTC_PERIODIC_1HZ      0x0c
#define RTC_PERIODIC_1PERMIN  0x0d
#define RTC_PERIODIC_1PERHOUR 0x0e
#define RTC_PERIODIC_1PERDAY  0x0f

/*
 * Definition of structure to access the RTC registers
 */
struct rtc_regs
{
    unsigned char sec;
    unsigned char min;
    unsigned char hour;
    unsigned char dow;
    unsigned char dom;
    unsigned char month;
    unsigned char year;
    unsigned char nu1;
    unsigned char alarm_sec;
    unsigned char alarm_min;
    unsigned char alarm_hour;
    unsigned char nu2;
    unsigned char nu3;
    unsigned char nu4;
    unsigned char nu5;
    unsigned char nu6;
    unsigned char status;
    unsigned char clk_control;
    unsigned char int_control;
};

/*
 * Function prototypes for RTC.
 */
int read_rtc_reg(unsigned char reg);
int write_rtc_reg(unsigned char byte, unsigned char reg);
void read_rtc(struct rtc_regs *r);
void write_rtc(struct rtc_regs *r);

/*
 * To add the above functions (defined in the file rtc.c) to libhc11.a:
 *
 *     icc11 -c rtc.c
 *     ilib -a libhc11.a rtc.o
 *
 * To compile a program which uses the functions (e.g., rtc_ex.c), include the
 * header file "rtc.h" and compile with:
 *
 *     icc11 -l rtc_ex.c -l libhc11.a -b:text=0x2000 -bdata:0x0100 -d_stack:0x9fff
 *
 */