STM32 PC13 配置成GPIO

CUBE_MX 5.21版本

RTC 设置

Activate Clock Source 选中

RTC OUT 选 No  RTC Output

然后生成的代码PC13可做GPIO.

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
要在 Keil 中使用 RTC 绘制时钟,需要先配置 RTC 模块并连接到相应的外部时钟源。然后可以使用 Keil 的图形库来绘制时钟的外观。 以下是一个简单的示例代码,可以在 Keil 中使用 STM32F4 开发板绘制时钟: ```c #include "stm32f4xx.h" #include "GLCD.h" #include <stdio.h> #define RTC_CLOCK_SOURCE_LSI #ifdef RTC_CLOCK_SOURCE_LSI #define RTC_ASYNCH_PREDIV 0x7F #define RTC_SYNCH_PREDIV 0x0138 #endif void RTC_Config(void) { RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); PWR_BackupAccessCmd(ENABLE); RCC_BackupResetCmd(ENABLE); RCC_BackupResetCmd(DISABLE); RCC_LSEConfig(RCC_LSE_ON); while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET); RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); RCC_RTCCLKCmd(ENABLE); RTC_InitTypeDef RTC_InitStructure; RTC_InitStructure.RTC_AsynchPrediv = RTC_ASYNCH_PREDIV; RTC_InitStructure.RTC_SynchPrediv = RTC_SYNCH_PREDIV; RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24; RTC_InitStructure.RTC_AutomaticWakeUp = RTC_AutomaticWakeUp_Disable; RTC_InitStructure.RTC_DateStruct.RTC_Date = 1; RTC_InitStructure.RTC_DateStruct.RTC_Month = RTC_Month_January; RTC_InitStructure.RTC_DateStruct.RTC_WeekDay = RTC_Weekday_Monday; RTC_InitStructure.RTC_DateStruct.RTC_Year = 0; RTC_Init(&RTC_InitStructure); RTC_WriteProtectionCmd(DISABLE); } void RTC_SetTime(uint32_t Time) { RTC_TimeTypeDef RTC_TimeStruct; RTC_TimeStruct.RTC_H12 = RTC_H12_AM; RTC_TimeStruct.RTC_Hours = (Time / 3600) % 24; RTC_TimeStruct.RTC_Minutes = (Time / 60) % 60; RTC_TimeStruct.RTC_Seconds = Time % 60; RTC_SetTime(RTC_Format_BCD, &RTC_TimeStruct); } void RTC_GetTime(uint32_t *Time) { RTC_TimeTypeDef RTC_TimeStruct; RTC_GetTime(RTC_Format_BCD, &RTC_TimeStruct); *Time = RTC_TimeStruct.RTC_Hours * 3600 + RTC_TimeStruct.RTC_Minutes * 60 + RTC_TimeStruct.RTC_Seconds; } void DrawClock(uint32_t Time) { GLCD_Clear(White); GLCD_Circle(120, 120, 100, Black, NO_FILL); GLCD_Line(120, 120, 120 + 80 * sin(Time * 2 * 3.1415926 / 3600), 120 - 80 * cos(Time * 2 * 3.1415926 / 3600), Black); GLCD_Line(120, 120, 120 + 60 * sin(Time * 2 * 3.1415926 / 60), 120 - 60 * cos(Time * 2 * 3.1415926 / 60), Black); GLCD_Line(120, 120, 120 + 40 * sin(Time * 2 * 3.1415926 / 60), 120 - 40 * cos(Time * 2 * 3.1415926 / 60), Black); GLCD_Line(120, 120, 120 + 20 * sin(Time * 2 * 3.1415926 / 60), 120 - 20 * cos(Time * 2 * 3.1415926 / 60), Black); } int main(void) { GLCD_Init(); GLCD_Clear(White); RTC_Config(); uint32_t Time; RTC_GetTime(&Time); while (1) { RTC_GetTime(&Time); DrawClock(Time); } } ``` 这段代码使用 RTC 模块获取当前时间,并使用图形库在屏幕上绘制时钟外观。你可以根据需要进行修改和优化。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值