• 大小: 9.15MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-11-21
  • 语言: 其他
  • 标签: STM32L152  RTC  

资源简介

STM32L152 RTC 读取时间和日期,用串口将时间发送出来,测试了年月日进位都正常。

资源截图

代码片段和文件信息

/******************** (C) COPYRIGHT 2016 ZhouJun ******************************
* File Name          : main.c
 hardware  : STM32L152
* Author             : ZhouJun
* Version            : V1.0
* Date               : 20161120
* Description        : 药品追溯项目主函数
********************************************************************************/
 /*--------------------------- 头文件包含 --------------------------------------*/

#include “main.h“

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/


/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/


/* Private function prototypes -----------------------------------------------*/
void SysTickConfig(void);


//毫秒级的延时  
static void Delay_ms(u16 time) 
{        
u16 i=0;      
while(time--)    
{        
// i=12000*4/9;  //自己定义72M时为10,32M时为4/9   
// i=12000*10/27;
i=4576; //用秒表调试出来10s为10.03,要更准确就用示波器测
while(i--);         

}
/* Private functions ---------------------------------------------------------*/

/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
RTC_TimeTypeDef  tempRTC_TimeStructure; //RTC时间临时变量
  /*!< At this stage the microcontroller clock setting is already configured 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32l1xx_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function refer to
       system_stm32l1xx.c file
     */     
       
  /* RTC configuration -------------------------------------------------------*/
  RTC_Config();

InitKeyGpio();
//SX1278
//  RFInit();  //射频模块初始化
//  //RFRxMode();  //进入接收模式
//  RFM96_Config(0); //处于待机模式待机模式1.8mA
//  RFM96_Sleep();
USART_Config(); //串口设置
/* Set the time to 01h 00mn 00s AM */
SetDateTime(); //设置日期时间

RTC_GetTime(RTC_Format_BIN &RTC_TimeStructure); //得先读时间,再读日期
RTC_GetDate(RTC_Format_BIN &RTC_DateStructure);
USART3_SendChar(RTC_DateStructure.RTC_Year); //年
USART3_SendChar(RTC_DateStructure.RTC_Month); //月
USART3_SendChar(RTC_DateStructure.RTC_Date); //日

USART3_SendChar(RTC_TimeStructure.RTC_Hours); //时
USART3_SendChar(RTC_TimeStructure.RTC_Minutes); //分
USART3_SendChar(RTC_TimeStructure.RTC_Seconds); //秒
USART3_SendChar(‘\r‘);
USART3_SendChar(‘\n‘);
while(1)
{
Delay_ms(1000);

RTC_GetTime(RTC_Format_BIN &RTC_TimeStructure); //得先读时间,再读日期
RTC_GetDate(RTC_Format_BIN &RTC_DateStructure);
USART3_SendChar(RTC_DateStructure.RTC_Year); //年
USART3_SendChar(RTC_DateStructure.RTC_Month); //月
USART3_SendChar(RTC_DateStructure.RTC_Date); //日

USART3_SendChar(RTC_TimeStructure.RTC_Hours); //时
USART3_SendChar(RTC_TimeStructure.RTC_Minutes); //分

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      24914  2015-04-20 14:15  10-PWR-RTC-年月日时分秒正常\CMSIS\CMSIS END USER LICENCE AGREEMENT.pdf

     文件     505206  2015-04-20 18:56  10-PWR-RTC-年月日时分秒正常\CMSIS\Device\ST\STM32L1xx\Include\stm32l1xx.h

     文件       2220  2015-04-20 18:56  10-PWR-RTC-年月日时分秒正常\CMSIS\Device\ST\STM32L1xx\Include\system_stm32l1xx.h

     文件      33403  2015-04-20 18:56  10-PWR-RTC-年月日时分秒正常\CMSIS\Device\ST\STM32L1xx\Release_Notes.html

     文件      14803  2015-04-20 18:56  10-PWR-RTC-年月日时分秒正常\CMSIS\Device\ST\STM32L1xx\Source\Templates\arm\startup_stm32l1xx_hd.s

     文件      13020  2015-04-20 18:56  10-PWR-RTC-年月日时分秒正常\CMSIS\Device\ST\STM32L1xx\Source\Templates\arm\startup_stm32l1xx_md.s

     文件      14559  2015-04-20 18:56  10-PWR-RTC-年月日时分秒正常\CMSIS\Device\ST\STM32L1xx\Source\Templates\arm\startup_stm32l1xx_mdp.s

     文件      14729  2015-04-20 18:56  10-PWR-RTC-年月日时分秒正常\CMSIS\Device\ST\STM32L1xx\Source\Templates\arm\startup_stm32l1xx_xl.s

     文件      11998  2015-04-20 18:56  10-PWR-RTC-年月日时分秒正常\CMSIS\Device\ST\STM32L1xx\Source\Templates\gcc_ride7\startup_stm32l1xx_hd.s

     文件      10669  2015-04-20 18:56  10-PWR-RTC-年月日时分秒正常\CMSIS\Device\ST\STM32L1xx\Source\Templates\gcc_ride7\startup_stm32l1xx_md.s

     文件      11745  2015-04-20 18:56  10-PWR-RTC-年月日时分秒正常\CMSIS\Device\ST\STM32L1xx\Source\Templates\gcc_ride7\startup_stm32l1xx_mdp.s

     文件      11909  2015-04-20 18:56  10-PWR-RTC-年月日时分秒正常\CMSIS\Device\ST\STM32L1xx\Source\Templates\gcc_ride7\startup_stm32l1xx_xl.s

     文件      17100  2015-04-20 18:56  10-PWR-RTC-年月日时分秒正常\CMSIS\Device\ST\STM32L1xx\Source\Templates\iar\startup_stm32l1xx_hd.s

     文件      14563  2015-04-20 18:56  10-PWR-RTC-年月日时分秒正常\CMSIS\Device\ST\STM32L1xx\Source\Templates\iar\startup_stm32l1xx_md.s

     文件      16502  2015-04-20 18:56  10-PWR-RTC-年月日时分秒正常\CMSIS\Device\ST\STM32L1xx\Source\Templates\iar\startup_stm32l1xx_mdp.s

     文件      16918  2015-04-20 18:56  10-PWR-RTC-年月日时分秒正常\CMSIS\Device\ST\STM32L1xx\Source\Templates\iar\startup_stm32l1xx_xl.s

     文件      20175  2015-04-20 18:56  10-PWR-RTC-年月日时分秒正常\CMSIS\Device\ST\STM32L1xx\Source\Templates\system_stm32l1xx.c

     文件       3686  2015-04-20 14:15  10-PWR-RTC-年月日时分秒正常\CMSIS\Device\ST\STM32L1xx\Source\Templates\TASKING\cstart_thumb2.asm

     文件      12064  2015-04-20 18:56  10-PWR-RTC-年月日时分秒正常\CMSIS\Device\ST\STM32L1xx\Source\Templates\TrueSTUDIO\startup_stm32l1xx_hd.s

     文件      10737  2015-04-20 18:56  10-PWR-RTC-年月日时分秒正常\CMSIS\Device\ST\STM32L1xx\Source\Templates\TrueSTUDIO\startup_stm32l1xx_md.s

     文件      11806  2015-04-20 18:56  10-PWR-RTC-年月日时分秒正常\CMSIS\Device\ST\STM32L1xx\Source\Templates\TrueSTUDIO\startup_stm32l1xx_mdp.s

     文件      11975  2015-04-20 18:56  10-PWR-RTC-年月日时分秒正常\CMSIS\Device\ST\STM32L1xx\Source\Templates\TrueSTUDIO\startup_stm32l1xx_xl.s

     文件      11118  2015-04-20 14:15  10-PWR-RTC-年月日时分秒正常\CMSIS\Documentation\Core\html\annotated.html

     文件       1082  2015-04-20 14:15  10-PWR-RTC-年月日时分秒正常\CMSIS\Documentation\Core\html\annotated.js

     文件        671  2015-04-20 14:15  10-PWR-RTC-年月日时分秒正常\CMSIS\Documentation\Core\html\bc_s.png

     文件        147  2015-04-20 14:15  10-PWR-RTC-年月日时分秒正常\CMSIS\Documentation\Core\html\bdwn.png

     文件        922  2015-04-20 14:15  10-PWR-RTC-年月日时分秒正常\CMSIS\Documentation\Core\html\check.png

     文件      11104  2015-04-20 14:15  10-PWR-RTC-年月日时分秒正常\CMSIS\Documentation\Core\html\classes.html

     文件        132  2015-04-20 14:15  10-PWR-RTC-年月日时分秒正常\CMSIS\Documentation\Core\html\closed.png

     文件      20532  2015-04-20 14:15  10-PWR-RTC-年月日时分秒正常\CMSIS\Documentation\Core\html\cmsis.css

............此处省略1036个文件信息

评论

共有 条评论