?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{BLAME START}

library

?curdirlinks? -

Blame information for rev 6

Line No. Rev Author Line
1 6 kaklik <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
3 <title>Procyon AVRlib: rtc.c Source File</title>
4 <link href="dox.css" rel="stylesheet" type="text/css">
5 </head><body>
6 <!-- Generated by Doxygen 1.4.2 -->
7 <div class="qindex"><a class="qindex" href="main.html">Main&nbsp;Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Data&nbsp;Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div>
8 <h1>rtc.c</h1><a href="rtc_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*! \file rtc.c \brief Real-time clock function library. */</span>
9 00002 <span class="comment">//*****************************************************************************</span>
10 00003 <span class="comment">//</span>
11 00004 <span class="comment">// File Name : 'rtc.c'</span>
12 00005 <span class="comment">// Title : Real-time clock function library</span>
13 00006 <span class="comment">// Author : Pascal Stang - Copyright (C) 2002</span>
14 00007 <span class="comment">// Created : 5/10/2002</span>
15 00008 <span class="comment">// Revised : 9/30/2002</span>
16 00009 <span class="comment">// Version : 0.6</span>
17 00010 <span class="comment">// Target MCU : Atmel AVR Series</span>
18 00011 <span class="comment">// Editor Tabs : 4</span>
19 00012 <span class="comment">//</span>
20 00013 <span class="comment">// NOTE: This code is currently below version 1.0, and therefore is considered</span>
21 00014 <span class="comment">// to be lacking in some functionality or documentation, or may not be fully</span>
22 00015 <span class="comment">// tested. Nonetheless, you can expect most functions to work.</span>
23 00016 <span class="comment">//</span>
24 00017 <span class="comment">// This code is distributed under the GNU Public License</span>
25 00018 <span class="comment">// which can be found at http://www.gnu.org/licenses/gpl.txt</span>
26 00019 <span class="comment">//</span>
27 00020 <span class="comment">//*****************************************************************************</span>
28 00021
29 00022 <span class="preprocessor">#ifndef WIN32</span>
30 00023 <span class="preprocessor"></span><span class="preprocessor"> #include &lt;avr/io.h&gt;</span>
31 00024 <span class="preprocessor"> #include &lt;avr/interrupt.h&gt;</span>
32 00025 <span class="preprocessor"> #include &lt;avr/pgmspace.h&gt;</span>
33 00026 <span class="preprocessor">#endif</span>
34 00027 <span class="preprocessor"></span>
35 00028 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span>
36 00029 <span class="comment">// include timer support</span>
37 00030 <span class="preprocessor">#ifdef __AVR_ATmega128__</span>
38 00031 <span class="preprocessor"></span><span class="preprocessor"> #include "<a class="code" href="timer128_8h.html">timer128.h</a>"</span>
39 00032 <span class="preprocessor">#else</span>
40 00033 <span class="preprocessor"></span><span class="preprocessor"> #include "<a class="code" href="timer_8h.html">timer.h</a>"</span>
41 00034 <span class="preprocessor">#endif</span>
42 00035 <span class="preprocessor"></span><span class="comment">// include rtc header</span>
43 00036 <span class="preprocessor">#include "<a class="code" href="rtc_8h.html">rtc.h</a>"</span>
44 00037
45 00038 <span class="comment">// Program ROM constants</span>
46 00039 <span class="keyword">static</span> <span class="keywordtype">char</span> __attribute__ ((progmem)) MonthDayTable[] = {31,28,31,30,31,30,31,31,30,31,30,31};
47 00040
48 00041 <span class="comment">// Global variables</span>
49 00042 <span class="comment">// time registers</span>
50 00043 RtcTimeType RtcTime;
51 00044
52 00045 <span class="keywordtype">void</span> rtcInit(<span class="keywordtype">void</span>)
53 00046 {
54 00047 <span class="comment">// set up timer for RTC operation</span>
55 00048 <span class="comment">// initialize real-time registers</span>
56 00049 RtcTime.totaltics = 0;
57 00050 RtcTime.tics = 0;
58 00051 RtcTime.seconds = 0;
59 00052 RtcTime.minutes = 0;
60 00053 RtcTime.hours = 0;
61 00054 RtcTime.day = 1;
62 00055 RtcTime.month = 1;
63 00056 RtcTime.year = 2000;
64 00057
65 00058 <span class="comment">// select the correct RTC timer based on bit defines</span>
66 00059 <span class="preprocessor"> #ifdef AS2</span>
67 00060 <span class="preprocessor"></span> <span class="comment">// use timer2 for most AVRs</span>
68 00061 <span class="comment">// initialize timer 2</span>
69 00062 timer2Init();
70 00063 <span class="comment">// count with 32.768KHz/8</span>
71 00064 <a class="code" href="group__timer128.html#ga8">timer2SetPrescaler</a>(<a class="code" href="group__timer.html#ga17">TIMER_CLK_DIV8</a>);
72 00065 <span class="comment">// switch to asynchronous input (32KHz crystal)</span>
73 00066 sbi(ASSR, AS2);
74 00067 <span class="comment">// attach service to real-time clock interrupt</span>
75 00068 <span class="comment">// rtcService() will be called at ((32768/8)/256) = 16Hz</span>
76 00069 <a class="code" href="group__timer.html#ga8">timerAttach</a>(TIMER2OVERFLOW_INT, rtcService);
77 00070 <span class="preprocessor"> #else</span>
78 00071 <span class="preprocessor"></span><span class="preprocessor"> #ifdef AS0</span>
79 00072 <span class="preprocessor"></span> <span class="comment">// use timer0 for ATmega103, ATmega128</span>
80 00073 <span class="comment">// initialize timer 0</span>
81 00074 <a class="code" href="group__timer.html#ga2">timer0Init</a>();
82 00075 <span class="comment">// count with 32.768KHz/8</span>
83 00076 <a class="code" href="group__timer.html#ga4">timer0SetPrescaler</a>(<a class="code" href="group__timer.html#ga17">TIMER_CLK_DIV8</a>);
84 00077 <span class="comment">// switch to asynchronous input (32KHz crystal)</span>
85 00078 sbi(ASSR, AS0);
86 00079 <span class="comment">// attach service to real-time clock interrupt</span>
87 00080 <span class="comment">// rtcService() will be called at ((32768/8)/256) = 16Hz</span>
88 00081 <a class="code" href="group__timer.html#ga8">timerAttach</a>(TIMER0OVERFLOW_INT, rtcService);
89 00082 <span class="preprocessor"> #endif</span>
90 00083 <span class="preprocessor"></span><span class="preprocessor"> #endif</span>
91 00084 <span class="preprocessor"></span>}
92 00085
93 00086 <span class="keywordtype">void</span> rtcService(<span class="keywordtype">void</span>)
94 00087 {
95 00088 <span class="comment">// update real-time clock registers</span>
96 00089 RtcTime.totaltics++;
97 00090 RtcTime.tics++;
98 00091 <span class="comment">// check for overflows</span>
99 00092 <span class="keywordflow">if</span>(RtcTime.tics == 16) <span class="comment">// tics</span>
100 00093 {
101 00094 RtcTime.tics = 0;
102 00095 RtcTime.seconds++; <span class="comment">// increment seconds</span>
103 00096 <span class="keywordflow">if</span>(RtcTime.seconds &gt; 59) <span class="comment">// check seconds overflow</span>
104 00097 {
105 00098 RtcTime.seconds -= 60;
106 00099 RtcTime.minutes++; <span class="comment">// increment minutes</span>
107 00100 <span class="keywordflow">if</span>(RtcTime.minutes &gt; 59) <span class="comment">// check minutes overflow</span>
108 00101 {
109 00102 RtcTime.minutes -= 60;
110 00103 RtcTime.hours++; <span class="comment">// increment hours</span>
111 00104 <span class="keywordflow">if</span>(RtcTime.hours &gt; 23) <span class="comment">// check hours overflow</span>
112 00105 {
113 00106 RtcTime.hours -= 24;
114 00107 RtcTime.day++; <span class="comment">// increment days</span>
115 00108 <span class="comment">// check days overflow</span>
116 00109 <span class="keywordflow">if</span>(RtcTime.day == pgm_read_byte(&amp;MonthDayTable[RtcTime.month-1]))
117 00110 {
118 00111 RtcTime.day = 1;
119 00112 RtcTime.month++; <span class="comment">// increment months</span>
120 00113 <span class="keywordflow">if</span>(RtcTime.month == 13) <span class="comment">// check months overflow</span>
121 00114 {
122 00115 RtcTime.month = 1;
123 00116 RtcTime.year++; <span class="comment">// increment years</span>
124 00117 }
125 00118 }
126 00119 }
127 00120 }
128 00121 }
129 00122 }
130 00123 }
131 00124
132 00125 RtcTimeType* rtcGetTime(<span class="keywordtype">void</span>)
133 00126 {
134 00127 <span class="comment">// return the real-time clock data</span>
135 00128 <span class="keywordflow">return</span> &amp;RtcTime;
136 00129 }
137 00130
138 </pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:07 2006 for Procyon AVRlib by&nbsp;
139 <a href="http://www.doxygen.org/index.html">
140 <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address>
141 </body>
142 </html>
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3