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