-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRTC.c
70 lines (64 loc) · 1.82 KB
/
RTC.c
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
#include <stdio.h>
#include <LPC23xx.H> /* LPC23xx definitions */
#include "LCD.h" /* Graphic LCD function prototypes */
int j,hr,min,sec;
char hrVal[2];
char minVal[2];
char secVal[2];
/* Import external IRQ handlers from IRQ.c file */
extern __irq void T0_IRQHandler (void);
/* Import external variables from IRQ.c file */
extern unsigned char clock_1s;
int main (void) {
/* Enable and setup timer interrupt, start timer */
T0MR0 = 11999; /* 1msec = 12000-1 at 12.0 MHz */
T0MCR = 3; /* Interrupt and Reset on MR0 */
T0TCR = 1; /* Timer0 Enable */
VICVectAddr4 = (unsigned long)T0_IRQHandler;/* Set Interrupt Vector */
VICVectCntl4 = 15; /* use it for Timer0 Interrupt */
VICIntEnable = (1 << 4); /* Enable Timer0 Interrupt */
lcd_init();
lcd_clear();
lcd_print ("Time");
set_cursor (0, 1);
lcd_print ("00:00:00");
while (1) { /* Loop forever */
if (clock_1s) {
clock_1s = 0;
sec++ ;
if (sec==60){
sec = 0;
min++;
if(min==60){
min = 0;
hr++ ;
if (hr==24){
hr = 0;
}
}
}
sprintf(hrVal, "%02i",hr);
sprintf(minVal, "%02i", min);
sprintf(secVal, "%02i", sec);
set_cursor(0,1);
for (j = 0; j < 2; j++)
{
lcd_putchar(hrVal[j]);
}
set_cursor(2,1);
lcd_print ( ":");
set_cursor(3,1);
for (j = 0; j < 2; j++)
{
lcd_putchar(minVal[j]);
}
set_cursor(5,1);
lcd_print ( ":");
set_cursor(6,1);
for (j = 0; j < 2; j++)
{
lcd_putchar(secVal[j]);
}
}
}
}