?? smartclock.lst
字號:
159 1 else
160 1 {
161 2 // Calculate month based on non leap year
162 2 if (total < 60)
163 2 {
164 3 (*month) = 2; // February
165 3 (*days) = total-31;
166 3 }
167 2 else if (total < 91)
168 2 {
169 3 (*month) = 3; // March
170 3 (*days) = total-59;
171 3 }
172 2 else if (total < 121)
173 2 {
174 3 (*month) = 4; // April
175 3 (*days) = total - 90;
176 3 }
177 2 else if (total < 152)
C51 COMPILER V8.17 SMARTCLOCK 03/26/2009 14:31:59 PAGE 4
178 2 {
179 3 (*month) = 5; // May
180 3 (*days) = total - 120;
181 3 }
182 2 else if (total < 182)
183 2 {
184 3 (*month) = 6; // June
185 3 (*days) = total-151;
186 3 }
187 2 else if (total < 213)
188 2 {
189 3 (*month) = 7; // July
190 3 (*days) = total - 181;
191 3 }
192 2 else if (total < 244)
193 2 {
194 3 (*month) = 8; // August
195 3 (*days) = total - 212;
196 3 }
197 2 else if (total < 274)
198 2 {
199 3 (*month) = 9; // September
200 3 (*days) = total - 243;
201 3 }
202 2 else if (total < 305)
203 2 {
204 3 (*month) = 10; // October
205 3 (*days) = total-273;
206 3 }
207 2 else if (total < 335)
208 2 {
209 3 (*month) = 11; // November
210 3 (*days) = total - 304;
211 3 }
212 2 else
213 2 {
214 3 (*month) = 12; // December
215 3 (*days) = total - 334;
216 3 }
217 2 }
218 1 }
219
220
221 //-----------------------------------------------------------------------------
222 // RTC_Read
223 //-----------------------------------------------------------------------------
224
225 INT8U RTC_Read (INT8U reg)
226 {
227 1 reg &= 0x0F; // Mask low nibble
228 1 RTC0ADR = reg; // Pick register
229 1 RTC0ADR |= 0x80; // Set BUSY bit to read
230 1 while ((RTC0ADR & 0x80) == 0x80); // Poll on the BUSY bit
231 1 return RTC0DAT; // Return value
232 1 }
233
234 //-----------------------------------------------------------------------------
235 // RTC_Write
236 //-----------------------------------------------------------------------------
237
238
239 void RTC_Write (INT8U reg, INT8U value)
C51 COMPILER V8.17 SMARTCLOCK 03/26/2009 14:31:59 PAGE 5
240 {
241 1 reg &= 0x0F; // Mask low nibble
242 1 RTC0ADR = reg; // Pick register
243 1 RTC0DAT = value; // Write data
244 1 while ((RTC0ADR & 0x80) == 0x80); // Poll on the BUSY bit
245 1 }
246
247 //-----------------------------------------------------------------------------
248 // RTC_Init
249 //-----------------------------------------------------------------------------
250
251 void RTC_Init (void)
252 {
253 1 INT16U i; // Counter used in for loop
254 1
255 1 UU32 alarm_interval_first; // Stores first alarm value
256 1
257 1 INT8U CLKSEL_SAVE = CLKSEL;
258 1
259 1
260 1 RTC0KEY = 0xA5; // Unlock the smaRTClock interface
261 1 RTC0KEY = 0xF1;
262 1
263 1 RTC_Write (RTC0XCN, 0x60); // Configure the smaRTClock
264 1 // oscillator for crystal mode
265 1 // Bias Doubling Enabled
266 1 // AGC Disabled
267 1 //0: smaRTClock is powered from VDD.
268 1
269 1 RTC_Write (RTC0CN, 0x80); // Enable smaRTClock oscillator
270 1
271 1
272 1 //----------------------------------
273 1 // Wait for smaRTClock to start
274 1 //----------------------------------
275 1
276 1 for(i=0;i<1000;i++);
277 1
278 1 while ((RTC_Read (RTC0XCN) & 0x10)== 0x00); // Wait for smaRTClock valid
279 1
280 1
281 1 //----------------------------------
282 1 // smaRTClock has been started
283 1 //----------------------------------
284 1
285 1 RTC_Write (RTC0XCN, 0xC0); // Enable Automatic Gain Control
286 1 // and disable bias doubling
287 1
288 1 RTC_Write (RTC0CN, 0xC0); // Enable missing smaRTClock detector
289 1 // and leave smaRTClock oscillator
290 1 // enabled.
291 1
292 1
293 1 //----------------------------------
294 1 // Set the smaRTClock Alarm
295 1 //----------------------------------
296 1
297 1 // Calculate the alarm interval in smaRTClock ticks
298 1 alarm_interval_first.U32 = (RTC_DAY-TIME_INIT);
299 1
300 1 // Copy the alarm interval to the alarm registers
301 1 RTC_Write (ALARM0, alarm_interval_first.U8[b0]); // LSB
C51 COMPILER V8.17 SMARTCLOCK 03/26/2009 14:31:59 PAGE 6
302 1 RTC_Write (ALARM1, alarm_interval_first.U8[b1]);
303 1 RTC_Write (ALARM2, alarm_interval_first.U8[b2]);
304 1 RTC_Write (ALARM3, alarm_interval_first.U8[b3]); // MSB
305 1
306 1 // Enable the smaRTClock timer and alarm with auto-reset
307 1 RTC_Write (RTC0CN, 0xDC);
308 1 }
309
310
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1220 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 16 15
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -