ATY_LIB V2_102_230218
ATY_LIB for general devices or ALGO
 
Loading...
Searching...
No Matches
ds3231_stc8h3k.c
Go to the documentation of this file.
1// Copyright 2021 IOsetting <iosetting(at)outlook.com>
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15/***
16 * Demo: ZS-042, DS3231 I2C RTC/TCXO/Crystal
17 * Board: STC8H3K32
18 *
19 * P32 -> SCL
20 * P33 -> SDA
21 * GND -> GND
22 * 3.3V -> VCC
23 */
24
25#include "fw_hal.h"
26#include "ds3231.h"
27
28__XDATA uint8_t time[9];
29
30void I2C_Init(void)
31{
32 // Master mode
38 // Switch alternative port
40 // Start I2C
42}
43
44void GPIO_Init(void)
45{
46 // SDA
48 // SCL
50}
51
52int main(void)
53{
55 // UART1 configuration: baud 115200 with Timer2, 1T mode, no interrupt
57
58 GPIO_Init();
59 I2C_Init();
61 UART1_TxString("Status:");
62 UART1_TxHex(time[0]);
63 UART1_TxString("\r\n");
64 // Set time
66 time[0] = 2022 - 1990; // year
67 time[1] = 7; // month
68 time[2] = 7; // week day
69 time[3] = 10; // date
70 time[4] = 14; // hour
71 time[5] = 21; // minute
72 time[6] = 10; // second
74
75 while(1)
76 {
78 UART1_TxHex(time[0]);
79 UART1_TxChar('-');
80 UART1_TxHex(time[1]);
81 UART1_TxChar('-');
82 UART1_TxHex(time[3]);
83 UART1_TxChar(' ');
84 UART1_TxHex(time[4]);
85 UART1_TxChar(':');
86 UART1_TxHex(time[5]);
87 UART1_TxChar(':');
88 UART1_TxHex(time[6]);
89 UART1_TxChar(' ');
90 UART1_TxHex(time[7]);
91 UART1_TxChar(' ');
92 UART1_TxHex(time[8]);
93 UART1_TxString("\r\n");
94 SYS_Delay(1000);
95 }
96}
uint8_t DS3231_GetStatus(void)
Definition: ds3231.c:34
uint8_t DS3231_SetTime(uint8_t *t)
Definition: ds3231.c:78
uint8_t DS3231_GetTime(uint8_t *t)
Definition: ds3231.c:40
@ DS3231_FORMAT_24H
Definition: ds3231.h:65
int main(void)
void I2C_Init(void)
void GPIO_Init(void)
__XDATA uint8_t time[9]
#define GPIO_P3_SetMode(__PINS__, __MODE__)
Definition: fw_gpio.h:89
@ GPIO_Pin_2
Definition: fw_gpio.h:47
@ GPIO_Pin_3
Definition: fw_gpio.h:48
@ GPIO_Mode_Output_PP
Definition: fw_gpio.h:24
@ GPIO_Mode_InOut_QBD
Definition: fw_gpio.h:23
#define I2C_SetClockPrescaler(__DIV__)
Definition: fw_i2c.h:71
@ I2C_WorkMode_Master
Definition: fw_i2c.h:24
#define I2C_SetWorkMode(__MODE__)
Definition: fw_i2c.h:65
#define I2C_SetEnabled(__STATE__)
Definition: fw_i2c.h:64
@ I2C_AlterPort_P32_P33
Definition: fw_i2c.h:51
#define I2C_SetPort(__ALTER_PORT__)
Definition: fw_i2c.h:121
void SYS_SetClock(void)
Definition: fw_sys.c:40
void SYS_Delay(uint16_t t)
Definition: fw_sys.c:65
@ HAL_State_ON
Definition: fw_types.h:71
unsigned char uint8_t
Definition: fw_types.h:18
void UART1_TxChar(char dat)
Definition: fw_uart.c:72
void UART1_TxString(uint8_t *str)
Definition: fw_uart.c:85
@ UART1_BaudSource_Timer2
Definition: fw_uart.h:34
void UART1_TxHex(uint8_t hex)
Definition: fw_uart.c:79
void UART1_Config8bitUart(UART1_BaudSource_t baudSource, HAL_State_t _1TMode, uint32_t baudrate)
Definition: fw_uart.c:56