Вт июн 28, 2022 17:58:37
Пт фев 17, 2023 23:34:45
typedef struct sRTC_struct{
unsigned year : 6;
unsigned month : 4;
unsigned week : 3;
unsigned date : 5;
unsigned hour : 5;
unsigned minute :6;
unsigned sec : 6;
}RTC_struct;
volatile RTC_struct rtc;
void RTC_Init(RTC_struct volatile *value)
{
RCC->CSR |= RCC_CSR_LSION;
while ( !(RCC->CSR & RCC_CSR_LSIRDY) ){}
RCC->APB1ENR |= RCC_APB1ENR_PWREN;
PWR->CR |= PWR_CR_DBP;
RCC->BDCR |= RCC_BDCR_RTCSEL_1;
RCC->BDCR |= RCC_BDCR_RTCEN;
RTC_Update(value);
}
void RTC_Update(RTC_struct volatile *value)
{
uint32_t TR, DR;
RTC->WPR = 0xCA;
RTC->WPR = 0x53;
RTC->ISR |= RTC_ISR_INIT;
while( !(RTC->ISR & RTC_ISR_INITF) ){};
RTC->PRER = (uint32_t)(99 << 16);
RTC->PRER |= (uint32_t)399;
TR = ( ((uint32_t)(value->hour/10*16 + value->hour%10) << 16) | ((uint32_t)(value->minute/10*16 + value->minute%10) << 8) | ((uint32_t)value->sec/10*16 + value->sec%10) );
RTC->TR = TR;
DR = (uint32_t)(value->year/10*16 + value->year%10) << 16 | (uint32_t)(value->week/10*16 + value->week%10) << 13 | (uint32_t)(value->month/10*16 + value->month%10) << 8 | (uint32_t)(value->date/10*16 + value->date%10);
RTC->DR = DR;
RTC->ISR &= ~(RTC_ISR_INIT);
RTC->WPR = 0xFF;
}
volatile RTC_struct rtn;
rtn.year = 23;// RTC_Init(rtc);
rtn.month = 4;
rtn.week = 3;
rtn.date = 17;
rtn.hour = 15;
rtn.minute = 45;
rtn.sec = 30;
RTC_Init(rtn.date);
Пт фев 17, 2023 23:56:18