Sensorian
1.0
C API Reference Guide Library
Main Page
Related Pages
Modules
Data Structures
Files
Examples
File List
Globals
main.c
Go to the documentation of this file.
1
/****************************************************************************
2
* Copyright (C) 2015 Sensorian
3
* *
4
* This file is part of Sensorian. *
5
* *
6
* Sensorian is free software: you can redistribute it and/or modify it *
7
* under the terms of the GNU Lesser General Public License as published *
8
* by the Free Software Foundation, either version 3 of the License, or *
9
* (at your option) any later version. *
10
* *
11
* Sensorian is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Lesser General Public License for more details. *
15
* *
16
* You should have received a copy of the GNU Lesser General Public *
17
* License along with Sensorian. *
18
* If not, see <http://www.gnu.org/licenses/>. *
19
****************************************************************************/
20
30
#include <stdio.h>
31
#include <stdlib.h>
32
#include <stdbool.h>
33
#include "
MCP79410.h
"
34
#include "
Utilities.h
"
35
#include "
i2c.h
"
36
37
int
main
(
int
argc,
char
**argv)
38
{
39
RTCC_Struct
*powerDown_Time = (
RTCC_Struct
*) malloc(
sizeof
(
RTCC_Struct
));
40
RTCC_Struct
*powerUp_Time = (
RTCC_Struct
*) malloc(
sizeof
(
RTCC_Struct
));
41
RTCC_Struct
*current_time = (
RTCC_Struct
*) malloc(
sizeof
(
RTCC_Struct
));
42
43
I2C_Initialize
(
MCP79410_ADDRESS
);
//Initialize I2C and setup chip address
44
45
if
(
MCP79410_IsVbatEnabled
())
46
{
47
printf(
"Battery mode Enabled.\r\n"
);
48
}
else
{
49
printf(
"Battery mode Disabled. Enabling ..\r\n"
);
50
MCP79410_EnableVbat
();
51
}
52
53
powerDown_Time =
MCP79410_GetPowerDownTime
();
54
printf(
"Power down time: %d-%d %d:%d:\r\n"
, powerDown_Time->
month
, powerDown_Time->
date
, powerDown_Time->
hour
, powerDown_Time->
min
);
55
56
powerUp_Time =
MCP79410_GetPowerUpTime
();
57
printf(
"Power up time: %d-%d %d:%d:\r\n\r\n"
, powerUp_Time->
month
, powerUp_Time->
date
, powerUp_Time->
hour
, powerUp_Time->
min
);
58
59
if
(
MCP79410_CheckPowerFailure
())
60
{
61
printf(
"There was a power failure.\r\n"
);
62
}
else
{
63
printf(
"No power failure.\r\n"
);
64
}
65
66
while
(1)
67
{
68
current_time =
MCP79410_GetTime
();
69
printf(
"now: %d-%d-%d %d:%d:%d\n"
, current_time->
year
, current_time->
month
, current_time->
date
, current_time->
hour
, current_time->
min
, current_time->
sec
);
70
delay_ms
(1000);
71
}
72
73
I2C_Close
();
//Return I2C pins to default status
74
75
return
0;
76
}
77
78
i2c.h
I2C driver.
MCP79410_ADDRESS
#define MCP79410_ADDRESS
The I2C address of the MCP79410 real time clock and calendar.
Definition:
MCP79410.h:45
_RTCC_Struct::year
unsigned char year
Month.
Definition:
MCP79410.h:151
I2C_Close
void I2C_Close(void)
Closes the I2C peripheral.
Definition:
i2c.c:174
_RTCC_Struct::date
unsigned char date
Weekday.
Definition:
MCP79410.h:149
MCP79410_CheckPowerFailure
unsigned char MCP79410_CheckPowerFailure(void)
This function checks if there was a power failure.
Definition:
MCP79410.c:465
MCP79410.h
MCP79410_GetTime
RTCC_Struct * MCP79410_GetTime(void)
The function returns a time structure with the current time from the RTCC.
Definition:
MCP79410.c:100
_RTCC_Struct::month
unsigned char month
Date of the month.
Definition:
MCP79410.h:150
_RTCC_Struct::sec
unsigned char sec
Definition:
MCP79410.h:145
Utilities.h
Utilities driver header.
_RTCC_Struct
Definition:
MCP79410.h:143
I2C_Initialize
void I2C_Initialize(unsigned char address)
Initializes the I2C peripheral.
Definition:
i2c.c:36
MCP79410_EnableVbat
void MCP79410_EnableVbat(void)
This function enables backup battery mode.
Definition:
MCP79410.c:503
main
int main(int argc, char **argv)
Definition:
main.c:34
delay_ms
void delay_ms(unsigned int ms)
Delay in ms.
Definition:
Utilities.c:39
_RTCC_Struct::min
unsigned char min
Seconds.
Definition:
MCP79410.h:146
MCP79410_GetPowerDownTime
RTCC_Struct * MCP79410_GetPowerDownTime(void)
This function returns the power-down time of the RTCC.
Definition:
MCP79410.c:543
_RTCC_Struct::hour
unsigned char hour
Minutes.
Definition:
MCP79410.h:147
MCP79410_IsVbatEnabled
unsigned char MCP79410_IsVbatEnabled(void)
This function checks if battery mode is enabled.
Definition:
MCP79410.c:486
MCP79410_GetPowerUpTime
RTCC_Struct * MCP79410_GetPowerUpTime(void)
This function returns the power-up time of the RTCC.
Definition:
MCP79410.c:527
MCP79410_RTCC
Example3
main.c
Generated on Sun Jul 12 2015 20:25:27 for Sensorian by
1.8.9.1