STM32实时时钟和闹钟程序
《STM32实时时钟和闹钟程序》由会员分享,可在线阅读,更多相关《STM32实时时钟和闹钟程序(10页珍藏版)》请在装配图网上搜索。
1、include ”lcd.h“#include delay.h#includc sys.h include ”lcd.h” #include usart.h #include rtc.h int main(void)u8 t=O;delay_init();/2:29600NVIC_Configuration();/ NVIC2uart_init(9600);/LEDJiiit();/LEDLCD_Init();BEEPJnit();/RTC_Iiiit();/RTCPOINT_COLOR=GREEN;/LCD_ShowString(70.50.2006.16,”人_人 andy A_A,1):
2、POINT_COLOR=BLUE;/LCD_ShowString(60.130.200.16.16.” ”);LCD_ShowString(6062,200.16.16,” : ”);while( 1)if(t!=calendar.sec)t=calendar.sec;LCD_ShowNum(60,130,calendar. w_ycar,4,16);LCD_ShowNuni( 10030,calendar. w_month,2.16);LCD_ShowNum(l 24.130xalendar.w_datc.2 16): switch(calendar.week)case 0:LCD_Show
3、String(6048.2006.16.Sunday”);break;case 1:LCD_ShowString(604&200.16.16. Monday”);break;case 2:LCD.ShowString(60 J48,200.16J 6/Tuesday ”);break;case 3:LCD_ShowString(60,148,200,16.16. Wednesday); break;case 4:LCD_ShowString(604&200.16.16.“Thursday ”); break;case 5:LCD_ShowString(60, 48,200J 6,16.M Fr
4、iday”);break;case 6:LCD_ShowString(604&2006.16.,fSaturday ”): break;)LCD_S howNu m( 6062,calendar.hour.2.16):LCD_ShowNum( 84,162,calendar.niin.2.16);LCD_ShowNum(i08.162.calendar.sec.2.16):LED0=!LED0;)dclay_ins(10);)#includc sys.h#include delay.h#include usart.hinclude ”rlc.h”_calendar_obj calendar:/
5、static void RTC_NVIC_Config(void)NVIC_InitTypeDcf NVIC_InitStructure;NVICJnitStructure.NVICJRQChannel = RTCRQn:/RTCNVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; /3NVICJnitStructure.NVICJRQChannelSubPriority = 0:/0NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; / NVICJnit(&NVICnitStructur
6、e);/ NVIC.InitStructNVICu8 RTC_Init(void)4/u8 temp=O;u32 flag=O:if (BKP_RcadBackupRcgistcr(BKP_DR 1) != 0x5050)/RCC.APB 1 PcriphClockCmd(RCC_APB 1 Pcriph.PWR I RCC.APB 1 Periph.BKRENABLE); / PWR BKPPWR_BackupAccessCmd(ENABLE); /BKP_DcInit();/RCC_LSEConfig(RCC_LSE_ON); /(LSE),while (RCC_GetFlagStatus
7、(RCC_FLAG_LSERDY)= RESET) /RCC,temp+; dclay_ms(10);i f( te mp=250)rctur n 1;RCC_RTCCLKConfig(RCC_RTCCLKSourc/e_LSE);9/RTC(RTCCLK).LSERTCRCC_RTCCLKCmd(ENABLE);/RTCRTC_WaitForLastTask();/RTCRTC_WaitForSynchro();/RTCRTC_ITConfig( RTC_IT_SEC. ENABLE);/RTCRTC.ITConfig(RTC_IT_ALR. ENABLE);RTC_WaitForLastT
8、ask();/RTCRTC_Entei*ConfigMode();IIIRTC_SctPrescalcr(32767);/RTCRTC_WaitForLastTask();IIRTCRTC_Set(2014,12.2.10,0,55);/RTC_ExitConfigMode():IIflag=RTC_GetCounter();RTC_WaitForLastTask();RTC_SetAlarm( flag+1);IIBKP_WritcBackupRcgister(BKP_DR 1. OX5O5O):IIIIelseRTC_WaitForSynchro();RTCRTCTConfig(RTCT_
9、SEC. ENABLE);RTC_ITConlig( RTC_IT_ALR. ENABLE);RTC_WaitForLastTask():/RTC/RTCRTC_N VIC_Config();/RCTRTC_Gct(); return 0;/okvoid RTC_IRQHandler(void)u32 flag=0;if (RTC_GetITStatus(RTC_IT_SEC) != RESET) /RTC_Get();/if(RTC_GetITStatus(RTC_IT_ALR)!= RESET)/RTC_ClearITPendingBit(RTC_IT_ALR);/LED1=!LED1;/
10、flag=RTC_GetCounter();RTC_WaitForLastTask();RTC_SetAlarm( flag+1);/ledRTC_Clc“fTTPcndingBit(RTCT_SECIRTC_IT_OW); / RTC_WaitForLastTask();/12 3 4 5 678 9 10 1112/3129 31 30 31 3031313031 30 31/3128 31 30 31 30 313130 31 30 31/ :/ : .1, .0,u8 Is_Leap_Year(u 16 year)if(year%4=0)if(year% 100=0)if(year%4
11、00=0)rcturn 1:/400else return 0;else return 1;Jelse return 0;/197011/1970-2099/ :0. ; : ./u8 const table_week 12=03.3.6J4625.0.3.5; /const u8 mon_table 12=31,28,31,30,31,30,31.31,30,31.30.31;u8 RTC_Set(ul6 syear,u8 smoiruS sday.uS hour,u8 min,u8 sec)ul6 t;u32 seccount=0;if(syear2099)return 1:for(t=
12、1970;tsyear:t+)/if(Is 丄 eap_ Year( t) )seccount+=31622400;/else seccount+=31536000;/smon-=l;for(t=0;t=365) if(Is_Leap_Year(templ)/ if(temp=366)temp-=366;/ else tcmpl+:brcaki)/1970else temp-=365;/templ+;)calendar.w_year=templ 7/ temp 1=0;while( temp=28)/if(Is_Leap_Year(calendar.w_year)&templ= 1)/ if(
13、te mp=29 )te mp-=29 JIelse break:/2elseif(tenip=nion_tablctenipl)tcnip-=mon_tablctcmpl;/ else break;templ+:)calendar. w_month=temp 1 +1: /calendar. w_date=tenip+1;/tcmp=timccount%86400;/calendar.hour=temp/3600;/calendar, mi n=(temp%3600)/60; /calendar.sec=(temp%3600)%60; /calendar. week=RTC_Gct_Week
14、( calendar. w_year,calendar.w】Kmlh.calcndarw_d;itc);/return 0;/ :1901-2099)/u8 RTC_Get_Wcek(u 16 year,u8 month.u8 day) ul6 temp2;u8 yearHycarL;yearH=year/1 (X); yearL=year% 100:/ 21 , 100if (ycarH 19)ycarL+= 100:/1900temp2=yearL+yearL/4; temp2=temp2%7;temp2=temp2+day+table_weck( month-1: if (yearL%4=0 &m onthPB5/IO50MHz/PB.5GPIO InitStructure.GPIO Pin = GPIO Pin 5;/LED1PE5/IO/PE.5GPIO_lnit(GPIOE. &GPIOJnitStructure); 50MHzGPIO_SetBits(GPIOE.GPIO_Pin_5);
- 温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。