ATY_LIB
V2_102_230218
ATY_LIB for general devices or ALGO
Loading...
Searching...
No Matches
main.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: RX8025T I2C RTC/TCXO
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 "
rx8025t.h
"
27
28
#define BUFF_SIZE 16
29
30
__XDATA
uint8_t
time
[
BUFF_SIZE
];
31
32
void
I2C_Init
(
void
)
33
{
34
// Master mode
35
I2C_SetWorkMode
(
I2C_WorkMode_Master
);
39
I2C_SetClockPrescaler
(0x3F);
40
// Switch alternative port
41
I2C_SetPort
(
I2C_AlterPort_P32_P33
);
42
// Start I2C
43
I2C_SetEnabled
(
HAL_State_ON
);
44
}
45
46
void
GPIO_Init
(
void
)
47
{
48
// SDA
49
GPIO_P3_SetMode
(
GPIO_Pin_3
,
GPIO_Mode_InOut_QBD
);
50
// SCL
51
GPIO_P3_SetMode
(
GPIO_Pin_2
,
GPIO_Mode_Output_PP
);
52
}
53
54
int
main
(
void
)
55
{
56
uint8_t
i
;
57
SYS_SetClock
();
58
// UART1 configuration: baud 115200 with Timer2, 1T mode, no interrupt
59
UART1_Config8bitUart
(
UART1_BaudSource_Timer2
,
HAL_State_ON
, 115200);
60
61
GPIO_Init
();
62
I2C_Init
();
63
RX8025T_Init
();
64
time
[0] = 0x10;
// second
65
time
[1] = 0x10;
// minute
66
time
[2] = 0x10;
// hour
67
time
[3] = 0x40;
// week day
68
time
[4] = 0x16;
// day
69
time
[5] = 0x07;
// month
70
time
[6] = 0x22;
// year
71
RX8025T_SetTime
(
time
);
72
73
while
(1)
74
{
75
RX8025T_GetTime
(
time
);
76
for
(
i
= 0;
i
<
BUFF_SIZE
;
i
++)
77
{
78
UART1_TxHex
(
time
[
i
]);
79
UART1_TxChar
(
'-'
);
80
}
81
UART1_TxString
(
"\r\n"
);
82
SYS_Delay
(1000);
83
}
84
}
GPIO_P3_SetMode
#define GPIO_P3_SetMode(__PINS__, __MODE__)
Definition:
fw_gpio.h:89
GPIO_Pin_2
@ GPIO_Pin_2
Definition:
fw_gpio.h:47
GPIO_Pin_3
@ GPIO_Pin_3
Definition:
fw_gpio.h:48
GPIO_Mode_Output_PP
@ GPIO_Mode_Output_PP
Definition:
fw_gpio.h:24
GPIO_Mode_InOut_QBD
@ GPIO_Mode_InOut_QBD
Definition:
fw_gpio.h:23
fw_hal.h
I2C_SetClockPrescaler
#define I2C_SetClockPrescaler(__DIV__)
Definition:
fw_i2c.h:71
I2C_WorkMode_Master
@ I2C_WorkMode_Master
Definition:
fw_i2c.h:24
I2C_SetWorkMode
#define I2C_SetWorkMode(__MODE__)
Definition:
fw_i2c.h:65
I2C_SetEnabled
#define I2C_SetEnabled(__STATE__)
Definition:
fw_i2c.h:64
I2C_AlterPort_P32_P33
@ I2C_AlterPort_P32_P33
Definition:
fw_i2c.h:51
I2C_SetPort
#define I2C_SetPort(__ALTER_PORT__)
Definition:
fw_i2c.h:121
SYS_SetClock
void SYS_SetClock(void)
Definition:
fw_sys.c:40
SYS_Delay
void SYS_Delay(uint16_t t)
Definition:
fw_sys.c:65
HAL_State_ON
@ HAL_State_ON
Definition:
fw_types.h:71
uint8_t
unsigned char uint8_t
Definition:
fw_types.h:18
UART1_TxChar
void UART1_TxChar(char dat)
Definition:
fw_uart.c:72
UART1_TxString
void UART1_TxString(uint8_t *str)
Definition:
fw_uart.c:85
UART1_BaudSource_Timer2
@ UART1_BaudSource_Timer2
Definition:
fw_uart.h:34
UART1_TxHex
void UART1_TxHex(uint8_t hex)
Definition:
fw_uart.c:79
UART1_Config8bitUart
void UART1_Config8bitUart(UART1_BaudSource_t baudSource, HAL_State_t _1TMode, uint32_t baudrate)
Definition:
fw_uart.c:56
main
int main(void)
Definition:
main.c:45
GPIO_Init
void GPIO_Init(void)
Definition:
main.c:39
I2C_Init
void I2C_Init(void)
Definition:
main.c:28
BUFF_SIZE
#define BUFF_SIZE
Definition:
main.c:28
time
__XDATA uint8_t time[BUFF_SIZE]
Definition:
main.c:30
i
uint8_t __XDATA i
Definition:
mem_read_chipid.c:24
RX8025T_SetTime
uint8_t RX8025T_SetTime(uint8_t *t)
Definition:
rx8025t.c:39
RX8025T_Init
uint8_t RX8025T_Init(void)
Definition:
rx8025t.c:24
RX8025T_GetTime
uint8_t RX8025T_GetTime(uint8_t *t)
Definition:
rx8025t.c:33
rx8025t.h
ATY_LIB
FwLib_STC8
demo
i2c
rx8025t
main.c
Generated by
1.9.6