C Library for MAXIM DS1302 Real Time Clock Copyright (c) 2009, Craig Smith See end of file for MIT license terms. This is a library of routines to interface a MAXIM DS1302 real time clock with a Parallax Propeller I microcontroller. The code was developed using ImageCraft's Propeller C (ICCv7) ver. 7.04 **************************************************************************** See DS1302Test.c for an example using this library. List of functions: ================== void ds1302_init(BYTE clkPin, BYTE ioPin, BYTE cePin); Purpose: Initialize variables and pins and configure default DS1302 options Parameters: inClk = Prop pin tied to DS1302 clock pin inIo = Prop pin tied to DS1302 io pin inCE = Prop pin tied to DS1302 ce pin void ds1302_setDatetime(struct ds1302_dateTime dt); Purpose: Set date and time in DS1302 Parameters: dt is ds1302_structure containing date and time information NOTE: see ds1320.h for structure declaration void ds1302_getDatetime(struct ds1302_dateTime *dt); Purpose: Get date and time from DS1302 Parameters: dt is pointer to ds1302_structure to receive date and time information NOTE: see ds1320.h for structure declaration void ds1302_setDay(BYTE day); Purpose: Set calendar day in DS1302 Parameters: day = 1 to 31 BYTE ds1302_getDay(void); Purpose: Get calendar day from DS1302 Returns: day as 1 to 31 void ds1302_setMonth(BYTE month); Purpose: Set calendar month in DS1302 Parameters: month = 1 to 12 BYTE ds1302_getMonth(void); Purpose: Get calendar month from DS1302 Returns: month as 1 to 12 void ds1302_setYear(BYTE year); Purpose: Set calendar year in DS1302 Parameters: month = 0 to 99 BYTE ds1302_getYear(void); Purpose: Get calendar year from DS1302 Returns: year as 0 to 99 void ds1302_setDOW(BYTE dow); Purpose: Set day of week in DS1302 Parameters: dow = 1 to 7 NOTE: You define 1 to mean any day you want. Subsequent days increase by one. BYTE ds1302_getDOW(void); Purpose: Get dow of week from DS1302 Returns: day as 1 to 7 void ds1302_setHour(BYTE hour); Purpose: Set hour in DS1302 Parameters: hour = 0 to 23 in 24 hour mode (default) hour = 1 to 12 in 12 hour mode NOTE: AM or PM can be set using ds1302_setPM() BYTE ds1302_getHour(void); Purpose: Get hour from DS1302 Returns: hour as 0 to 23 in 24 hour mode (default) hour as 1 to 12 in 12 hour mode NOTE: AM or PM can be retrieved using ds1302_getPM() void ds1302_setMinute(BYTE minute); Purpose: Set minute in DS1302 Parameters: minute = 0 to 59 BYTE ds1302_getMinute(void); Purpose: Get minute from DS1302 Returns: minute as 0 to 59 void ds1302_setSecond(BYTE second); Purpose: Set second in DS1302 Parameters: second = 0 to 59 BYTE ds1302_getSecond(void); Purpose: Get second from DS1302 Returns: second as 0 to 59 void ds1302_setPM(BYTE pm); Purpose: Set AM or PM clock mode of DS1302 Parameters: pm = TRUE if PM, FALSE if AM NOTE: This function has no effect if clock is not in 12 hour mode BYTE ds1302_getPM(void); Purpose: Get AM or PM clock mode of DS1302 Returns: TRUE if PM, FALSE if AM void ds1302_set12HourMode(BYTE goto12HourMode); Purpose: Set 12 or 24 hour clock mode of DS1302 Parameters: goto12HourMode = TRUE if 12 hour, FALSE if 24 hour (default) BYTE ds1302_get12HourMode(void); Purpose: Get 12 or 24 hour clock mode of DS1302 Returns: TRUE if 12 hour, FALSE if 24 hour void ds1302_setWriteProtect(BYTE on); Purpose: Set write protect option of DS1302 Parameters: on = TRUE if write protect, FALSE if not (default) BYTE ds1302_getWriteProtect(void); Purpose: Get write protect option of DS1302 Returns: TRUE if write protect, FALSE if not (default) void ds1302_setClockHalt(BYTE halt); Purpose: Set clock halt option of DS1302 Parameters: halt = TRUE if clock halted, FALSE if not (default) BYTE ds1302_getClockHalt(void); Purpose: Get clock halt option of DS1302 Returns: TRUE if clock halted, FALSE if not (default) void ds1302_setTrickleCharge(BYTE mode); Purpose: Set trickle charge option of DS1302 Parameters: mode = 0 to turn off trickle charge (default) 1 for 1 diode and 2k ohm resistor 2 for 1 diode and 4k ohm resistor 3 for 1 diode and 8k ohm resistor 4 for 2 diodes and 2k ohm resistor 5 for 2 diodes and 4k ohm resistor 6 for 2 diodes and 8k ohm resistor BYTE ds1302_getTrickleCharge(void); Purpose: Get trickle charge option of DS1302 Returns: 0 for disabled trickle charge 1 for 1 diode and 2k ohm resistor 2 for 1 diode and 4k ohm resistor 3 for 1 diode and 8k ohm resistor 4 for 2 diodes and 2k ohm resistor 5 for 2 diodes and 4k ohm resistor 6 for 2 diodes and 8k ohm resistor void ds1302_setRamByte(BYTE address, BYTE data); Purpose: Set byte in DS1302 RAM Parameters: address = 0 to 30 data = 0 to 255 BYTE ds1302_getRamByte(BYTE address); Purpose: Get byte from DS1302 RAM Parameters: address = 0 to 30 Returns: data byte void ds1302_setRamBlock(BYTE address, BYTE length, BYTE *data); Purpose: Set a block of RAM in DS1302 Parameters: bytes is an array of up to 31 bytes bytes is an array of up to 31 bytes void ds1302_getRamBlock(BYTE address, BYTE length, BYTE *data); Purpose: Get a block of RAM from DS1302 Parameters: dt is pointer to ds1302_structure to receive date and time information see ds1320.h for structure declaration +-----------------------------------------------------------------------------+ ¦ TERMS OF USE: MIT License ¦ +-----------------------------------------------------------------------------¦ ¦Permission is hereby granted, free of charge, to any person obtaining a copy ¦ ¦of this software and associated documentation files (the "Software"), to deal¦ ¦in the Software without restriction, including without limitation the rights ¦ ¦to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ¦ ¦copies of the Software, and to permit persons to whom the Software is ¦ ¦furnished to do so, subject to the following conditions: ¦ ¦ ¦ ¦ The above copyright notice and this permission notice shall be included in ¦ ¦ all copies or substantial portions of the Software. ¦ ¦ ¦ ¦ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ¦ ¦ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ¦ ¦ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ¦ ¦ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ¦ ¦ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING ¦ ¦ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER ¦ ¦ DEALINGS IN THE SOFTWARE. ¦ +-----------------------------------------------------------------------------+