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
MCP7940.h
Go to the documentation of this file.
1 /*******************************************************************************
2 
3 Author : Mauro Laurenti
4 Version : 1.1
5 Created on Date : 13/03/2015
6 Last update : 16/03/2016
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 PURPOSES
36 ********************************************************
37 
38 This library supports the Real Time Clock Calendar MCP7940 or compatible
39 devices. The library is kept compatible with the PCF8563
40 
41 The following functions have been added:
42 
43  set_seconds_alarm_RTCC (seconds associated to the first alarm)
44 
45  Some flexibility has been removed to keep compatibility with
46  the other RTCC libraries.
47 
48 *******************************************************************************/
49 
50 
51 #ifndef LTLIB_MCP7940_H
52 #define LTLIB_MCP7940_H
53 
54 
55 #ifdef __XC8
56  #include <xc.h>
57 #endif
58 
59 
60 //*****************************************
61 // Library Test
62 //*****************************************
63 
64 #include "LTlib.h"
65 
66 #ifndef LTLIB_I2C_MODULE_H
67  #error The MCP7940 Library requires the "module_I2C" library to be included.
68 #endif
69 
70 #ifndef LTLIB_DELAY_H
71  #error The MCP7940 Library requires the "delay" library to be included.
72 #endif
73 
74 
75 //*****************************************
76 // I2C Module Switch
77 //*****************************************
78 #if defined (MCP7940_I2C_MODULE_1) || defined (MCP7940_I2C_MODULE_2)
79 
80 #else
81  #define MCP7940_I2C_MODULE_1
82 #endif
83 
84 
85 #ifdef MCP7940_I2C_MODULE_1
86  #define MCP7940_I2C_open I2C1_open
87  #define MCP7940_I2C_baud_rate I2C1_baud_rate
88  #define MCP7940_I2C_write_byte_to_external_device I2C1_write_byte_to_external_device
89  #define MCP7940_I2C_read_byte_from_external_device I2C1_read_byte_from_external_device
90 #endif
91 
92 #ifdef MCP7940_I2C_MODULE_2
93  #define MCP7940_I2C_open I2C2_open
94  #define MCP7940_I2C_baud_rate I2C2_baud_rate
95  #define MCP7940_I2C_write_byte_to_external_device I2C2_write_byte_to_external_device
96  #define MCP7940_I2C_read_byte_from_external_device I2C2_read_byte_from_external_device
97 #endif
98 
99 
100 //**************************************************
101 // you must change this address if
102 // you change the device.
103 //**************************************************
104 #define RTCC_WRITE_ADD 0b11011110
105 
106 //**************************************************
107 // Definition of Day constants (Italian, English)
108 //**************************************************
109 
110 // Italian
111 #define RTCC_DO 0x00
112 #define RTCC_LU 0x01
113 #define RTCC_MA 0x02
114 #define RTCC_ME 0x03
115 #define RTCC_GI 0x04
116 #define RTCC_VE 0x05
117 #define RTCC_SA 0x06
118 
119 // English
120 #define RTCC_SU 0x00
121 #define RTCC_MO 0x01
122 #define RTCC_TU 0x02
123 #define RTCC_WE 0x03
124 #define RTCC_TR 0x04
125 #define RTCC_FR 0x05
126 #define RTCC_SA 0x06
127 
128 
129 
130 //**************************************************
131 // Standard Constants
132 // enable value for the alarm bit
133 //**************************************************
134 
135 #define RTCC_ENABLE_ON 0b00000000
136 #define RTCC_ENABLE_OFF 0b10000000
137 
138 
139 //**************************************************
140 // Address constants
141 //**************************************************
142 
143 #define RTCC_SECONDS_ADDR 0x00
144 #define RTCC_MINUTES_ADDR 0x01
145 #define RTCC_HOURS_ADDR 0x02
146 #define RTCC_DAYS_ADDR 0x04
147 #define RTCC_MONTHS_ADDR 0x05
148 #define RTCC_YEARS_ADDR 0x06
149 #define RTCC_SECONDS_ALARM_ADDR 0x0A
150 #define RTCC_MINUTES_ALARM_ADDR 0x0B
151 #define RTCC_HOURS_ALARM_ADDR 0x0C
152 #define RTCC_DAYS_ALARM_ADDR 0x0E
153 #define RTCC_SECONDS_ALARM_2_ADDR 0x11
154 #define RTCC_MINUTES_ALARM_2_ADDR 0x12
155 #define RTCC_HOURS_ALARM_2_ADDR 0x13
156 #define RTCC_DAYS_ALARM_2_ADDR 0x15
157 #define RTCC_CONFIGURATION_REG_ADDR 0x07
158 #define RTCC_ALARM_CONTROL_REG_1_ADDR 0x0D
159 #define RTCC_ALARM_CONTROL_REG_2_ADDR 0x14
160 
161 //**************************************************
162 // Limits constants
163 //**************************************************
164 #define RTCC_MAX_MINUTES 0x60
165 #define RTCC_MAX_HOURS 0x24
166 #define RTCC_MAX_YEARS 0xA0
167 #define RTCC_MAX_MONTHS 0x13
168 #define RTCC_MAX_DAYS 0x32
169 
185 void RTCC_initialize (unsigned int baud_rate_KHz);
186 #define initialize_RTCC RTCC_initialize
187 
188 
197 void RTCC_start_oscillator (void);
198 #define start_oscillator_RTCC RTCC_start_oscillator
199 
200 
213 signed char RTCC_set_seconds (unsigned char seconds);
214 #define set_seconds_RTCC RTCC_set_seconds
215 
216 
224 unsigned char RTCC_get_seconds (void);
225 #define get_seconds_RTCC RTCC_get_seconds
226 
227 
240 signed char RTCC_set_minutes (unsigned char minutes);
241 #define set_minutes_RTCC RTCC_set_minutes
242 
250 unsigned char get_minutes_RTCC (void);
251 #define get_minutes_RTCC RTCC_get_minutes
252 
253 
266 signed char RTCC_set_hours (unsigned char hours);
267 #define set_hours_RTCC RTCC_set_hours
268 
269 
277 unsigned char RTCC_get_hours (void);
278 #define get_hours_RTCC RTCC_get_hours
279 
280 
287 unsigned char* RTCC_get_time_seconds (void);
288 #define get_time_seconds_RTCC RTCC_get_time_seconds
289 
290 
297 unsigned char* RTCC_get_time (void);
298 #define get_time_RTCC RTCC_get_time
299 
300 
313 signed char RTCC_set_days (unsigned char days);
314 #define set_days_RTCC RTCC_set_days
315 
316 
324 unsigned char RTCC_get_days (void);
325 #define get_days_RTCC RTCC_get_days
326 
327 
328 
341 signed char RTCC_set_months (unsigned char months);
342 #define set_months_RTCC RTCC_set_months
343 
344 
352 unsigned char RTCC_get_months (void);
353 #define get_months_RTCC RTCC_get_months
354 
355 
369 signed char RTCC_set_years (unsigned char years);
370 #define set_years_RTCC RTCC_set_years
371 
372 
380 unsigned char RTCC_get_years (void);
381 #define get_years_RTCC RTCC_get_years
382 
383 
384 
391 unsigned char* RTCC_get_date (void);
392 #define get_date_RTCC RTCC_get_date
393 
394 
411 signed char RTCC_set_seconds_alarm (unsigned char seconds, unsigned char alarm_enable);
412 #define set_seconds_alarm_RTCC RTCC_set_seconds_alarm
413 
430 signed char RTCC_set_minutes_alarm (unsigned char minutes, unsigned char alarm_enable);
431 #define set_minutes_alarm_RTCC RTCC_set_minutes_alarm
432 
433 
450 signed char RTCC_set_hours_alarm (unsigned char hours, unsigned char alarm_enable);
451 #define set_hours_alarm_RTCC RTCC_set_hours_alarm
452 
469 signed char RTCC_set_days_alarm (unsigned char days, unsigned char alarm_enable);
470 #define set_days_alarm_RTCC RTCC_set_days_alarm
471 
472 
483 signed char RTCC_enable_alarm_interrupt (void);
484 #define enable_alarm_interrupt_RTCC RTCC_enable_alarm_interrupt
485 
486 
497 signed char RTCC_disable_alarm_interrupt (void);
498 #define disable_alarm_interrupt_RTCC RTCC_disable_alarm_interrupt
499 
500 
509 unsigned char RTCC_is_alarm_ON (void);
510 #define is_alarm_ON_RTCC RTCC_is_alarm_ON
511 
512 
524 signed char RTCC_increment_minutes (void);
525 #define increment_minutes_RTCC RTCC_increment_minutes
526 
527 
539 signed char RTCC_increment_hours (void);
540 #define increment_hours_RTCC RTCC_increment_hours
541 
542 
554 signed char RTCC_increment_years (void);
555 #define increment_years_RTCC RTCC_increment_years
556 
557 
569 signed char RTCC_increment_months (void);
570 #define increment_months_RTCC RTCC_increment_months
571 
572 
585 signed char RTCC_increment_days (void);
586 #define increment_days_RTCC RTCC_increment_days
587 
588 
589 #endif
590