ATY_LIB V2_102_230218
ATY_LIB for general devices or ALGO
 
Loading...
Searching...
No Matches
rtc_interrupt.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: RTC
17 * Board: STC8H8K64U
18 *
19 * Note: Cx51 compiler supports interrupt 0~31 only, for interrupts greater
20 * than 31, you need to
21 1. Define the handler in EXTI_VectUser(vector:006BH)
22 2. add an asm code to redirect the interrupt from EXTI_VectRTC(
23 vector:0123H) to EXTI_VectUser(vector:006BH)
24
25 ASM code example:
26
27 CSEG AT 0123H ; vector address of EXTI_VectRTC
28 LJMP 006BH ; jump to vector address of EXTI_VectUser
29 END
30 *
31 *
32 */
33
34#include "fw_hal.h"
35
37
38#if defined __CX51__ || defined __C51__
39INTERRUPT(RTC_Routine, EXTI_VectUser)
40#else
41INTERRUPT(RTC_Routine, EXTI_VectRTC)
42#endif
43{
44 SFRX_ON();
46 {
48 year = YEAR;
49 month = MONTH;
50 day = DAY;
51 hour = HOUR;
52 minute = MIN;
53 second = SEC;
54 }
56}
57
58void RTC_Init(void)
59{
60 // Enable internal 32kHz OSC
62 // Set RTC clock source
64 // Set clock initial value
65 RTC_ConfigClock(22, 1, 9, 18, 59, 03, 0);
66 // Init clock
68 // Enable second interrupt
70 // Enable global interrupt
72 // Clear interrupts
74 // Enable RTC
76}
77
78int main(void)
79{
82 RTC_Init();
83
84 while(1)
85 {
86 SFRX_ON();
87 UART1_TxString("RTCCR:");
89 UART1_TxString(" RTCCFG:");
91 UART1_TxString(" RTCIEN:");
93 UART1_TxString(" RTCIF:");
95 SFRX_OFF();
96 UART1_TxString(" Year:");
98 UART1_TxString(" Month:");
100 UART1_TxString(" Day:");
102 UART1_TxString(" Hour:");
104 UART1_TxString(" Minute:");
106 UART1_TxString(" Second:");
108 UART1_TxString("\r\n");
109 SYS_Delay(900);
110 }
111}
INTERRUPT(ADC_Routine, EXTI_VectADC)
#define EXTI_VectRTC
Definition: fw_exti.h:86
#define EXTI_RTC_SetSecondIntState(__STATE__)
Definition: fw_exti.h:155
#define EXTI_Global_SetIntState(__STATE__)
Definition: fw_exti.h:115
#define EXTI_VectUser
Definition: fw_exti.h:50
#define RTCIF
Definition: fw_reg_stc8g.h:338
#define MONTH
Definition: fw_reg_stc8g.h:351
#define HOUR
Definition: fw_reg_stc8g.h:353
#define DAY
Definition: fw_reg_stc8g.h:352
#define YEAR
Definition: fw_reg_stc8g.h:350
#define RTCIEN
Definition: fw_reg_stc8g.h:337
#define SEC
Definition: fw_reg_stc8g.h:355
#define RTCCFG
Definition: fw_reg_stc8g.h:336
#define MIN
Definition: fw_reg_stc8g.h:354
#define RTCCR
Definition: fw_reg_stc8g.h:335
#define RTC_SetRunState(__STATE__)
Definition: fw_rtc.h:27
@ RTC_ClockSource_Internal
Definition: fw_rtc.h:24
#define RTC_ClearSecondInterrupt()
Definition: fw_rtc.h:44
#define RTC_ConfigClockApply()
Definition: fw_rtc.h:29
#define RTC_IsSecondInterrupt()
Definition: fw_rtc.h:43
#define RTC_ConfigClock(__YEAR__, __MON__, __DAY__, __HOUR__, __MIN__, __SEC__, __SSEC__)
Definition: fw_rtc.h:66
#define RTC_SetClockSource(__SOURCE__)
Definition: fw_rtc.h:28
#define RTC_ClearAllInterrupts()
Definition: fw_rtc.h:34
#define SYS_EnableOscillatorLSI()
Definition: fw_sys.h:75
void SYS_SetClock(void)
Definition: fw_sys.c:40
void SYS_Delay(uint16_t t)
Definition: fw_sys.c:65
#define SFRX_ON()
Definition: fw_types.h:112
@ HAL_State_ON
Definition: fw_types.h:71
unsigned char uint8_t
Definition: fw_types.h:18
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
void RTC_Init(void)
Definition: rtc_interrupt.c:58
uint8_t month
Definition: rtc_interrupt.c:36
uint8_t day
Definition: rtc_interrupt.c:36
uint8_t year
Definition: rtc_interrupt.c:36
int main(void)
Definition: rtc_interrupt.c:78
uint8_t second
Definition: rtc_interrupt.c:36
uint8_t minute
Definition: rtc_interrupt.c:36
SFRX_OFF()
uint8_t hour
Definition: rtc_interrupt.c:36