/*************************************************************************
* Ds1302Spi.h - Header file for Ds1302Spi.c, which demonstrates the use of
* the 68HC12 SPI for the DS1302 RTC.
*
* MCU: 68HC912B32, fE = 8MHz
*
* 03/09/01 Todd Morton
* rev 5/12/03 Reuben Brown
* 1. added address defines for Motovars Structure RAM storage
* 2. Changed SCK clock rate to 500kHz
/*************************************************************************
* General time structure
*************************************************************************/
typedef struct {
INT8U sec;
INT8U min;
INT8U hr;
INT8U dom;
INT8U month;
INT8U dow;
INT8U year;
} RTCCLK;
/*************************************************************************
* DS1302 command/address word definitions
*************************************************************************/
#define CNTLRD 0x8F /* Read control register */
#define CNTLWR 0x8E /* Write to control register */
#define SECRD 0x81 /* Read seconds register */
#define SECWR 0x80 /* Write to seconds register */
#define MINRD 0x83 /* Read minutes register */
#define MINWR 0x82 /* Write to minutes register */
#define HRRD 0x85 /* Read Hours register */
#define HRWR 0x84 /* Write to the hours register */
#define MONWR 0x88 /* Write to month register */
#define MONRD 0x89 /* Read month register */
#define DAYWR 0x8A /* Write to day register */
#define DAYRD 0x8B /* Read day register */
#define YRWR 0x8C /* Write to year register */
#define YRRD 0x8D /* Read Year register */
#define CBRSTRD 0xBF /* Burst read of clock */
/*************************************************************************
* RAM command/address definitions for storing MotoVars Struct
*************************************************************************/
#define TRIPTIMESECRD 0xC1 /* 1 byte needed */
#define TRIPTIMEMINRD 0xC3 /* 1 byte needed */
#define TRIPTIMEHRRD 0xC5 /* 1 byte needed */
#define TRIPSPEEDRD 0xC7 /* 1 byte needed */
#define TRIPODORD 0xC9 /* 4 bytes needed */
#define ODORD 0xD1 /* 4 bytes needed */
#define MPGODORD 0xD9 /* 4 bytes needed */
#define MPGRD 0xE1 /* 1 byte needed */
#define TANKRD 0xE3 /* 2 bytes */
#define WHEELRD 0xE7 /* 2 bytes */
/*************************************************************************
* RAM command/address definitions for storing MotoVars Struct
*************************************************************************/
#define TRIPTIMESECWR 0xC0
#define TRIPTIMEMINWR 0xC2
#define TRIPTIMEHRWR 0xC4
#define TRIPSPEEDWR 0xC6
#define TRIPODOWR 0xC8
#define ODOWR 0xD0
#define MPGODOWR 0xD8
#define MPGWR 0xE0
#define TANKWR 0xE2
#define WHEELWR 0xE6
/*************************************************************************
* SPI definitions
*************************************************************************/
#define SS 0x80
#define MOMI 0x20
#define SCK 0x40
#define SPIF 0x80
#define CR1 0x71
#define CR2 0x01
#define BR 0x02
/*************************************************************************
* Function prototypes (Public)
*************************************************************************/
extern OS_EVENT *SpiKey;
extern void DS1302SpiInit(void);
extern void RTCBurstRd(RTCCLK *rtcbuf);
extern void RamRetrieve(void);
extern void RamStore(void);
extern void WriteTime(INT8U hr, INT8U min);