LTlib LaurTec Library  4.0.1
Open Source C Library for Microchip Microcontrollers based on XC8 Compiler
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
DS1337.c
Go to the documentation of this file.
1 /*******************************************************************************
2 
3 Author : Mauro Laurenti
4 Version : 1.2
5 Created on Date : 02/02/2013
6 Last update : 29/11/2015
7 
8 CopyRight 2006-2015 all rights are reserved
9 
10 ********************************************************
11 SOFTWARE LICENSE AGREEMENT
12 ********************************************************
13 
14 The usage of the supplied software imply the acceptance of the following license.
15 
16 The software supplied herewith by Mauro Laurenti (the Author) is intended for
17 use solely and exclusively on Microchip PIC Microcontroller (registered mark).
18 The software is owned by the Author, and is protected under applicable
19 copyright laws. All rights are reserved.
20 Any use in violation of the foregoing restrictions may subject the
21 user to criminal sanctions under applicable laws, as well as to civil liability
22 for the breach of the terms and conditions of this license.
23 Commercial use is forbidden without a written acknowledgement with the Author.
24 Personal or educational use is allowed if the application containing the
25 following software doesn't aim to commercial use or monetary earning of any kind.
26 
27 THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES,
28 WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
29 TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
30 PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE AUTHOR SHALL NOT,
31 IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
32 CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
33 
34 *******************************************************************************/
35 
36 #ifdef __XC8
37  #include <xc.h>
38 #endif
39 
40 #include "DS1337.h"
41 
42 
43 //************************************************************
44 // RTCC_initialize function implementation
45 //************************************************************
46 void RTCC_initialize (unsigned int baud_rate_KHz){
47 
49  DS1337_I2C_baud_rate(baud_rate_KHz);
50 }
51 
52 
53 //************************************************************
54 // RTCC_set_seconds function implementation
55 //************************************************************
56 signed char RTCC_set_seconds (unsigned char seconds) {
57 
59 
60 }
61 
62 
63 //************************************************************
64 // RTCC_get_seconds function implementation
65 //************************************************************
66 unsigned char RTCC_get_seconds (void) {
67 
68  unsigned char seconds;
69 
71 
72  // I set to 0 the not significant bits
73  seconds = seconds & 0b01111111;
74  return (seconds);
75 }
76 
77 
78 
79 //************************************************************
80 // RTCC_set_minutes function implementation
81 //************************************************************
82 
83 signed char RTCC_set_minutes (unsigned char minutes) {
84 
86 
87 }
88 
89 
90 //************************************************************
91 // RTCC_get_minutes function implementation
92 //************************************************************
93 unsigned char RTCC_get_minutes (void) {
94 
95  unsigned char minutes;
97 
98  // I set to 0 the not significant bits
99  minutes = minutes & 0b01111111;
100  return (minutes);
101 }
102 
103 
104 //************************************************************
105 // RTCC_set_hours function implementation
106 //************************************************************
107 signed char RTCC_set_hours (unsigned char hours) {
108 
110 }
111 
112 
113 //************************************************************
114 // RTCC_get_hours function implementation
115 //************************************************************
116 unsigned char RTCC_get_hours (void){
117 
118  unsigned char hours;
120 
121  // I set to 0 the not significant bits
122  hours = hours & 0b00111111;
123  return (hours);
124 }
125 
126 
127 //************************************************************
128 // RTCC_get_time_seconds function implementation
129 //************************************************************
130 unsigned char* RTCC_get_time_seconds (void) {
131 
132  static unsigned char time[9];
133  unsigned char value;
134 
135  value = RTCC_get_hours();
136 
137  // with +48 I convert the number in ASCII number
138  time[1] = (value & 0b00001111)+48;
139  time[0] = (value >> 4)+48;
140 
141  time[2] = ':';
142 
143  value = RTCC_get_minutes();
144  time[4] = (value & 0b00001111)+48;
145  time[3] = (value >> 4)+48;
146 
147  time[5] = '.';
148 
149  value = RTCC_get_seconds();
150  time[7] = (value & 0b00001111)+48;
151  time[6] = (value >> 4)+48;
152 
153  time[8] = '\0';
154 
155  return (time);
156 
157 }
158 
159 
160 //************************************************************
161 // RTCC_get_time function implementation
162 //************************************************************
163 unsigned char* RTCC_get_time (void) {
164 
165  static unsigned char time[6];
166  unsigned char value;
167 
168  value = RTCC_get_hours();
169 
170  // with +48 I convert the number in ASCII number
171  time[1] = (value & 0b00001111)+48;
172  time[0] = (value >> 4)+48;
173 
174  time[2] = ':';
175 
176  value = RTCC_get_minutes();
177  time[4] = (value & 0b00001111)+48;
178  time[3] = (value >> 4)+48;
179 
180 
181  time[5] = '\0';
182 
183  return (time);
184 
185 }
186 
187 
188 //************************************************************
189 // RTCC_set_days function implementation
190 //************************************************************
191 signed char RTCC_set_days (unsigned char days) {
192 
194 }
195 
196 
197 //************************************************************
198 // RTCC_get_days function implementation
199 //************************************************************
200 unsigned char RTCC_get_days (void) {
201 
202  unsigned char days;
204 
205  // I set to 0 the not significant bits
206  days = days & 0b00111111;
207  return (days);
208 }
209 
210 
211 //************************************************************
212 // RTCC_set_months function implementation
213 //************************************************************
214 signed char RTCC_set_months (unsigned char months) {
215 
217 
218 }
219 
220 
221 //************************************************************
222 // RTCC_get_months function implementation
223 //************************************************************
224 unsigned char RTCC_get_months (void) {
225 
226  unsigned char months;
228 
229  // I set to 0 the not significant bits
230  months = months & 0b00011111;
231  return (months);
232 }
233 
234 
235 //************************************************************
236 // RTCC_set_years function implementation
237 //************************************************************
238 signed char RTCC_set_years (unsigned char years) {
239 
241 }
242 
243 
244 //************************************************************
245 // RTCC_get_years function implementation
246 //************************************************************
247 unsigned char RTCC_get_years (void) {
248 
249  unsigned char years;
251  return (years);
252 }
253 
254 
255 //************************************************************
256 // RTCC_get_date function implementation
257 //************************************************************
258 unsigned char* RTCC_get_date (void) {
259 
260  static unsigned char date[9];
261  unsigned char value;
262 
263  value = RTCC_get_days();
264 
265  // with +48 I convert the number in ASCII number
266  date[1] = (value & 0b00001111)+48;
267  date[0] = (value >> 4)+48;
268 
269  date[2] = '/';
270 
271  value = RTCC_get_months();
272  date[4] = (value & 0b00001111)+48;
273  date[3] = (value >> 4)+48;
274 
275  date[5] = '/';
276 
277 
278  value = RTCC_get_years();
279  date[7] = (value & 0b00001111)+48;
280  date[6] = (value >> 4)+48;
281 
282  date[8] = '\0';
283 
284  return (date);
285 
286 }
287 
288 
289 //************************************************************
290 // RTCC_set_seconds_alarm function implementation
291 //************************************************************
292 signed char RTCC_set_seconds_alarm (unsigned char seconds, unsigned char alarm_enable) {
293 
294  //I activate AE if required
295  seconds = seconds + alarm_enable;
297 
298 }
299 
300 
301 //************************************************************
302 // RTCC_set_minutes_alarm function implementation
303 //************************************************************
304 signed char RTCC_set_minutes_alarm (unsigned char minutes, unsigned char alarm_enable) {
305 
306  //I activate AE if required
307  minutes = minutes + alarm_enable;
308 
310 
311 }
312 
313 
314 //************************************************************
315 // RTCC_set_hours_alarm function implementation
316 //************************************************************
317 signed char RTCC_set_hours_alarm (unsigned char hours, unsigned char alarm_enable) {
318 
319  //I activate AE if required
320  hours = hours + alarm_enable;
322 }
323 
324 
325 //************************************************************
326 // RTCC_set_days_alarm function implementation
327 //************************************************************
328 signed char RTCC_set_days_alarm (unsigned char days, unsigned char alarm_enable) {
329 
330  //I activate AE if required
331  days = days + alarm_enable;
333 
334 }
335 
336 
337 //************************************************************
338 // RTCC_enable_alarm_interrupt function implementation
339 //************************************************************
340 signed char RTCC_enable_alarm_interrupt (void) {
341 
342  //Reset interrutp flags
343  //EEByteWrite (WRITE_ADD,CONTROL_REG_2_ADDR,0x00);
344 
346 
347 }
348 
349 
350 //************************************************************
351 // RTCC_disable_alarm_interrupt function implementation
352 //************************************************************
353 signed char RTCC_disable_alarm_interrupt (void) {
354 
356 
357 }
358 
359 
360 //************************************************************
361 // RTCC_is_alarm_ON function implementation
362 //************************************************************
363 unsigned char RTCC_is_alarm_ON (void) {
364 
365  unsigned char value;
367 
368  // Just A1F bit is controlled
369  if (value & 0x01) {
370 
371  value = value & 0xFE;
372 
373  // I clean AF bit without changing the other bits
375  return (1);
376 
377  } else {
378  return (0);
379  }
380 
381 }
382 
383 
384 //************************************************************
385 // RTCC_increment_minutes function implementation
386 //************************************************************
387 signed char RTCC_increment_minutes (void) {
388 
389  unsigned char minutes;
390  signed char error;
391 
392  // Read the current minutes
393  minutes = RTCC_get_minutes ();
394 
395  // Increment the minutes
396  minutes ++;
397 
398  // Check the minute limits
399 
400  if ((minutes&0x0F) > (unsigned char) 9 ) {
401  minutes &= 0xF0;
402  minutes += 0x10;
403  }
404 
405  if (minutes == (unsigned char) RTCC_MAX_MINUTES) {
406 
407  minutes = 0;
408  }
409 
410  // Update the minutes
411  error = RTCC_set_minutes (minutes);
412 
413  return (error);
414 
415 }
416 
417 
418 //************************************************************
419 // RTCC_increment_hours function implementation
420 //************************************************************
421 
422 signed char RTCC_increment_hours (void) {
423 
424  unsigned char hours;
425  signed char error;
426 
427  // Read the current hours
428  hours = RTCC_get_hours ();
429 
430  // Increment the hours
431  hours ++;
432 
433  // Check the hour limits
434 
435  if ((hours&0x0F) > (unsigned char) 9 ) {
436  hours &= 0xF0;
437  hours += 0x10;
438  }
439 
440  if (hours == (unsigned char) RTCC_MAX_HOURS) {
441 
442  hours = 0;
443  }
444 
445  // Update the hours
446  error = RTCC_set_hours (hours);
447 
448  return (error);
449 
450 }
451 
452 
453 //************************************************************
454 // RTCC_increment_years function implementation
455 //************************************************************
456 
457 signed char RTCC_increment_years (void) {
458 
459  unsigned char years;
460  signed char error;
461 
462  // Read the current years
463  years = RTCC_get_years ();
464 
465  // Increment the years
466  years ++;
467 
468  // Check the year limits
469 
470  if ((years&0x0F) > (unsigned char) 9 ) {
471  years &= 0xF0;
472  years += 0x10;
473  }
474 
475  if (years == (unsigned char) RTCC_MAX_YEARS) {
476 
477  years = 0;
478  }
479 
480  // Update the years
481  error = RTCC_set_years (years);
482 
483  return (error);
484 
485 }
486 
487 
488 //************************************************************
489 // RTCC_increment_months function implementation
490 //************************************************************
491 
492 signed char RTCC_increment_months (void) {
493 
494  unsigned char months;
495  signed char error;
496 
497  // Read the current months
498  months = RTCC_get_months ();
499 
500  // Increment the months
501  months ++;
502 
503  // Check the month limits
504 
505  if ((months&0x0F) > (unsigned char) 9 ) {
506  months &= 0xF0;
507  months += 0x10;
508  }
509 
510  if (months == (unsigned char) RTCC_MAX_MONTHS) {
511 
512  months = 1;
513  }
514 
515  // Update the months
516  error = RTCC_set_months (months);
517 
518  return (error);
519 
520 }
521 
522 //************************************************************
523 // RTCC_increment_days function implementation
524 //************************************************************
525 
526 signed char RTCC_increment_days (void) {
527 
528  unsigned char days;
529  signed char error;
530 
531  // Read the current days
532  days = RTCC_get_days ();
533 
534  // Increment the days
535  days ++;
536 
537  // Check the day limits
538 
539  if ((days&0x0F) > (unsigned char) 9 ) {
540  days &= 0xF0;
541  days += 0x10;
542  }
543 
544  if (days == (unsigned char) RTCC_MAX_DAYS) {
545 
546  days = 1;
547  }
548 
549  // Update the days
550  error = RTCC_set_days (days);
551 
552  return (error);
553 }
554