-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRTCC.h
69 lines (54 loc) · 1.64 KB
/
RTCC.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/********************************************************************
Fichier : Bluetooth_module.h
---------------------------------------------------------------------
Auteur : ISMAIL BEN SALAH
Compilateur : MPLAB X
Date : 7. Août 2014
Version : 2.05
---------------------------------------------------------------------
Description : Librairie de fonctionnement du RTCC
--------------------------Modifications------------------------------
Version : 1.2
Modification : Ajout du lock
*********************************************************************/
#ifndef RTCC_H
#define RTCC_H
#include <peripheral/rtcc.h>
/*Prototypes*/
void RTCCInit(void);
void RTCCLock(void);
/*Functions*/
//Initialize the RTCC
void RTCCInit(void)
{
RTCCLock();
RTCCONbits.CAL =0;
RTCCONbits.SIDL = 0;
RTCALRMbits.ALRMEN = 0;
RtccInit();
rtccTime tm; // time structure
rtccDate dt; // date structure
tm.l = 0;
tm.sec = 0x00;
tm.min = 0x00;
tm.hour = 0x08;
dt.wday = 2;
dt.mday = 0x03;
dt.mon = 0x09;
dt.year = 0x14;
RtccSetTimeDate(tm.l, dt.l);
RtccEnable();
RtccWrEnable(1);
RtccEnable();
RtccOpen(tm.l, dt.l, 0);
RTCCONSET=0x8000; // turn on the RTCC
}
void RTCCLock (void)
{
INTDisableInterrupts(); //Disable the interrupts to configure the clock
SYSKEY = 0xaa996655; // write first unlock key to SYSKEY
SYSKEY = 0x556699aa; // write second unlock key to SYSKEY
RTCCONSET = 0x8; // set RTCWREN in RTCCONSET
INTEnableInterrupts();
}
#endif /* RTCC_H */