LTlib LaurTec Library  4.0.3
Open Source C Library for Microchip Microcontrollers based on XC8 Compiler
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
PCF8563.c
Go to the documentation of this file.
1 /*******************************************************************************
2 
3 Author : Mauro Laurenti
4 Version : 1.4
5 Created on Date : 4/9/2006
6 Last update : 19/06/2016
7 
8 CopyRight 2006-2014 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 "PCF8563.h"
41 
42 
43 //************************************************************
44 // RTCC_initialize function implementation
45 //************************************************************
46 void RTCC_initialize (unsigned int baud_rate_KHz){
48  PCF8563_I2C_baud_rate(baud_rate_KHz);
49 
50  //short delay to make sure that the 32KHz crystal is oscillating
51  delay_ms(500);
52 }
53 
54 
55 //************************************************************
56 // RTCC_set_seconds function implementation
57 //************************************************************
58 signed char RTCC_set_seconds (unsigned char seconds) {
59 
61 
62 }
63 
64 
65 //************************************************************
66 // RTCC_get_seconds function implementation
67 //************************************************************
68 unsigned char RTCC_get_seconds (void) {
69 
70  unsigned char seconds;
71 
73 
74  // I set to 0 the not significant bits
75  seconds = seconds & 0b01111111;
76  return (seconds);
77 }
78 
79 
80 
81 //************************************************************
82 // RTCC_set_minutes function implementation
83 //************************************************************
84 signed char RTCC_set_minutes (unsigned char minutes) {
85 
87 
88 }
89 
90 
91 //************************************************************
92 // RTCC_get_minutes function implementation
93 //************************************************************
94 unsigned char RTCC_get_minutes (void) {
95 
96  unsigned char minutes;
98 
99  // I set to 0 the not significant bits
100  minutes = minutes & 0b01111111;
101  return (minutes);
102 }
103 
104 
105 //************************************************************
106 // RTCC_set_hours function implementation
107 //************************************************************
108 signed char RTCC_set_hours (unsigned char hours) {
109 
111 }
112 
113 
114 //************************************************************
115 // RTCC_get_hours function implementation
116 //************************************************************
117 unsigned char RTCC_get_hours (void){
118 
119  unsigned char hours;
121 
122  // I set to 0 the not significant bits
123  hours = hours & 0b00111111;
124  return (hours);
125 }
126 
127 
128 //************************************************************
129 // RTCC_get_time_seconds function implementation
130 //************************************************************
131 unsigned char* RTCC_get_time_seconds (void) {
132 
133  static unsigned char time[9];
134  unsigned char value;
135 
136  value = get_hours_RTCC();
137 
138  // with +48 I convert the number in ASCII number
139  time[1] = (value & 0b00001111)+48;
140  time[0] = (value >> 4)+48;
141 
142  time[2] = ':';
143 
144  value = get_minutes_RTCC();
145  time[4] = (value & 0b00001111)+48;
146  time[3] = (value >> 4)+48;
147 
148  time[5] = '.';
149 
150  value = get_seconds_RTCC();
151  time[7] = (value & 0b00001111)+48;
152  time[6] = (value >> 4)+48;
153 
154  time[8] = '\0';
155 
156  return (time);
157 
158 }
159 
160 
161 //************************************************************
162 // RTCC_get_time function implementation
163 //************************************************************
164 unsigned char* RTCC_get_time (void) {
165 
166  static unsigned char time[6];
167  unsigned char value;
168 
169  value = get_hours_RTCC();
170 
171  // with +48 I convert the number in ASCII number
172  time[1] = (value & 0b00001111)+48;
173  time[0] = (value >> 4)+48;
174 
175  time[2] = ':';
176 
177  value = get_minutes_RTCC();
178  time[4] = (value & 0b00001111)+48;
179  time[3] = (value >> 4)+48;
180 
181 
182  time[5] = '\0';
183 
184  return (time);
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_day_of_the_week function implementation
213 //************************************************************
214 signed char RTCC_set_day_of_the_week (unsigned char day_of_the_week) {
215 
217 }
218 
219 
220 //************************************************************
221 // RTCC_get_day_of_the_week function implementation
222 //************************************************************
223 unsigned char RTCC_get_day_of_the_week (void){
224 
225  unsigned char day_of_the_week;
227 
228  // I set to 0 the not significant bits
229  day_of_the_week = day_of_the_week & 0b00000111;
230  return (day_of_the_week);
231 }
232 
233 
234 //************************************************************
235 // RTCC_set_months function implementation
236 //************************************************************
237 signed char RTCC_set_months (unsigned char months) {
238 
240 
241 }
242 
243 
244 //************************************************************
245 // RTCC_get_months function implementation
246 //************************************************************
247 unsigned char RTCC_get_months (void) {
248 
249  unsigned char months;
251 
252  // I set to 0 the not significant bits
253  months = months & 0b00011111;
254  return (months);
255 }
256 
257 
258 //************************************************************
259 // RTCC_set_years function implementation
260 //************************************************************
261 signed char RTCC_set_years (unsigned char years) {
262 
264 }
265 
266 
267 //************************************************************
268 // RTCC_get_years function implementation
269 //************************************************************
270 unsigned char RTCC_get_years (void) {
271 
272  unsigned char years;
274  return (years);
275 }
276 
277 
278 //************************************************************
279 // RTCC_get_date function implementation
280 //************************************************************
281 unsigned char* RTCC_get_date (void) {
282 
283  static unsigned char date[9];
284  unsigned char value;
285 
286  value = get_days_RTCC();
287 
288  // with +48 I convert the number in ASCII number
289  date[1] = (value & 0b00001111)+48;
290  date[0] = (value >> 4)+48;
291 
292  date[2] = '/';
293 
294  value = get_months_RTCC();
295  date[4] = (value & 0b00001111)+48;
296  date[3] = (value >> 4)+48;
297 
298  date[5] = '/';
299 
300 
301  value = get_years_RTCC();
302  date[7] = (value & 0b00001111)+48;
303  date[6] = (value >> 4)+48;
304 
305  date[8] = '\0';
306 
307  return (date);
308 
309 }
310 
311 
312 //************************************************************
313 // RTCC_set_minutes_alarm function implementation
314 //************************************************************
315 signed char RTCC_set_minutes_alarm (unsigned char minutes, unsigned char alarm_enable) {
316 
317  //I activate AE if required
318  minutes = minutes + alarm_enable;
319 
321 
322 }
323 
324 
325 //************************************************************
326 // RTCC_set_hours_alarm function implementation
327 //************************************************************
328 signed char RTCC_set_hours_alarm (unsigned char hours, unsigned char alarm_enable) {
329 
330  //I activate AE if required
331  hours = hours + alarm_enable;
333 }
334 
335 
336 //************************************************************
337 // RTCC_set_days_alarm function implementation
338 //************************************************************
339 signed char RTCC_set_days_alarm (unsigned char days, unsigned char alarm_enable) {
340 
341  //I activate AE if required
342  days = days + alarm_enable;
344 
345 }
346 
347 
348 //************************************************************
349 // RTCC_set_day_of_the_week_alarm function implementation
350 //************************************************************
351 signed char RTCC_set_day_of_the_week_alarm (unsigned char day_of_the_week_alarm, unsigned char alarm_enable) {
352 
353  //I activate AE if required
354  day_of_the_week_alarm = day_of_the_week_alarm + alarm_enable;
356 
357 }
358 
359 
360 //************************************************************
361 // RTCC_enable_alarm_interrupt function implementation
362 //************************************************************
363 signed char RTCC_enable_alarm_interrupt (void) {
364 
366 
367 }
368 
369 
370 //************************************************************
371 // RTCC_disable_alarm_interrupt function implementation
372 //************************************************************
373 signed char RTCC_disable_alarm_interrupt (void) {
374 
376 
377 }
378 
379 
380 //************************************************************
381 // RTCC_is_alarm_ON function implementation
382 //************************************************************
383 unsigned char RTCC_is_alarm_ON (void) {
384 
385  unsigned char value;
387 
388  // Just AF bit is controlled
389  if (value & 0x08) {
390 
391  value = value & 0xF7;
392 
393  // I clean AF bit without changing the other bits
395  return (1);
396 
397  } else {
398  return (0);
399  }
400 
401 }
402 
403 
404 //************************************************************
405 // RTCC_increment_minutes function implementation
406 //************************************************************
407 signed char RTCC_increment_minutes (void) {
408 
409  unsigned char minutes;
410  signed char error;
411 
412  // Read the current minutes
413  minutes = get_minutes_RTCC ();
414 
415  // Increment the minutes
416  minutes ++;
417 
418  // Check the minute limits
419 
420  if ((minutes&0x0F) > (unsigned char) 9 ) {
421  minutes &= 0xF0;
422  minutes += 0x10;
423  }
424 
425  if (minutes == (unsigned char) RTCC_MAX_MINUTES) {
426 
427  minutes = 0;
428  }
429 
430  // Update the minutes
431  error = set_minutes_RTCC (minutes);
432 
433  return (error);
434 
435 }
436 
437 
438 //************************************************************
439 // RTCC_increment_hours function implementation
440 //************************************************************
441 signed char RTCC_increment_hours (void) {
442 
443  unsigned char hours;
444  signed char error;
445 
446  // Read the current hours
447  hours = get_hours_RTCC ();
448 
449  // Increment the hours
450  hours ++;
451 
452  // Check the hour limits
453 
454  if ((hours&0x0F) > (unsigned char) 9 ) {
455  hours &= 0xF0;
456  hours += 0x10;
457  }
458 
459  if (hours == (unsigned char) RTCC_MAX_HOURS) {
460 
461  hours = 0;
462  }
463 
464  // Update the hours
465  error = set_hours_RTCC (hours);
466 
467  return (error);
468 
469 }
470 
471 
472 //************************************************************
473 // RTCC_increment_years function implementation
474 //************************************************************
475 signed char RTCC_increment_years (void) {
476 
477  unsigned char years;
478  signed char error;
479 
480  // Read the current years
481  years = get_years_RTCC ();
482 
483  // Increment the years
484  years ++;
485 
486  // Check the year limits
487 
488  if ((years&0x0F) > (unsigned char) 9 ) {
489  years &= 0xF0;
490  years += 0x10;
491  }
492 
493  if (years == (unsigned char) RTCC_MAX_YEARS) {
494 
495  years = 0;
496  }
497 
498  // Update the years
499  error = set_years_RTCC (years);
500 
501  return (error);
502 
503 }
504 
505 
506 //************************************************************
507 // RTCC_increment_months function implementation
508 //************************************************************
509 signed char RTCC_increment_months (void) {
510 
511  unsigned char months;
512  signed char error;
513 
514  // Read the current months
515  months = get_months_RTCC ();
516 
517  // Increment the months
518  months ++;
519 
520  // Check the month limits
521 
522  if ((months&0x0F) > (unsigned char) 9 ) {
523  months &= 0xF0;
524  months += 0x10;
525  }
526 
527  if (months == (unsigned char) RTCC_MAX_MONTHS) {
528 
529  months = 1;
530  }
531 
532  // Update the months
533  error = set_months_RTCC (months);
534 
535  return (error);
536 
537 }
538 
539 //************************************************************
540 // RTCC_increment_days function implementation
541 //************************************************************
542 signed char RTCC_increment_days (void) {
543 
544  unsigned char days;
545  signed char error;
546 
547  // Read the current days
548  days = get_days_RTCC ();
549 
550  // Increment the days
551  days ++;
552 
553  // Check the day limits
554 
555  if ((days&0x0F) > (unsigned char) 9 ) {
556  days &= 0xF0;
557  days += 0x10;
558  }
559 
560  if (days == (unsigned char) RTCC_MAX_DAYS) {
561 
562  days = 1;
563  }
564 
565  // Update the days
566  error = set_days_RTCC (days);
567 
568  return (error);
569 }
570