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@@ @@@@@ @@@@@@@ @@@ @@@ @@@ @@ @@ @@@@@ @@@ @@@ @@@@ @@@ @@ @@@@ @@@ @@@ @@@ @@@ @@ @@ @@@ @@@ @@@ @@@@ @@@ @@ @@@@ @@@ @@@ @@@ @@@ @@ @@ @@@ @@@ @@@ @@@@ @@@ @@ @@@@ @@@ @@@ @@@ @@@ @@ @@@ @@@ @@@@@@@ @@@@ @@@@@@ @@ @@@ @@@@@@@ @@@@@@@ @@@@@@@ @@@@@ @@@@@ @@@@ @@@@@@ @@ @@@ @@@@@ @@@@@ @@@@@@ @@@@@ */ //=======================================================================================================//| // //| // BEGINNNING OF FILE //| // //| //=======================================================================================================//| //=======================================================================================================//| // //| // TITLE: DS1302 Real Time Clock //| // FILENAME: virtuabotixRTC.h //| // PREPARED FOR: Virtuabotic, LLC //| // PROGRAMMER(S): Arduino.cc user "Krodal" //| // Joseph Datillo //| // T. Daniel Murphy //| // DEVELOPMENT DATE: 06 January 2014 //| // COMPILER USED: Arduino 1.0.5 and xCode 5.0.2 (Version 5A3005) //| // TARGET PLATFORM: Versilino and Arduino Microcontrollers //| // //| //=======================================================================================================//| //=======================================================================================================//| // //| // Program Description Begin //| // //| //=======================================================================================================//| // //| // This file defines the functions declared within the associated header file. This allows for the //| // structure of the Real Time Clock to be defined, set, updated, then accessed. //| // //| //=======================================================================================================//| // //| // Program Description End //| // //| //=======================================================================================================//| //=======================================================================================================//| // //| // This is the Revision Section Begin //| // //| //=======================================================================================================//| // //| // Date Programmer Revisions Made //| // //| // XX June 2012 Krodal Original //| // XX March 2013 Krodal Added bcd2bin, bin2bcd_h, and bin2bcd_l functions//| // 07 January 2014 Joseph Datillo Converted file into library format. //| // T. Daniel Murphy Added functions to allow for user implentation //| // as a library, vice a stand alone program. //| // Added function for converting time into current //| // UNIX time. //| // //| //=======================================================================================================//| // //| // Revision Section End //| // //| //=======================================================================================================//| //=======================================================================================================//| // //| // Acknowledgements Begin //| // //| //=======================================================================================================//| // //| // The original program was provided by Arduino.cc user Kodal on URL: //| // http://playground.arduino.cc/Main/DS1302 //| // //| //=======================================================================================================//| // //| // Acknowledgements End //| // //| //=======================================================================================================//| //=======================================================================================================//| // //| // Reference Links Begin //| // //| //=======================================================================================================//| //| // Datasheet: http://www.hobbytronics.co.uk/datasheets/DS1302.pdf //| // GET UPDATES: https://www.virtuabotix.com/resources.php?product=versalino //| //| //=======================================================================================================//| // //| // Reference Links End //| // //| //=======================================================================================================//| //=======================================================================================================//| // //| // Include files required for Program Function Begin //| // //| //=======================================================================================================//| //| #include "virtuabotixRTC.h" //| //| //=======================================================================================================//| // //| // Include files required for Program Function End //| // //| //=======================================================================================================//| //=======================================================================================================//| // //| // Defines Required for Library Begin //| // //| //=======================================================================================================//| //| //+++++++++++++++++++++++++++++++++++++++++ Set Pin Assignments +++++++++++++++++++++++++++++++++++++++++//| #define DS1302_SCLK_PIN SCLK // Arduino pin for the Serial Clock //| #define DS1302_IO_PIN IO // Arduino pin for the Data I/O //| #define DS1302_CE_PIN C_E // Arduino pin for the Chip Enable //| //| //++++++++++++++++++++++++++++++++++++++++++ Conversion Macros ++++++++++++++++++++++++++++++++++++++++++//| // Macros to convert the bcd values of the registers to normal integer variables. The code uses //| // seperate variables for the high byte and the low byte of the bcd, so these macros handle both bytes //| // seperately. //| #define bcd2bin(h,l) (((h)*10) + (l)) //| #define bin2bcd_h(x) ((x)/10) //| #define bin2bcd_l(x) ((x)%10) //| //| //+++++++++++++++++++++++++++++++++++++++++ Set Register Names ++++++++++++++++++++++++++++++++++++++++++//| // Since the highest bit is always '1', the registers start at 0x80. If the register is read, the //| // lowest bit should be '1'. //| #define DS1302_SECONDS 0x80 //| #define DS1302_MINUTES 0x82 //| #define DS1302_HOURS 0x84 //| #define DS1302_DATE 0x86 //| #define DS1302_MONTH 0x88 //| #define DS1302_DAY 0x8A //| #define DS1302_YEAR 0x8C //| #define DS1302_CLOCK_BURST 0xBE //| #define DS1302_CLOCK_BURST_WRITE 0xBE //| #define DS1302_CLOCK_BURST_READ 0xBF //| #define DS1302_RAMSTART 0xC0 //| #define DS1302_RAMEND 0xFC //| #define DS1302_RAM_BURST 0xFE //| #define DS1302_RAM_BURST_WRITE 0xFE //| #define DS1302_RAM_BURST_READ 0xFF //| //| //+++++++++++++++++++++++++++++++++++++++++++++ Bit Defines +++++++++++++++++++++++++++++++++++++++++++++//| // Defines for the bits, to be able to change between bit number and binary definition. By using the //| // bit number, using the DS1302 is like programming an AVR microcontroller. But instead of using //| // "(1<