ADVERTISEMENT

DS1302.zip

RTC - Wyświetlanie jakiejś dziwnej daty obok poprawnej

Zobacz czy zadziała. #include <DS1302.h> //Inicjalizacja DS1302(ce, data, clock); DS1302 rtc(12,11,10); void set_time() { rtc.setDOW(SATURDAY); //Nazwa dnia rtc.setTime(16, 1, 3); //Czas rtc.setDate(7, 9, 13); //Data } void setup() { Serial.begin(9600); // Start, zablokuj write_protection rtc.halt(false); rtc.writeProtect(false); //rtc.setTCR(TCR_OFF); //Wywołaj funkcje set_time set_time(); } void loop() { //Wyslij czas Serial.println(rtc.getTimeStr()); //Wyslij dzien Serial.println(rtc.getDOWStr(FORMAT_SHORT)); //Wyslij date Serial.println(rtc.getDateStr()); //Pauza delay (1000); }


Download file - link to post
  • DS1302.zip
    • keywords.txt
    • examples
      • DS1302_LCD
        • DS1302_LCD.pde
      • DS1302_Serial_Easy
        • DS1302_Serial_Easy.pde
      • DS1302_Serial_Hard
        • DS1302_Serial_Hard.pde
      • DS1302_RAM_Demo
        • DS1302_RAM_Demo.pde
    • DS1302.h
    • License
      • License - CC BY-NC-SA 3.0 - Legal.pdf
      • License - CC BY-NC-SA 3.0 - Summary.pdf
    • DS1302.cpp
    • Documentation
      • version.txt
      • DS1302.pdf


DS1302.zip > DS1302.h

/*
DS1302.h - Arduino library support for the DS1302 Trickle Charge Timekeeping Chip
Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved

This library has been made to easily interface and use the DS1302 RTC with
the Arduino.

You can find the latest version of the library at
http://www.RinkyDinkElectronics.com/

This library is free software; you can redistribute it and/or
modify it under the terms of the CC BY-NC-SA 3.0 license.
Please see the included documents for further information.

Commercial use of this library requires you to buy a license that
will allow commercial use. This includes using the library,
modified or not, as a tool to sell products.

The license applies to all part of the library including the
examples and tools supplied with the library.
*/
#ifndef DS1302_h
#define DS1302_h

#if defined(ARDUINO) &amp; &amp; ARDUINO &amp; gt; = 100
#include &quot; Arduino.h &quot;
#else
#include &quot; WProgram.h &quot;
#endif

#define FORMAT_SHORT 1
#define FORMAT_LONG 2

#define FORMAT_LITTLEENDIAN 1
#define FORMAT_BIGENDIAN 2
#define FORMAT_MIDDLEENDIAN 3

#define MONDAY 1
#define TUESDAY 2
#define WEDNESDAY 3
#define THURSDAY 4
#define FRIDAY 5
#define SATURDAY 6
#define SUNDAY 7

#define TCR_D1R2K 165
#define TCR_D1R4K 166
#define TCR_D1R8K 167
#define TCR_D2R2K 169
#define TCR_D2R4K 170
#define TCR_D2R8K 171
#define TCR_OFF 92

class Time
{
public:
uint8_t hour;
uint8_t min;
uint8_t sec;
uint8_t date;
uint8_t mon;
uint16_t year;
uint8_t dow;

Time();
};

class DS1302_RAM
{
public:
byte cell[31];

DS1302_RAM();
};

class DS1302
{
public:
DS1302(uint8_t ce_pin, uint8_t data_pin, uint8_t sclk_pin);
Time getTime();
void setTime(uint8_t hour, uint8_t min, uint8_t sec);
void setDate(uint8_t date, uint8_t mon, uint16_t year);
void setDOW(uint8_t dow);

char *getTimeStr(uint8_t format=FORMAT_LONG);
char *getDateStr(uint8_t slformat=FORMAT_LONG, uint8_t eformat=FORMAT_LITTLEENDIAN, char divider='.');
char *getDOWStr(uint8_t format=FORMAT_LONG);
char *getMonthStr(uint8_t format=FORMAT_LONG);

void halt(bool value);
void writeProtect(bool enable);
void setTCR(uint8_t value);

void writeBuffer(DS1302_RAM r);
DS1302_RAM readBuffer();
void poke(uint8_t addr, uint8_t value);
uint8_t peek(uint8_t addr);

private:
uint8_t _ce_pin;
uint8_t _data_pin;
uint8_t _sclk_pin;
uint8_t _burstArray[8];

uint8_t _readByte();
void _writeByte(uint8_t value);
uint8_t _readRegister(uint8_t reg);
void _writeRegister(uint8_t reg, uint8_t value);
void _burstRead();
uint8_t _decode(uint8_t value);
uint8_t _decodeH(uint8_t value);
uint8_t _decodeY(uint8_t value);
uint8_t _encode(uint8_t vaule);
};
#endif


DS1302.zip > License - CC BY-NC-SA 3.0 - Legal.pdf

Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0)
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE LEGAL SERVICES.
DISTRIBUTION OF THIS LICENSE DOES NOT CREATE AN ATTORNEY-CLIENT RELATIONSHIP. CREATIVE
COMMONS PROVIDES THIS INFORMATION ON AN &quot; AS-IS &quot; BASIS. CREATIVE COMMONS MAKES NO
WARRANTIES REGARDING THE INFORMATION PROVIDED, AND DISCLAIMS LIABILITY FOR DAMAGES
RESULTING FROM ITS USE.

License
THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE
COMMONS PUBLIC LICENSE ( &quot; CCPL &quot; OR &quot; LICENSE &quot; ). THE WORK IS PROTECTED BY
COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS
AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE TO BE
BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE MAY BE CONSIDERED
TO BE A CONTRACT, THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED HERE IN
CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
1. Definitions
a. &quot; Adaptation &quot; means a work based upon the Work, or upon the Work and other preexisting works, such as a translation, adaptation, derivative work, arrangement of
music or other alterations of a literary or artistic work, or phonogram or performance
and includes cinematographic adaptations or any other form in which the Work may
be recast, transformed, or adapted including in any form recognizably derived from
the original, except that a work that constitutes a Collection will not be considered an
Adaptation for the purpose of this License. For the avoidance of doubt, where the
Work is a musical work, performance or phonogram, the synchronization of the Work
in timed-relation with a moving image ( &quot; synching &quot; ) will be considered an Adaptation
for the purpose of this License.
b. &quot; Collection &quot; means a collection of literary or artistic works, such as encyclopedias
and anthologies, or performances, phonograms or broadcasts, or other works or
subject matter other than works listed in Section 1(g) below, which, by reason of the
selection and arrangement of their contents, constitute intellectual creations, in
which the Work is included in its entirety in unmodified form along with one or more
other contributions, each constituting separate and independent works in
themselves, which together are assembled into a collective whole. A work that
constitutes a Collection will not be considered an Adaptation (as defined above) for
the purposes of this License.
CC BY-NC-SA 3.0 – Legal

Page 1/7

c. &quot; Distribute &quot; means to make available to the public the original and copies of the
Work or Adaptation, as appropriate, through sale or other transfer of ownership.
d. &quot; License Elements &quot; means the following high-level license attributes as selected by
Licensor and indicated in the title of this License: Attribution, Noncommercial,
ShareAlike.
e. &quot; Licensor &quot; means the individual, individuals, entity or entities that offer(s) the Work
under the terms of this License.
f. &quot; Original Author &quot; means, in the case of a literary or artistic work, the individual,
individuals, entity or entities who created the Work or if no individual or entity can
be identified, the publisher; and in addition (i) in the case of a performance the
actors, singers, musicians, dancers, and other persons who act, sing, deliver, declaim,
play in, interpret or otherwise perform literary or artistic works or expressions of
folklore; (ii) in the case of a phonogram the producer being the person or legal entity
who first fixes the sounds of a performance or other sounds; and, (iii) in the case of
broadcasts, the organization that transmits the broadcast.
g. &quot; Work &quot; means the literary and/or artistic work offered under the terms of this
License including without limitation any production in the literary, scientific and
artistic domain, whatever may be the mode or form of its expression including digital
form, such as a book, pamphlet and other writing; a lecture, address, sermon or
other work of the same nature; a dramatic or dramatico-musical work; a
choreographic work or entertainment in dumb show; a musical composition with or
without words; a cinematographic work to which are assimilated works expressed by
a process analogous to cinematography; a work of drawing, painting, architecture,
sculpture, engraving or lithography; a photographic work to which are assimilated
works expressed by a process analogous to photography; a work of applied art; an
illustration, map, plan, sketch or three-dimensional work relative to geography,
topography, architecture or science; a performance; a broadcast; a phonogram; a
compilation of data to the extent it is protected as a copyrightable work; or a work
performed by a variety or circus performer to the extent it is not otherwise
considered a literary or artistic work.
h. &quot; You &quot; means an individual or entity exercising rights under this License who has not
previously violated the terms of this License with respect to the Work, or who has
received express permission from the Licensor to exercise rights under this License
despite a previous violation.
i. &quot; Publicly Perform &quot; means to perform public recitations of the Work and to
communicate to the public those public recitations, by any means or process,
including by wire or wireless means or public digital performances; to make available
to the public Works in such a way that members of the public may access these
Works from a place and at a place individually chosen by them; to perform the Work
to the public by any means or process and the communication to the public of the
performances of the Work, including by public digital performance; to broadcast and
rebroadcast the Work by any means including signs, sounds or images.
j. &quot; Reproduce &quot; means to make copies of the Work by any means including without
limitation by sound or visual recordings and the right of fixation and reproducing
fixations of the Work, including storage of a protected performance or phonogram in
digital form or other electronic medium.

CC BY-NC-SA 3.0 – Legal

Page 2/7

2. Fair Dealing Rights. Nothing in this License is intended to reduce, limit, or restrict any uses
free from copyright or rights arising from limitations or exceptions that are provided for in
connection with the copyright protection under copyright law or other applicable laws.
3. License Grant. Subject to the terms and conditions of this License, Licensor hereby grants
You a worldwide, royalty-free, non-exclusive, perpetual (for the duration of the applicable
copyright) license to exercise the rights in the Work as stated below:
a. to Reproduce the Work, to incorporate the Work into one or more Collections, and to
Reproduce the Work as incorporated in the Collections;
b. to create and Reproduce Adaptations provided that any such Adaptation, including
any translation in any medium, takes reasonable steps to clearly label, demarcate or
otherwise identify that changes were made to the original Work. For example, a
translation could be marked &quot; The original work was translated from English to
Spanish, &quot; or a modification could indicate &quot; The original work has been modified. &quot; ;
c. to Distribute and Publicly Perform the Work including as incorporated in Collections;
and,
d. to Distribute and Publicly Perform Adaptations.
The above rights may be exercised in all media and formats whether now known or
hereafter devised. The above rights include the right to make such modifications as are
technically necessary to exercise the rights in other media and formats. Subject to Section
8(f), all rights not expressly granted by Licensor are hereby reserved, including but not
limited to the rights described in Section 4(e).
4. Restrictions. The license granted in Section 3 above is expressly made subject to and
limited by the following restrictions:
a. You may Distribute or Publicly Perform the Work only under the terms of this
License. You must include a copy of, or the Uniform Resource Identifier (URI) for, this
License with every copy of the Work You Distribute or Publicly Perform. You may not
offer or impose any terms on the Work that restrict the terms of this License or the
ability of the recipient of the Work to exercise the rights granted to that recipient
under the terms of the License. You may not sublicense the Work. You must keep
intact all notices that refer to this License and to the disclaimer of warranties with
every copy of the Work You Distribute or Publicly Perform. When You Distribute or
Publicly Perform the Work, You may not impose any effective technological measures
on the Work that restrict the ability of a recipient of the Work from You to exercise
the rights granted to that recipient under the terms of the License. This Section 4(a)
applies to the Work as incorporated in a Collection, but this does not require the
Collection apart from the Work itself to be made subject to the terms of this License.
If You create a Collection, upon notice from any Licensor You must, to the extent
practicable, remove from the Collection any credit as required by Section 4(d), as
requested. If You create an Adaptation, upon notice from any Licensor You must, to
the extent practicable, remove from the Adaptation any credit as required by Section
4(d), as requested.
b. You may Distribute or Publicly Perform an Adaptation only under: (i) the terms of this
License; (ii) a later version of this License with the same License Elements as this
CC BY-NC-SA 3.0 – Legal

Page 3/7

License; (iii) a Creative Commons jurisdiction license (either this or a later license
version) that contains the same License Elements as this License (e.g., AttributionNonCommercial-ShareAlike 3.0 US) ( &quot; Applicable License &quot; ). You must include a copy
of, or the URI, for Applicable License with every copy of each Adaptation You
Distribute or Publicly Perform. You may not offer or impose any terms on the
Adaptation that restrict the terms of the Applicable License or the ability of the
recipient of the Adaptation to exercise the rights granted to that recipient under the
terms of the Applicable License. You must keep intact all notices that refer to the
Applicable License and to the disclaimer of warranties with every copy of the Work as
included in the Adaptation You Distribute or Publicly Perform. When You Distribute
or Publicly Perform the Adaptation, You may not impose any effective technological
measures on the Adaptation that restrict the ability of a recipient of the Adaptation
from You to exercise the rights granted to that recipient under the terms of the
Applicable License. This Section 4(b) applies to the Adaptation as incorporated in a
Collection, but this does not require the Collection apart from the Adaptation itself to
be made subject to the terms of the Applicable License.
c. You may not exercise any of the rights granted to You in Section 3 above in any
manner that is primarily intended for or directed toward commercial advantage or
private monetary compensation. The exchange of the Work for other copyrighted
works by means of digital file-sharing or otherwise shall not be considered to be
intended for or directed toward commercial advantage or private monetary
compensation, provided there is no payment of any monetary compensation in connection with the exchange of copyrighted works.
d. If You Distribute, or Publicly Perform the Work or any Adaptations or Collections, You
must, unless a request has been made pursuant to Section 4(a), keep intact all
copyright notices for the Work and provide, reasonable to the medium or means You
are utilizing: (i) the name of the Original Author (or pseudonym, if applicable) if
supplied, and/or if the Original Author and/or Licensor designate another party or
parties (e.g., a sponsor institute, publishing entity, journal) for attribution
( &quot; Attribution Parties &quot; ) in Licensor's copyright notice, terms of service or by other
reasonable means, the name of such party or parties; (ii) the title of the Work if
supplied; (iii) to the extent reasonably practicable, the URI, if any, that Licensor
specifies to be associated with the Work, unless such URI does not refer to the
copyright notice or licensing information for the Work; and, (iv) consistent with
Section 3(b), in the case of an Adaptation, a credit identifying the use of the Work in
the Adaptation (e.g., &quot; French translation of the Work by Original Author, &quot; or
&quot; Screenplay based on original Work by Original Author &quot; ). The credit required by this
Section 4(d) may be implemented in any reasonable manner; provided, however,
that in the case of a Adaptation or Collection, at a minimum such credit will appear, if
a credit for all contributing authors of the Adaptation or Collection appears, then as
part of these credits and in a manner at least as prominent as the credits for the
other contributing authors. For the avoidance of doubt, You may only use the credit
required by this Section for the purpose of attribution in the manner set out above
and, by exercising Your rights under this License, You may not implicitly or explicitly
assert or imply any connection with, sponsorship or endorsement by the Original
Author, Licensor and/or Attribution Parties, as appropriate, of You or Your use of the

CC BY-NC-SA 3.0 – Legal

Page 4/7

Work, without the separate, express prior written permission of the Original Author,
Licensor and/or Attribution Parties.
e. For the avoidance of doubt:
i. Non-waivable Compulsory License Schemes. In those jurisdictions in which
the right to collect royalties through any statutory or compulsory licensing
scheme cannot be waived, the Licensor reserves the exclusive right to collect
such royalties for any exercise by You of the rights granted under this License;
ii. Waivable Compulsory License Schemes. In those jurisdictions in which the
right to collect royalties through any statutory or compulsory licensing
scheme can be waived, the Licensor reserves the exclusive right to collect
such royalties for any exercise by You of the rights granted under this License
if Your exercise of such rights is for a purpose or use which is otherwise than
noncommercial as permitted under Section 4(c) and otherwise waives the
right to collect royalties through any statutory or compulsory licensing
scheme; and,
iii. Voluntary License Schemes. The Licensor reserves the right to collect
royalties, whether individually or, in the event that the Licensor is a member
of a collecting society that administers voluntary licensing schemes, via that
society, from any exercise by You of the rights granted under this License that
is for a purpose or use which is otherwise than noncommercial as permitted
under Section 4(c).
f. Except as otherwise agreed in writing by the Licensor or as may be otherwise
permitted by applicable law, if You Reproduce, Distribute or Publicly Perform the
Work either by itself or as part of any Adaptations or Collections, You must not
distort, mutilate, modify or take other derogatory action in relation to the Work
which would be prejudicial to the Original Author's honor or reputation. Licensor
agrees that in those jurisdictions (e.g. Japan), in which any exercise of the right
granted in Section 3(b) of this License (the right to make Adaptations) would be
deemed to be a distortion, mutilation, modification or other derogatory action
prejudicial to the Original Author's honor and reputation, the Licensor will waive or
not assert, as appropriate, this Section, to the fullest extent permitted by the
applicable national law, to enable You to reasonably exercise Your right under
Section 3(b) of this License (right to make Adaptations) but not otherwise.
5. Representations, Warranties and Disclaimer
UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN WRITING AND TO THE
FULLEST EXTENT PERMITTED BY APPLICABLE LAW, LICENSOR OFFERS THE WORK AS-IS AND
MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE WORK,
EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, INCLUDING, WITHOUT LIMITATION,
WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, ACCURACY, OR THE
PRESENCE OF ABSENCE OF ERRORS, WHETHER OR NOT DISCOVERABLE. SOME
JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED WARRANTIES, SO THIS
EXCLUSION MAY NOT APPLY TO YOU.

CC BY-NC-SA 3.0 – Legal

Page 5/7

6. Limitation on Liability. EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO
EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL,
INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS
LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
7. Termination
a. This License and the rights granted hereunder will terminate automatically upon any
breach by You of the terms of this License. Individuals or entities who have received
Adaptations or Collections from You under this License, however, will not have their
licenses terminated provided such individuals or entities remain in full compliance
with those licenses. Sections 1, 2, 5, 6, 7, and 8 will survive any termination of this
License.
b. Subject to the above terms and conditions, the license granted here is perpetual (for
the duration of the applicable copyright in the Work). Notwithstanding the above,
Licensor reserves the right to release the Work under different license terms or to
stop distributing the Work at any time; provided, however that any such election will
not serve to withdraw this License (or any other license that has been, or is required
to be, granted under the terms of this License), and this License will continue in full
force and effect unless terminated as stated above.
8. Miscellaneous
a. Each time You Distribute or Publicly Perform the Work or a Collection, the Licensor
offers to the recipient a license to the Work on the same terms and conditions as the
license granted to You under this License.
b. Each time You Distribute or Publicly Perform an Adaptation, Licensor offers to the
recipient a license to the original Work on the same terms and conditions as the
license granted to You under this License.
c. If any provision of this License is invalid or unenforceable under applicable law, it
shall not affect the validity or enforceability of the remainder of the terms of this
License, and without further action by the parties to this agreement, such provision
shall be reformed to the minimum extent necessary to make such provision valid and
enforceable.
d. No term or provision of this License shall be deemed waived and no breach
consented to unless such waiver or consent shall be in writing and signed by the
party to be charged with such waiver or consent.
e. This License constitutes the entire agreement between the parties with respect to
the Work licensed here. There are no understandings, agreements or representations
with respect to the Work not specified here. Licensor shall not be bound by any
additional provisions that may appear in any communication from You. This License
may not be modified without the mutual written agreement of the Licensor and You.
f. The rights granted under, and the subject matter referenced, in this License were
drafted utilizing the terminology of the Berne Convention for the Protection of
Literary and Artistic Works (as amended on September 28, 1979), the Rome
Convention of 1961, the WIPO Copyright Treaty of 1996, the WIPO Performances and
CC BY-NC-SA 3.0 – Legal

Page 6/7

Phonograms Treaty of 1996 and the Universal Copyright Convention (as revised on
July 24, 1971). These rights and subject matter take effect in the relevant jurisdiction
in which the License terms are sought to be enforced according to the corresponding
provisions of the implementation of those treaty provisions in the applicable national
law. If the standard suite of rights granted under applicable copyright law includes
additional rights not granted under this License, such additional rights are deemed to
be included in the License; this License is not intended to restrict the license of any
rights under applicable law.

Creative Commons Notice
Creative Commons is not a party to this License, and makes no warranty whatsoever in connection with
the Work. Creative Commons will not be liable to You or any party on any legal theory for any damages
whatsoever, including without limitation any general, special, incidental or consequential damages
arising in connection to this license. Notwithstanding the foregoing two (2) sentences, if Creative
Commons has expressly identified itself as the Licensor hereunder, it shall have all rights and obligations
of Licensor.
Except for the limited purpose of indicating to the public that the Work is licensed under the CCPL,
Creative Commons does not authorize the use by either party of the trademark &quot; Creative Commons &quot; or
any related trademark or logo of Creative Commons without the prior written consent of Creative
Commons. Any permitted use will be in compliance with Creative Commons' then-current trademark
usage guidelines, as may be published on its website or otherwise made available upon request from
time to time. For the avoidance of doubt, this trademark restriction does not form part of this License.
Creative Commons may be contacted at http://creativecommons.org/.

CC BY-NC-SA 3.0 – Legal

Page 7/7


DS1302.zip > License - CC BY-NC-SA 3.0 - Summary.pdf

Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0)
You are free:
to Share — to copy, distribute and transmit the work
to Remix — to adapt the work
Under the following conditions:
Attribution — You must attribute the work in the manner specified by
the author or licensor (but not in any way that suggests that they
endorse you or your use of the work).
Noncommercial — You may not use this work for commercial purposes.
Share Alike — If you alter, transform, or build upon this work, you may
distribute the resulting work only under the same or similar license to
this one.
With the understanding that:
Waiver

Any of the above conditions can be waived if you get permission
from the copyright holder.

Public Domain

Where the work or any of its elements is in the public domain under
applicable law, that status is in no way affected by the license.

Other Rights

In no way are any of the following rights affected by the license:
• Your fair dealing or fair use rights, or other applicable copyright
exceptions and limitations;
• The author's moral rights;
• Rights other persons may have either in the work itself or in how
the work is used, such as publicity or privacy rights.

Notice

For any reuse or distribution, you must make clear to others the
license terms of this work. The best way to do this is with a link to
the web page:
http://creativecommons.org/licenses/by-nc-sa/3.0/


DS1302.zip > keywords.txt

DS1302 KEYWORD1
Time KEYWORD1
DS1302_RAM KEYWORD1

getTime KEYWORD2
setTime KEYWORD2
setDate KEYWORD2
setDOW KEYWORD2
getTimeStr KEYWORD2
getDateStr KEYWORD2
getDOWStr KEYWORD2
getMonthStr KEYWORD2
halt KEYWORD2
writeProtect KEYWORD2
setTCR KEYWORD2
writeBuffer KEYWORD2
readBuffer KEYWORD2
poke KEYWORD2
peek KEYWORD2

hour KEYWORD2
min KEYWORD2
sec KEYWORD2
date KEYWORD2
mon KEYWORD2
year KEYWORD2
dow KEYWORD2

FORMAT_SHORT LITERAL1
FORMAT_LONG LITERAL1

FORMAT_LITTLEENDIAN LITERAL1
FORMAT_BIGENDIAN LITERAL1
FORMAT_MIDDLEENDIAN LITERAL1

MONDAY LITERAL1
TUESDAY LITERAL1
WEDNESDAY LITERAL1
THURSDAY LITERAL1
FRIDAY LITERAL1
SATURDAY LITERAL1
SUNDAY LITERAL1

TCR_D1R2K LITERAL1
TCR_D1R4K LITERAL1
TCR_D1R8K LITERAL1
TCR_D2R2K LITERAL1
TCR_D2R4K LITERAL1
TCR_D2R8K LITERAL1
TCR_OFF LITERAL1


DS1302.zip > DS1302.cpp

/*
DS1302.cpp - Arduino library support for the DS1302 Trickle Charge Timekeeping Chip
Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved

This library has been made to easily interface and use the DS1302 RTC with
the Arduino.

You can find the latest version of the library at
http://www.RinkyDinkElectronics.com/

This library is free software; you can redistribute it and/or
modify it under the terms of the CC BY-NC-SA 3.0 license.
Please see the included documents for further information.

Commercial use of this library requires you to buy a license that
will allow commercial use. This includes using the library,
modified or not, as a tool to sell products.

The license applies to all part of the library including the
examples and tools supplied with the library.
*/
#include &quot; DS1302.h &quot;

#define REG_SEC 0
#define REG_MIN 1
#define REG_HOUR 2
#define REG_DATE 3
#define REG_MON 4
#define REG_DOW 5
#define REG_YEAR 6
#define REG_WP 7
#define REG_TCR 8

/* Public */

Time::Time()
{
this- &amp; gt; year = 2010;
this- &amp; gt; mon = 1;
this- &amp; gt; date = 1;
this- &amp; gt; hour = 0;
this- &amp; gt; min = 0;
this- &amp; gt; sec = 0;
this- &amp; gt; dow = 5;
}

DS1302_RAM::DS1302_RAM()
{
for (int i=0; i &amp; lt; 31; i++)
cell[i]=0;
}

DS1302::DS1302(uint8_t ce_pin, uint8_t data_pin, uint8_t sclk_pin)
{
_ce_pin = ce_pin;
_data_pin = data_pin;
_sclk_pin = sclk_pin;

pinMode(_ce_pin, OUTPUT);
pinMode(_sclk_pin, OUTPUT);
}

Time DS1302::getTime()
{
Time t;
_burstRead();
t.sec = _decode(_burstArray[0]);
t.min = _decode(_burstArray[1]);
t.hour = _decodeH(_burstArray[2]);
t.date = _decode(_burstArray[3]);
t.mon = _decode(_burstArray[4]);
t.dow = _burstArray[5];
t.year = _decodeY(_burstArray[6])+2000;
return t;
}

void DS1302::setTime(uint8_t hour, uint8_t min, uint8_t sec)
{
if (((hour &amp; gt; =0) &amp; &amp; (hour &amp; lt; 24)) &amp; &amp; ((min &amp; gt; =0) &amp; &amp; (min &amp; lt; 60)) &amp; &amp; ((sec &amp; gt; =0) &amp; &amp; (sec &amp; lt; 60)))
{
_writeRegister(REG_HOUR, _encode(hour));
_writeRegister(REG_MIN, _encode(min));
_writeRegister(REG_SEC, _encode(sec));
}
}

void DS1302::setDate(uint8_t date, uint8_t mon, uint16_t year)
{
if (((date &amp; gt; 0) &amp; &amp; (date &amp; lt; =31)) &amp; &amp; ((mon &amp; gt; 0) &amp; &amp; (mon &amp; lt; =12)) &amp; &amp; ((year &amp; gt; =2000) &amp; &amp; (year &amp; lt; 3000)))
{
year -= 2000;
_writeRegister(REG_YEAR, _encode(year));
_writeRegister(REG_MON, _encode(mon));
_writeRegister(REG_DATE, _encode(date));
}
}

void DS1302::setDOW(uint8_t dow)
{
if ((dow &amp; gt; 0) &amp; &amp; (dow &amp; lt; 8))
_writeRegister(REG_DOW, dow);
}

char *DS1302::getTimeStr(uint8_t format)
{
char *output= &quot; xxxxxxxx &quot; ;
Time t;
t=getTime();
if (t.hour &amp; lt; 10)
output[0]=48;
else
output[0]=char((t.hour / 10)+48);
output[1]=char((t.hour % 10)+48);
output[2]=58;
if (t.min &amp; lt; 10)
output[3]=48;
else
output[3]=char((t.min / 10)+48);
output[4]=char((t.min % 10)+48);
output[5]=58;
if (format==FORMAT_SHORT)
output[5]=0;
else
{
if (t.sec &amp; lt; 10)
output[6]=48;
else
output[6]=char((t.sec / 10)+48);
output[7]=char((t.sec % 10)+48);
output[8]=0;
}
return output;
}

char *DS1302::getDateStr(uint8_t slformat, uint8_t eformat, char divider)
{
char *output= &quot; xxxxxxxxxx &quot; ;
int yr, offset;
Time t;
t=getTime();
switch (eformat)
{
case FORMAT_LITTLEENDIAN:
if (t.date &amp; lt; 10)
output[0]=48;
else
output[0]=char((t.date / 10)+48);
output[1]=char((t.date % 10)+48);
output[2]=divider;
if (t.mon &amp; lt; 10)
output[3]=48;
else
output[3]=char((t.mon / 10)+48);
output[4]=char((t.mon % 10)+48);
output[5]=divider;
if (slformat==FORMAT_SHORT)
{
yr=t.year-2000;
if (yr &amp; lt; 10)
output[6]=48;
else
output[6]=char((yr / 10)+48);
output[7]=char((yr % 10)+48);
output[8]=0;
}
else
{
yr=t.year;
output[6]=char((yr / 1000)+48);
output[7]=char(((yr % 1000) / 100)+48);
output[8]=char(((yr % 100) / 10)+48);
output[9]=char((yr % 10)+48);
output[10]=0;
}
break;
case FORMAT_BIGENDIAN:
if (slformat==FORMAT_SHORT)
offset=0;
else
offset=2;
if (slformat==FORMAT_SHORT)
{
yr=t.year-2000;
if (yr &amp; lt; 10)
output[0]=48;
else
output[0]=char((yr / 10)+48);
output[1]=char((yr % 10)+48);
output[2]=divider;
}
else
{
yr=t.year;
output[0]=char((yr / 1000)+48);
output[1]=char(((yr % 1000) / 100)+48);
output[2]=char(((yr % 100) / 10)+48);
output[3]=char((yr % 10)+48);
output[4]=divider;
}
if (t.mon &amp; lt; 10)
output[3+offset]=48;
else
output[3+offset]=char((t.mon / 10)+48);
output[4+offset]=char((t.mon % 10)+48);
output[5+offset]=divider;
if (t.date &amp; lt; 10)
output[6+offset]=48;
else
output[6+offset]=char((t.date / 10)+48);
output[7+offset]=char((t.date % 10)+48);
output[8+offset]=0;
break;
case FORMAT_MIDDLEENDIAN:
if (t.mon &amp; lt; 10)
output[0]=48;
else
output[0]=char((t.mon / 10)+48);
output[1]=char((t.mon % 10)+48);
output[2]=divider;
if (t.date &amp; lt; 10)
output[3]=48;
else
output[3]=char((t.date / 10)+48);
output[4]=char((t.date % 10)+48);
output[5]=divider;
if (slformat==FORMAT_SHORT)
{
yr=t.year-2000;
if (yr &amp; lt; 10)
output[6]=48;
else
output[6]=char((yr / 10)+48);
output[7]=char((yr % 10)+48);
output[8]=0;
}
else
{
yr=t.year;
output[6]=char((yr / 1000)+48);
output[7]=char(((yr % 1000) / 100)+48);
output[8]=char(((yr % 100) / 10)+48);
output[9]=char((yr % 10)+48);
output[10]=0;
}
break;
}
return output;
}

char *DS1302::getDOWStr(uint8_t format)
{
char *output= &quot; xxxxxxxxx &quot; ;
Time t;
t=getTime();
switch (t.dow)
{
case MONDAY:
output= &quot; Monday &quot; ;
break;
case TUESDAY:
output= &quot; Tuesday &quot; ;
break;
case WEDNESDAY:
output= &quot; Wednesday &quot; ;
break;
case THURSDAY:
output= &quot; Thursday &quot; ;
break;
case FRIDAY:
output= &quot; Friday &quot; ;
break;
case SATURDAY:
output= &quot; Saturday &quot; ;
break;
case SUNDAY:
output= &quot; Sunday &quot; ;
break;
}
if (format==FORMAT_SHORT)
output[3]=0;
return output;
}

char *DS1302::getMonthStr(uint8_t format)
{
char *output= &quot; xxxxxxxxx &quot; ;
Time t;
t=getTime();
switch (t.mon)
{
case 1:
output= &quot; January &quot; ;
break;
case 2:
output= &quot; February &quot; ;
break;
case 3:
output= &quot; March &quot; ;
break;
case 4:
output= &quot; April &quot; ;
break;
case 5:
output= &quot; May &quot; ;
break;
case 6:
output= &quot; June &quot; ;
break;
case 7:
output= &quot; July &quot; ;
break;
case 8:
output= &quot; August &quot; ;
break;
case 9:
output= &quot; September &quot; ;
break;
case 10:
output= &quot; October &quot; ;
break;
case 11:
output= &quot; November &quot; ;
break;
case 12:
output= &quot; December &quot; ;
break;
}
if (format==FORMAT_SHORT)
output[3]=0;
return output;
}

void DS1302::halt(bool enable)
{
uint8_t _reg = _readRegister(REG_SEC);
_reg &amp; = ~(1 &amp; lt; &amp; lt; 7);
_reg |= (enable &amp; lt; &amp; lt; 7);
_writeRegister(REG_SEC, _reg);
}

void DS1302::writeProtect(bool enable)
{
uint8_t _reg = (enable &amp; lt; &amp; lt; 7);
_writeRegister(REG_WP, _reg);
}

void DS1302::setTCR(uint8_t value)
{
_writeRegister(REG_TCR, value);
}

/* Private */

uint8_t DS1302::_readByte()
{
pinMode(_data_pin, INPUT);

uint8_t value = 0;
uint8_t currentBit = 0;

for (int i = 0; i &amp; lt; 8; ++i)
{
currentBit = digitalRead(_data_pin);
value |= (currentBit &amp; lt; &amp; lt; i);
digitalWrite(_sclk_pin, HIGH);
delayMicroseconds(1);
digitalWrite(_sclk_pin, LOW);
}
return value;
}

void DS1302::_writeByte(uint8_t value)
{
pinMode(_data_pin, OUTPUT);
shiftOut(_data_pin, _sclk_pin, LSBFIRST, value);
}

uint8_t DS1302::_readRegister(uint8_t reg)
{
uint8_t cmdByte = 129;
cmdByte |= (reg &amp; lt; &amp; lt; 1);

uint8_t readValue;

digitalWrite(_sclk_pin, LOW);
digitalWrite(_ce_pin, HIGH);

_writeByte(cmdByte);
readValue = _readByte();

digitalWrite(_ce_pin, LOW);

return readValue;
}

void DS1302::_writeRegister(uint8_t reg, uint8_t value)
{
uint8_t cmdByte = (128 | (reg &amp; lt; &amp; lt; 1));

digitalWrite(_sclk_pin, LOW);
digitalWrite(_ce_pin, HIGH);

_writeByte(cmdByte);
_writeByte(value);

digitalWrite(_ce_pin, LOW);
}

void DS1302::_burstRead()
{
digitalWrite(_sclk_pin, LOW);
digitalWrite(_ce_pin, HIGH);

_writeByte(191);
for (int i=0; i &amp; lt; 8; i++)
{
_burstArray[i] = _readByte();
}
digitalWrite(_ce_pin, LOW);
}

uint8_t DS1302::_decode(uint8_t value)
{
uint8_t decoded = value &amp; 127;
decoded = (decoded &amp; 15) + 10 * ((decoded &amp; (15 &amp; lt; &amp; lt; 4)) &amp; gt; &amp; gt; 4);
return decoded;
}

uint8_t DS1302::_decodeH(uint8_t value)
{
if (value &amp; 128)
value = (value &amp; 15) + (12 * ((value &amp; 32) &amp; gt; &amp; gt; 5));
else
value = (value &amp; 15) + (10 * ((value &amp; 48) &amp; gt; &amp; gt; 4));
return value;
}

uint8_t DS1302::_decodeY(uint8_t value)
{
uint8_t decoded = (value &amp; 15) + 10 * ((value &amp; (15 &amp; lt; &amp; lt; 4)) &amp; gt; &amp; gt; 4);
return decoded;
}

uint8_t DS1302::_encode(uint8_t value)
{
uint8_t encoded = ((value / 10) &amp; lt; &amp; lt; 4) + (value % 10);
return encoded;
}

void DS1302::writeBuffer(DS1302_RAM r)
{
digitalWrite(_sclk_pin, LOW);
digitalWrite(_ce_pin, HIGH);

_writeByte(254);
for (int i=0; i &amp; lt; 31; i++)
{
_writeByte(r.cell[i]);
}
digitalWrite(_ce_pin, LOW);
}

DS1302_RAM DS1302::readBuffer()
{
DS1302_RAM r;

digitalWrite(_sclk_pin, LOW);
digitalWrite(_ce_pin, HIGH);

_writeByte(255);
for (int i=0; i &amp; lt; 31; i++)
{
r.cell[i] = _readByte();
}
digitalWrite(_ce_pin, LOW);

return r;
}

void DS1302::poke(uint8_t addr, uint8_t value)
{
if ((addr &amp; gt; =0) &amp; &amp; (addr &amp; lt; =30))
{
addr = (addr * 2) + 192;

digitalWrite(_sclk_pin, LOW);
digitalWrite(_ce_pin, HIGH);

_writeByte(addr);
_writeByte(value);

digitalWrite(_ce_pin, LOW);
}
}

uint8_t DS1302::peek(uint8_t addr)
{
if ((addr &amp; gt; =0) &amp; &amp; (addr &amp; lt; =30))
{
addr = (addr * 2) + 193;

uint8_t readValue;

digitalWrite(_sclk_pin, LOW);
digitalWrite(_ce_pin, HIGH);

_writeByte(addr);
readValue = _readByte();

digitalWrite(_ce_pin, LOW);

return readValue;
}
else
return 0;
}


DS1302.zip > DS1302.pdf

DS1302
DS1302 Trickle Charge Timekeeping Chip Arduino library

Manual

http://www.RinkyDinkElectronics.com/

(C)2014 Rinky-Dink Electronics, Henning Karlsen

Introduction:
This library has been made to easily interface and use the DS1302 RTC with the Arduino.
This library uses a software-based communication protocol which will require exclusive access
to the pins used. You will not be able to share pins with other devices.
From the DS1302 datasheet:
The DS1302 trickle-charge timekeeping chip contains a real-time clock/calendar
and 31 bytes of static RAM. It communicates with a microprocessor via a simple
serial interface. The real-time clock/calendar provides seconds, minutes, hours,
day, date, month, and year information. The end of the month date is
automatically adjusted for months with fewer than 31 days, including corrections
for leap year. The clock operates in either the 24-hour or 12-hour format with an
AM/PM indicator.
Interfacing the DS1302 with a microprocessor is simplified by using synchronous
serial communication. Only three wires are required to communicate with the
clock/RAM: CE, I/O (data line), and SCLK (serial clock). Data can be transferred
to and from the clock/RAM 1 byte at a time or in a burst of up to 31 bytes. The
DS1302 is designed to operate on very low power and retain data and clock
information on less than 1μW.
The DS1302 is the successor to the DS1202. In addition to the basic timekeeping
functions of the DS1202, the DS1302 has the additional features of dual power
pins for primary and backup power supplies, programmable trickle charger for VCC1,
and seven additional bytes of scratchpad memory.
Please note that this library only makes use of the 24-hour format.

You can always find the latest version of the library at http://www.RinkyDinkElectronics.com/
For version information, please refer to version.txt.

This library is licensed under a CC BY-NC-SA 3.0 (Creative Commons AttributionNonCommercial-ShareAlike 3.0 Unported) License.
For more information see: http://creativecommons.org/licenses/by-nc-sa/3.0/
Library Manual: DS1302

Page 1

Structures:
Time;

Structure to manipulate time- and date-data.
Variables:

Usage:

hour, min, sec: For holding time-data
date, mon, year: For holding date-data
dow:
Day-of-the-week with monday being the first day
Time t; // Define a structure named t of the Time-class
DS1302_RAM;

Buffer for use with readBuffer() and writeBuffer().
Variables:
Usage:

Cell[0-30]: Array of 31 bytes to hold the data read from or to be written to the on-chip RAM.
DS1302_RAM ramBuffer; // Declare a buffer for use

Defined Literals:
Weekdays

For use with setDOW() and Time.dow
MONDAY:
TUESDAY:
WEDNESDAY:
THURSDAY:
FRIDAY:
SATURDAY:
SUNDAY:

1
2
3
4
5
6
7

Select length

For use with getTimeStr(), getDateStr(), getDOWStr() and getMonthStr()
FORMAT_SHORT:
FORMAT_LONG:

1
2

Select date format

For use with getDateStr()
FORMAT_LITTLEENDIAN:
FORMAT_BIGENDIAN:
FORMAT_MIDDLEENDIAN:

1
2
3

Select Trickle-Charge values

For use with setTCR()
TCR_D1R2K:
TCR_D1R4K:
TCR_D1R8K:
TCR_D2R2K:
TCR_D2R4K:
TCR_D2R8K:
TCR_OFF:

Library Manual: DS1302

165
166
167
169
170
171
92

Page 2

Functions:
DS1302(CE, IO, SCLK);

The main class of the interface.
Parameters:

Usage:

CE:
CE-pin of the DS1302 (Pin 5)
IO:
I/O-pin of the DS1302 (Pin 6)
SCLK: SCLK-pin of the DS1302 (Pin 7)
DS1302 rtc(2, 3, 4); // Start an instance of the DS1302 class
getTime();

Get current data from the DS1302.
Parameters:
Returns:
Usage:

None
Time-structure
t = rtc.getTime(); // Read current time and date.
getTimeStr([format]);

Get current time as a string.
Parameters:

Returns:
Usage:

format: &amp; lt; Optional &amp; gt;
FORMAT_LONG &quot; hh:mm:ss &quot; (default)
FORMAT_SHORT &quot; hh:mm &quot;
String containing the current time with or without seconds.
Serial.print(rtc.getTimeStr()); // Send the current time over a serial connection
getDateStr([slformat[, eformat[, divider]]]);

Get current date as a string.
Parameters:

Returns:
Usage:
Notes:

slformat: &amp; lt; Optional &amp; gt; *1
FORMAT_LONG Year with 4 digits (yyyy) (default)
FORMAT_SHORT Year with 2 digits (yy)
eformat: &amp; lt; Optional &amp; gt; *2
FORMAT_LITTLEENDIAN &quot; dd.mm.yyyy &quot; (default)
FORMAT_BIGENDIAN
&quot; yyyy.mm.dd &quot;
FORMAT_MIDDLEENDIAN &quot; mm.dd.yyyy &quot;
divider: &amp; lt; Optional &amp; gt;
Single character to use as divider. Default is '.'
String containing the current date in the specified format.
Serial.print(rtc.getDateStr()); // Send the current date over a serial connection (in Little-Endian
format)
*1: Required if you need eformat or divider.
*2: Required if you need divider. More information on Wikipedia
(http://en.wikipedia.org/wiki/Date_format#Date_format).
getDOWStr([format]);

Get current day-of-the-week as a string.
Parameters:

Returns:
Usage:

format: &amp; lt; Optional &amp; gt;
FORMAT_LONG Day-of-the-week in English (default)
FORMAT_SHORT Abbreviated Day-of-the-week in English (3 letters)
String containing the current day-of-the-week in full or abbreviated format.
Serial.print(rtc.getDOWStr(FORMAT_SHORT)); // Send the current day in abbreviated format over a
serial connection
getMonthStr([format]);

Get current month as a string.
Parameters:

Returns:
Usage:

format: &amp; lt; Optional &amp; gt;
FORMAT_LONG Month in English (default)
FORMAT_SHORT Abbreviated month in English (3 letters)
String containing the current month in full or abbreviated format.
Serial.print(rtc.getMonthStr()); // Send the current month over a serial connection

Library Manual: DS1302

Page 3

setTime(hour, min, sec);

Set the time.
Parameters:

Returns:
Usage:
Notes:

hour: Hour to store in the DS1302 (0-23)
min: Minute to store in the DS1302 (0-59)
sec: Second to store in the DS1302 (0-59)
Nothing
rtc.setTime(23, 59, 59); // Set the time to 23:59:59
Setting the time will clear the CH (Clock Halt) flag. See the datesheet for more information on the
CH flag.
setDate(date, mon, year);

Set the date.
Parameters:

Returns:
Usage:
Notes:

date: Date of the month to store in the DS1302 (1-31) *1
mon: Month to store in the DS1302 (1-12)
year: Year to store in the DS1302 (2000-2099)
Nothing
rtc.setDate(6, 8, 2010); // Set the date to August 6., 2010.
*1: No cheking for illegal dates so Feb 31. is possible to input. The effect of doing this is
unknown.
setDOW(dow);

Set the day-of-the-week.
Parameters:
Returns:
Usage:
Notes:

dow: Day of the week to store in the DS1302 (1-7) *1
Nothing
rtc.setDOW(FRIDAY); // Set the day-of-the-week to be friday
*1: Monday is 1, and through to sunday being 7.

Library Manual: DS1302

Page 4

halt(value);

Set or clear the CH*1 flag.
Parameters:
Returns:
Usage:
Notes:

value: true: Set the CH flag
false: Clear the CH flag
Nothing
rtc.halt(true); // Set the CH flag
*1: CH: Clock Halt flag. See the datasheet for more information.
writeProtect(enable);

Set or clear the WP*1 bit.
Parameters:
Returns:
Usage:
Notes:

enable: true: Set the WP bit
false: Clear the WP bit
Nothing
rtc.writeProtect(false); // Clear the WP bit
*1: WP: Write-Protect bit. See the datasheet for more information.
setTCR(value);

Set the Trickle-Charge Register. Use the defined literals to set the correct value.
Parameters:
Returns:
Usage:
Notes:

Added in v2.1

value: Use the defined literals to set the number of diodes and resistance used.
Nothing
rtc.setTCR(TCR_D1R4K); // Set the Trickle-charge register to support 1 diode and a 4K ohm resistor.
The literals are defines as TCR_DxRyK where x is the number of diodes used (1 or 2), and y is the
resistance used (2, 4 or 8 Kohm). TCR_OFF turns of the Trickle-Charge function.

Library Manual: DS1302

Page 5

writeBuffer(buffer);

Burst-write the buffer to on-chip RAM.
Parameters:
Returns:
Usage:

Added in v2.0

buffer: DS1302_RAM buffer
Nothing
rtc.writebuffer(ramBuffer); // Write the 31 bytes of ramBuffer to the on-chip RAM
readBuffer();

Burst-read the on-chip RAM to the buffer.
Parameters:
Returns:
Usage:

Added in v2.0

None
DS1302_RAM buffer
ramBuffer=rtc.readBuffer(); // Read all 31 bytes of on-chip RAM and store the in ramBuffer
poke(address, value);

Write one single byte to on-chip RAM.
Parameters:
Returns:
Usage:

Added in v2.0

address: address of byte to write (0-30)
value : value to write to &amp; lt; address &amp; gt; (0-255)
Nothing
rtc.poke(15, 160); // Write 160 to address 15
peek(address);

Read one single byte from on-chip RAM.
Parameters:
Returns:
Usage:

Added in v2.0

address: address of byte to read (0-30)
Byte containing data read from on-chip RAM
b=rtc.peek(18); // Read a single byte from address 18 and put the result in b

Library Manual: DS1302

Page 6


DS1302.zip > version.txt

Version:
1.0 6 Aug 2010 - initial release
2.0 23 Aug 2010 - Added functions to use on-chip RAM.
2.1 17 Nov 2010 - Added setTCR();
2.2 26 Jan 2012 - Added support for Arduino 1.0 IDE