-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrtc.c
More file actions
127 lines (125 loc) · 2.71 KB
/
rtc.c
File metadata and controls
127 lines (125 loc) · 2.71 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include <LPC21xx.H>
#include "rtc_defines.h"
#include "types.h"
#include "lcd.h"
#include "lcd_defines.h"
// Array to hold names of days of the week
char week[][4] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
/*
Initialize the Real-Time Clock (RTC)
This function disables the RTC, sets the prescaler values,
and then enables the RTC.
*/
void RTC_Init(void) {
// Disable and reset the RTC
CCR = RTC_RESET;
#ifdef _LPC2148
// Enable the RTC & select the clock source
CCR = RTC_ENABLE | RTC_CLKSRC;
#else
// Set prescaler integer and fractional parts
PREINT = PREINT_VAL;
PREFRAC= PREFRAC_VAL;
// Enable the RTC
CCR = RTC_ENABLE;
#endif
}
/*
Get the current RTC time
hour Pointer to store the current hour
minute Pointer to store the current minute
second Pointer to store the current second
*/
void GetRTCTimeInfo(s32 *hour, s32 *minute, s32 *second){
*hour = HOUR;
*minute = MIN;
*second = SEC;
}
/*
Display the RTC time on LCD
hour value (0 23)
minute value (0 59)
second value (0 59) seperated by ':'
*/
void DisplayRTCTime(u32 hour, u32 minute, u32 second){
CmdLCD(GOTO_LINE1_POS0);
CharLCD((hour/10)+48);
CharLCD((hour%10)+48);
CharLCD(':');
CharLCD((minute/10)+48);
CharLCD((minute%10)+48);
CharLCD(':');
CharLCD((second/10)+48);
CharLCD((second%10)+48);
}
/*
Get the current RTC date
day Pointer to store the current date (1 31)
month Pointer to store the current month (1 12)
year Pointer to store the current year (four digits)
*/
void GetRTCDateInfo(s32 *date, s32 *month, s32 *year){
*date = DOM;
*month = MONTH;
*year = YEAR;
}
/*
Display the RTC date on LCD
Day of month (1 31)
Month (1 12)
Year (four digits) and seperated by '/'
*/
void DisplayRTCDate(u32 date, u32 month, u32 year){
CmdLCD(GOTO_LINE2_POS0);
CharLCD((date/10)+48);
CharLCD((date%10)+48);
CharLCD('/');
CharLCD((month/10)+48);
CharLCD((month%10)+48);
CharLCD('/');
U32LCD(year);
}
/*
Set the RTC time
Hour to set (0-23)
Minute to set (0-59)
Second to set (0-59)
*/
void SetRTCTimeInfo(u32 hour, u32 minute, u32 second){
HOUR = hour;
MIN = minute;
SEC = second;
}
/*
Set the RTC date
day of month to set (1 31)
month to set (1 12)
year to set (four digits)
*/
void SetRTCDateInfo(u32 date, u32 month, u32 year){
DOM = date;
MONTH = month;
YEAR = year;
}
/*
Get the current day of the week
dow Pointer to store Day of Week (0=Sunday, ..., 6=Saturday)
*/
void GetRTCDay(s32 *day){
*day = DOW;
}
/*
Display the current day of the week on LCD
dow (Day of Week) (0=Sunday, ..., 6=Saturday)
*/
void DisplayRTCDay(u32 dow){
CmdLCD(GOTO_LINE1_POS0+10);
StrLCD(week[dow]);
}
/*
Set the day of the week in RTC
Day of Week to set (0=Sunday, ..., 6=Saturday)
*/
void SetRTCDay(u32 day){
DOW = day;
}