Suite à une suggestion sur le forum dédié à Energia et au MSP430 en général (http://forum NULL.43oh NULL.com/forum/28-energia/), j’ai procédé à une petite réécriture de ma librairie horloge temps-réel (http://xv4y NULL.radioclub NULL.asia/2012/05/22/bibliotheque-rtc-pour-le-msp430/) (Real Time Clock ou RTC) pour le MSP430. Le changement sont principalement cosmétiques mais quelques petits bogues ont été corrigés.
Les fichiers peuvent être téléchargés sur la page téléchargements (http://xv4y NULL.radioclub NULL.asia/boutique/docs/).
Ici le fichier de déclarations sRTC.h :
/* sRTC.h - Library for adding simple RTC capabilities using MSP430 hardware By Yannick DEVOS (XV4Y) - 2012-2013 Any commercial use or inclusion in a kit is subject to author approval ==== Revision history : v1.00 2012-05-22 First release v1.01 2012-12-17 Minor cosmetic changes v1.02 2012-12-18 Strucutral changes to improve code cleaness Currently does not work with Energia009 v1.03 2012-12-21 Settings in constructor to override default Energia settings, work with Energia 009 v1.04 2013-01-08 Moved settings to begin(), corrected bug related to Energia 009 => Thanks Grahamf72 from 43oh forums ==== This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You can download a copy of the GNU General Public License at <http://www.gnu.org/licenses/> ///////////////////////////////// How to use the lib * Create an instance of the object RealTimeClock myClock; * Do low-level Timer and Clock setup yourself or call begin(); myClock.begin(); * In order to have this RTC library working you should add this code to the end of your main program : interrupt(TIMER1_A0_VECTOR) Tic_Tac(void) { myClock++; // Update chunks }; * Enjoy the clock reading the RTC_sec, RTC_min, RTC_hr variables */ // ensure this library description is only included once #ifndef RTC_h #define RTC_h // library interface description class RealTimeClock { // user-accessible "public" interface public: RealTimeClock(void); void begin(void); void Set_Time(char hr, char mins, char secs); int RTC_chunk; // This how you read the time, by reading the vars char RTC_sec; // This how you read the time, by reading the vars char RTC_min; char RTC_hr; void Inc_chunk(void); // This methode should be invoked by an Interrupt call (see top of the file comment) RealTimeClock& operator++(); // Overload ++ operator for writing convenience (Prefix Variant) RealTimeClock& operator++(int); // PostFix variant // A few private methods private: void Inc_sec(void); void Inc_min(void); void Inc_hr(void); }; #endif
Et le code par lui même sRTC.cpp :
/* sRTC.h - Library for adding simple RTC capabilities using MSP430 hardware By Yannick DEVOS (XV4Y) - 2012 Any commercial use or inclusion in a kit is subject to author approval ==== This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You can download a copy of the GNU General Public License at <http://www.gnu.org/licenses/> */ // include this library's description file #include #include // Constructor ///////////////////////////////////////////////////////////////// RealTimeClock::RealTimeClock(void) { }; // Methods ///////////////////////////////////////////////////////////////// void RealTimeClock::begin(void) { BCSCTL1 &= ~DIVA_3; // ACLK without divider, set it to DIVA_0 BCSCTL3 |= XCAP_3; // Internal 12.5pF cap for 32KHz crystal TA1CCTL0 = CCIE; // CCR0 interupt activated TA1CCR0 = 128-1; // 4096 ticks of 32KHz XTal = 1 second, so 4 slices are 1 second => CCR0 counts N+1 TA1CTL = TASSEL_1 | ID_0 | MC_1; // Clock for TIMER 1 = ACLK, No division, up mode P2SEL |= (BIT6 | BIT7); // This is to override default Energia settings that set P2_6 and P2_7 to GPIO instead of ACLK BCSCTL3 = LFXT1S_0; // Override default Energia setting sourcing ACLK from VLO, now source from XTal RTC_chunk = 0; RTC_sec = 0; RTC_min = 0; RTC_hr = 0; }; RealTimeClock& RealTimeClock::operator++() { // Overload ++ operator for writing convenience (Prefix Variant) Inc_chunk(); // This just call Inc_chunk return *this; }; RealTimeClock& RealTimeClock::operator++(int) { // PostFix variant RealTimeClock tmp(*this); ++(*this); return tmp; }; void RealTimeClock::Inc_chunk(void) { RTC_chunk = RTC_chunk + 1; // Update chuncks if (RTC_chunk == 256) { RTC_chunk=0; Inc_sec(); }; }; void RealTimeClock::Inc_sec(void) { RTC_sec = RTC_sec + 1; // Update seconds if (RTC_sec == 60) { RTC_sec=0; Inc_min(); }; }; void RealTimeClock::Inc_min(void) { RTC_min = RTC_min + 1; // Update minutes if (RTC_min == 60) { RTC_min=0; Inc_hr(); }; }; void RealTimeClock::Inc_hr(void) { RTC_hr = RTC_hr + 1; // Update hours if (RTC_hr == 24) { RTC_hr=0; }; }; void RealTimeClock::Set_Time(char hrs=0, char mins=0, char secs=0) { if ((hrs>=0 && hrs <24) && (mins>=0 && mins<60) && (secs>=0 && secs<60)) { RTC_hr = hrs; // Set time to values given in parameters RTC_min = mins; RTC_sec = secs; RTC_chunk = 0; }; };
2 réflexions sur « Bibliothèque RTC pour Energia version 1.04 »
Les commentaires sont fermés.