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
DS1337.h
Go to the documentation of this file.
1 /*******************************************************************************
2 
3 Author : Mauro Laurenti
4 Version : 1.4
5 Created on Date : 02/02/2013
6 Last update : 30/04/2016
7 
8 CopyRight 2006-2016 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 DS1337 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  The second alarm is not handled but it can be easily implemented.
46 
47 *******************************************************************************/
48 
49 
50 #ifndef LTLIB_DS1337_H
51 #define LTLIB_DS1337_H
52 
53 #ifdef __XC8
54  #include <xc.h>
55 #endif
56 
57 //*****************************************
58 // Library Test
59 //*****************************************
60 #include "LTlib.h"
61 
62 #ifndef LTLIB_I2C_MODULE_H
63  #error The DS1337 Library requires the "module_I2C" library to be included.
64 #endif
65 
66 #ifndef LTLIB_DELAY_H
67  #error The DS1337 Library requires the "delay" library to be included.
68 #endif
69 
70 //*****************************************
71 // I2C Module Switch
72 //*****************************************
73 #if defined (DS1337_I2C_MODULE_1) || defined (DS1337_I2C_MODULE_2)
74 
75 #else
76  #define DS1337_I2C_MODULE_1
77 #endif
78 
79 #ifdef DS1337_I2C_MODULE_1
80  #define DS1337_I2C_open I2C1_open
81  #define DS1337_I2C_baud_rate I2C1_baud_rate
82  #define DS1337_I2C_write_byte_to_external_device I2C1_write_byte_to_external_device
83  #define DS1337_I2C_read_byte_from_external_device I2C1_read_byte_from_external_device
84 #endif
85 
86 #ifdef DS1337_I2C_MODULE_2
87  #define DS1337_I2C_open I2C2_open
88  #define DS1337_I2C_baud_rate I2C2_baud_rate
89  #define DS1337_I2C_write_byte_to_external_device I2C2_write_byte_to_external_device
90  #define DS1337_I2C_read_byte_from_external_device I2C2_read_byte_from_external_device
91 #endif
92 
93 
94 //**************************************************
95 // you must change this address if
96 // you change the device.
97 //**************************************************
98 
99 #define RTCC_WRITE_ADD 0xD0
100 
101 //**************************************************
102 // Definition of Day constants (Italian, English)
103 //**************************************************
104 
105 // Italian
106 #define RTCC_DO 0x00
107 #define RTCC_LU 0x01
108 #define RTCC_MA 0x02
109 #define RTCC_ME 0x03
110 #define RTCC_GI 0x04
111 #define RTCC_VE 0x05
112 #define RTCC_SA 0x06
113 
114 // English
115 #define RTCC_SU 0x00
116 #define RTCC_MO 0x01
117 #define RTCC_TU 0x02
118 #define RTCC_WE 0x03
119 #define RTCC_TR 0x04
120 #define RTCC_FR 0x05
121 #define RTCC_SA 0x06
122 
123 
124 
125 //**************************************************
126 // Standard Constants
127 // enable value for the alarm bit
128 //**************************************************
129 
130 #define RTCC_ENABLE_ON 0b00000000
131 #define RTCC_ENABLE_OFF 0b10000000
132 
133 #define RTCC_ALARM_ENABLED 0b00000000
134 #define RTCC_ALARM_DISABLED 0b10000000
135 
136 
137 //**************************************************
138 // Address constants
139 //**************************************************
140 
141 #define RTCC_SECONDS_ADDR 0x00
142 #define RTCC_MINUTES_ADDR 0x01
143 #define RTCC_HOURS_ADDR 0x02
144 #define RTCC_DAYS_ADDR 0x04
145 #define RTCC_MONTHS_ADDR 0x05
146 #define RTCC_YEARS_ADDR 0x06
147 #define RTCC_SECONDS_ALARM_ADDR 0x07
148 #define RTCC_MINUTS_ALARM_ADDR 0x08
149 #define RTCC_HOURS_ALARM_ADDR 0x09
150 #define RTCC_DAYS_ALARM_ADDR 0x0A
151 #define RTCC_MINUTS_ALARM_2_ADDR 0x0B
152 #define RTCC_HOURS_ALARM_2_ADDR 0x0C
153 #define RTCC_DAYS_ALARM_2_ADDR 0x0D
154 #define RTCC_CONTROL_REG_1_ADDR 0x0E
155 #define RTCC_CONTROL_REG_2_ADDR 0x0F
156 
157 //**************************************************
158 // Limits constants
159 //**************************************************
160 #define RTCC_MAX_MINUTES 0x60
161 #define RTCC_MAX_HOURS 0x24
162 #define RTCC_MAX_YEARS 0xA0
163 #define RTCC_MAX_MONTHS 0x13
164 #define RTCC_MAX_DAYS 0x32
165 
178 void RTCC_initialize (unsigned int baud_rate_KHz);
179 #define initialize_RTTC RTCC_initialize
180 
181 
194 signed char RTCC_set_seconds (unsigned char seconds);
195 #define set_seconds_RTCC RTCC_set_seconds
196 
197 
205 unsigned char RTCC_get_seconds (void);
206 #define get_seconds_RTCC RTCC_get_seconds
207 
208 
221 signed char RTCC_set_minutes (unsigned char minutes);
222 #define set_minutes_RTCC RTCC_set_minutes
223 
231 unsigned char get_minutes_RTCC (void);
232 #define get_minutes_RTCC RTCC_get_minutes
233 
234 
247 signed char RTCC_set_hours (unsigned char hours);
248 #define set_hours_RTCC RTCC_set_hours
249 
250 
258 unsigned char RTCC_get_hours (void);
259 #define get_hours_RTCC RTCC_get_hours
260 
261 
268 unsigned char* RTCC_get_time_seconds (void);
269 #define get_time_seconds_RTCC RTCC_get_time_seconds
270 
271 
278 unsigned char* RTCC_get_time (void);
279 #define get_time_RTCC RTCC_get_time
280 
281 
294 signed char RTCC_set_days (unsigned char days);
295 #define set_days_RTCC RTCC_set_days
296 
297 
305 unsigned char RTCC_get_days (void);
306 #define get_days_RTCC RTCC_get_days
307 
308 
309 
322 signed char RTCC_set_months (unsigned char months);
323 #define set_months_RTCC RTCC_set_months
324 
325 
333 unsigned char RTCC_get_months (void);
334 #define get_months_RTCC RTCC_get_months
335 
336 
350 signed char RTCC_set_years (unsigned char years);
351 #define set_years_RTCC RTCC_set_years
352 
353 
361 unsigned char RTCC_get_years (void);
362 #define get_years_RTCC RTCC_get_years
363 
364 
365 
372 unsigned char* RTCC_get_date (void);
373 #define get_date_RTCC RTCC_get_date
374 
375 
392 signed char RTCC_set_seconds_alarm (unsigned char seconds, unsigned char alarm_enable);
393 #define set_seconds_alarm_RTCC RTCC_set_seconds_alarm
394 
411 signed char RTCC_set_minutes_alarm (unsigned char minutes, unsigned char alarm_enable);
412 #define set_minutes_alarm_RTCC RTCC_set_minutes_alarm
413 
414 
431 signed char RTCC_set_hours_alarm (unsigned char hours, unsigned char alarm_enable);
432 #define set_hours_alarm_RTCC RTCC_set_hours_alarm
433 
450 signed char RTCC_set_days_alarm (unsigned char days, unsigned char alarm_enable);
451 #define set_days_alarm_RTCC RTCC_set_days_alarm
452 
453 
464 signed char RTCC_enable_alarm_interrupt (void);
465 #define enable_alarm_interrupt_RTCC RTCC_enable_alarm_interrupt
466 
467 
478 signed char RTCC_disable_alarm_interrupt (void);
479 #define disable_alarm_interrupt_RTCC RTCC_disable_alarm_interrupt
480 
481 
490 unsigned char RTCC_is_alarm_ON (void);
491 #define is_alarm_ON_RTCC RTCC_is_alarm_ON
492 
493 
505 signed char RTCC_increment_minutes (void);
506 #define increment_minutes_RTCC RTCC_increment_minutes
507 
508 
520 signed char RTCC_increment_hours (void);
521 #define increment_hours_RTCC RTCC_increment_hours
522 
523 
535 signed char RTCC_increment_years (void);
536 #define increment_years_RTCC RTCC_increment_years
537 
538 
550 signed char RTCC_increment_months (void);
551 #define increment_months_RTCC RTCC_increment_months
552 
553 
566 signed char RTCC_increment_days (void);
567 #define increment_days_RTCC RTCC_increment_days
568 
569 
570 #endif
571