




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、嵌入式系统课程设计报告 基于arm的万年历系统 院 系: 机电学院 学生姓名: 专 业: 应用电子技术教育 班 级: 指导教师: 田丰庆 付广春 完成时间: 2013年3月29日 目录1 引言12 stm32芯片rtc时钟介绍13 程序运行结果23.1 stm32管脚介绍23.2 stm32复位电路和时钟设计24 总体设计框图35 程序运行结果图示46 程序流程图57 总结体会58 参考文献6附录一:总体电路图7附录二:源程序8基于arm的万年历系统摘要:本设计选择stm32为核心控制元件,设计了用rtc定时器实现万年历的控制与设计。程序使用c语言进行编程,能动态显示当前时间,包括年、月、日、
2、时、分、秒,并且用串口助手显示。关键词:stm32 arm 时钟 1 引言 随着科技的发展,嵌入式系统广泛应用于工业控制和商业管理领域,在多媒体手机、袖珍电脑,掌上电脑,车载导航器等方面的应用,更是极大地促进了嵌入式技术深入到生活和工作各个方面。嵌入式系统主要由嵌入式处理器、相关支撑硬件及嵌入式软件系统组成。本文介绍基于stm32f103r6t6的嵌入式微处理器的万年历设计,并且在液晶上显示。2 stm32芯片rtc时钟介绍stm32的实时时钟(rtc)是一个独立的定时器。rtc模块拥有一组连续计数的计数器,在相应软件配置下,可以提供时钟日历的功能,修改计数器的值可以重新设置系统当前的时间和日
3、期。stm32f10x系列微控制器片上内置的rtc模块,主要特性如下:(1) 可编程的预分频系数,分频系数最高位220。(2) 32位的可编程计数器,可用于长程时间段的测量。(3) 两个单独的时钟:用于apb1接口的plck1和rtc时钟(此时rtc时钟的频率必须小于pclk1时钟的四分之一以上)。(4) 可以选择一下三种rtc的时钟源: hse(high speed external)时钟除以128,即高速外部时钟,接石英/陶瓷谐振器,或者接外部时钟源,频率范围为416mhz。 lsi(low speed internal)振荡器时钟,即低速内部时钟,频率为40khz。 lse(low sp
4、eed external)振荡器时钟,即低速外部时钟,接石英晶体,频率为32.768khz。(5)2钟独立的复位类型: apb1接口由系统复位。 rtc核(预分频器、闹钟、计数器和分频器)只能由备份域复位。(6)3个专门的可屏蔽中断:闹钟中断,用来产生一个软件可编程的闹钟中断。秒中断,用来产生一个可编程的周期性中断信号(最长可达1s)。溢出中断,检测内部可编程计数器溢出并回转为0的状态 (7)stm32侵入检测: tpal=0时启动侵入检测tamper引脚前已经为高电平,一旦启动检测功能,则会产生一个额外的侵入事件。 tpal=1时启动侵入引脚tamper前该引脚为低电平,一旦启动检测功能,则
5、会产生一个额外的侵入事件。 检测tamper上的点品变化,就会把备份寄存器的内容清空,以保护重要的数据不被非法盗取。3 stm32最小系统电路3.1 stm32芯片管脚介绍stm32f103r6t6管脚示意图,如图1所示。图1 stm32f103r6t6管脚示意图3.2 stm32复位和时钟电路设计 此电路主要是复位电路和时钟电路两部分,其中复位电路采用按键手动复位和上电自动复位组合,电路如图2(右)所示:其中7脚为stm32的复位端。时钟电路如图2(左)所示:晶振采用的是8mhz和32.786khz,8mkz分别接stm32的5脚和6脚,32.786khz分别接stm32的3脚和4脚。图2
6、stm32复位和时钟电路4 总体设计框图 本电路主要由3大部分电路组成:arm最小系统电路、时钟显示电路和闹钟警报电路(本设计用led灯指示)。其中atm最小系统主要由复位电路和时钟电路组成。在该设计中,闹钟提醒由led灯代替,当闹钟时间到的话,led灯亮,延时设定的时间后自动关闭。总体设计方框图,如图3所示。stm32 复位电路串口显示 输入时间 时钟电路图3总体设计方框图5 程序运行结果如图4所示图4 程序运行结果6 程序流程图 程序流程图,如图5所示。 图5 程序主流程和时间程序流程图7 总结与体会通过这次万年历的设计,使我对arm有了更深的理解。刚开始拿到题提目,我先是查找相关资料,从
7、图书馆和网上找到相关的课题,参考借鉴别人的设计,从而理清我们设计的思路。此次作业设计大致可以分为两部分,电路图部分和程序编程部分,其中最有难度的是程序的编写与调试。在编写程序的过程中,我遇到了各种各样的问题,工程之间的结合,对于其中的错误怎样解决,需要配置什么,更改哪里等等。对于arm我学的很浅,编程遇到问题不知道如何解决,我知道这个是我的弱点,但在这两周的课程设计中,用keil uvision4在arm开发板上进行程序调试,遇到问题解决问题,在这个过程中我收获了不少。 参考文献1 彭刚、秦志强等.基于arm cortex-m3的stm32系列嵌入式微控制器应用实践m.北京:电子工业出版社2
8、李宁.基于mdk的stm32处理器开发应用m.北京航空航天大学出版社,2008.3 王永红、徐炜、赫立平.stm32系列arm cortex-m3微控制器原理与实践m.北京航空航天大学出版社,2008.4 arm limited.cortex-m3 technical reference manual(r2p0). arm ddi 0037g 2008.5 附录一:总体电路图附录二:程序#include "stm32f10x.h"#include "stdio.h" #include "calendar.h"#include &quo
9、t;date.h"_io uint32_t timedisplay = 0;void rcc_configuration(void);void nvic_configuration(void);void gpio_configuration(void);void usart_configuration(void);int fputc(int ch, file *f);void rtc_configuration(void);void time_regulate(struct rtc_time *tm);void time_adjust(void);void time_display(
10、uint32_t timevar);void time_show(void);u8 usart_scanf(u32 value);#define rtcclocksource_lseu8 const *week_str = "日", "一", "二", "三", "四", "五", "六"u8 const *zodiac_sign = "猪", "鼠", "牛", "虎", &
11、quot;兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗"struct rtc_time systmtime;int main() rcc_configuration(); nvic_configuration(); gpio_configuration(); usart_configuration(); if (bkp_readbackupregister(bkp_dr1) != 0xa5a5) printf(&quo
12、t;rnn rtc not yet configured."); rtc_configuration();printf("rn rtc configured."); time_adjust();bkp_writebackupregister(bkp_dr1, 0xa5a5);elseif (rcc_getflagstatus(rcc_flag_porrst) != reset) printf("rnn power on reset occurred.");else if (rcc_getflagstatus(rcc_flag_pinrst) !
13、= reset) printf("rnn external reset occurred."); printf("rn no need to configure rtc.");rtc_waitforsynchro();rtc_itconfig(rtc_it_sec, enable);rtc_waitforlasttask(); #ifdef rtcclockoutput_enable rcc_apb1periphclockcmd(rcc_apb1periph_pwr | rcc_apb1periph_bkp, enable); pwr_backupacc
14、esscmd(enable); bkp_tamperpincmd(disable); bkp_rtcoutputconfig(bkp_rtcoutputsource_calibclock);#endif rcc_clearflag(); time_show();void rcc_configuration()systeminit();rcc_apb2periphclockcmd(rcc_apb2periph_usart1 | rcc_apb2periph_gpioa, enable);void nvic_configuration() nvic_inittypedef nvic_initstr
15、ucture; nvic_prioritygroupconfig(nvic_prioritygroup_1); nvic_initstructure.nvic_irqchannel = rtc_irqn; nvic_initstructure.nvic_irqchannelpreemptionpriority = 1; nvic_initstructure.nvic_irqchannelsubpriority = 0; nvic_initstructure.nvic_irqchannelcmd = enable; nvic_init(&nvic_initstructure);void
16、gpio_configuration() gpio_inittypedef gpio_initstructure; gpio_initstructure.gpio_pin = gpio_pin_9; gpio_initstructure.gpio_mode = gpio_mode_af_pp; gpio_initstructure.gpio_speed = gpio_speed_50mhz; gpio_init(gpioa, &gpio_initstructure); gpio_initstructure.gpio_pin = gpio_pin_10; gpio_initstructu
17、re.gpio_mode = gpio_mode_in_floating; gpio_init(gpioa, &gpio_initstructure);void usart_configuration() usart_inittypedef usart_initstructure;usart_initstructure.usart_baudrate = 115200;usart_initstructure.usart_wordlength = usart_wordlength_8b;usart_initstructure.usart_stopbits = usart_stopbits_
18、1;usart_initstructure.usart_parity = usart_parity_no ;usart_initstructure.usart_hardwareflowcontrol = usart_hardwareflowcontrol_none; usart_initstructure.usart_mode = usart_mode_rx | usart_mode_tx;usart_init(usart1, &usart_initstructure); usart_cmd(usart1, enable);int fputc(int ch, file *f) usar
19、t_senddata(usart1, (unsigned char) ch); while (!(usart1->sr & usart_flag_txe); return (ch);void rtc_configuration() rcc_apb1periphclockcmd(rcc_apb1periph_pwr | rcc_apb1periph_bkp, enable); pwr_backupaccesscmd(enable); bkp_deinit(); #ifdef rtcclocksource_lsi rcc_lsicmd(enable); while(rcc_getfl
20、agstatus(rcc_flag_lsirdy)=reset) rcc_rtcclkconfig(rcc_rtcclksource_lsi); #elif defined rtcclocksource_lse rcc_lseconfig(rcc_lse_on); while(rcc_getflagstatus(rcc_flag_lserdy)=reset) rcc_rtcclkconfig(rcc_rtcclksource_lse); #endif rcc_rtcclkcmd(enable); #ifdef rtcclockoutput_enable bkp_tamperpincmd(dis
21、able); bkp_rtccalibrationclockoutputcmd(enable); #endif rtc_waitforsynchro(); rtc_waitforlasttask(); rtc_itconfig(rtc_it_sec, enable); rtc_waitforlasttask(); #ifdef rtcclocksource_lsi rtc_setprescaler(31999); #elif defined rtcclocksource_lse rtc_setprescaler(32767); #endif rtc_waitforlasttask();void
22、 time_regulate(struct rtc_time *tm) u32 tmp_yy = 0xff, tmp_mm = 0xff, tmp_dd = 0xff, tmp_hh = 0xff, tmp_mi = 0xff, tmp_ss = 0xff; printf("rn=time settings="); printf("rn 请输入年份(please set years): 20"); while (tmp_yy = 0xff) tmp_yy = usart_scanf(99); printf("nr 年份被设置为: 20%0.2d
23、nr", tmp_yy); tm->tm_year = tmp_yy+2000; tmp_mm = 0xff; printf("rn 请输入月份(please set months): "); while (tmp_mm = 0xff) tmp_mm = usart_scanf(12); printf("nr 月份被设置为: %dnr", tmp_mm); tm->tm_mon= tmp_mm; tmp_dd = 0xff; printf("rn 请输入日期(please set dates): "); whil
24、e (tmp_dd = 0xff) tmp_dd = usart_scanf(31); printf("nr 日期被设置为: %dnr", tmp_dd); tm->tm_mday= tmp_dd; tmp_hh = 0xff; printf("rn 请输入时钟(please set hours): "); while (tmp_hh = 0xff) tmp_hh = usart_scanf(23); printf("nr 时钟被设置为: %dnr", tmp_hh ); tm->tm_hour= tmp_hh; tmp_
25、mi = 0xff; printf("rn 请输入分钟(please set minutes): "); while (tmp_mi = 0xff) tmp_mi = usart_scanf(59); printf("nr 分钟被设置为: %dnr", tmp_mi); tm->tm_min= tmp_mi; tmp_ss = 0xff; printf("rn 请输入秒钟(please set seconds): "); while (tmp_ss = 0xff) tmp_ss = usart_scanf(59); printf
26、("nr 秒钟被设置为: %dnr", tmp_ss); tm->tm_sec= tmp_ss;void time_adjust() rtc_waitforlasttask(); time_regulate(&systmtime); gregorianday(&systmtime); rtc_setcounter(mktimev(&systmtime); rtc_waitforlasttask();void time_display(uint32_t timevar) static uint32_t firstdisplay = 1; u8 s
27、tr15; to_tm(timevar, &systmtime); if(!systmtime.tm_hour && !systmtime.tm_min && !systmtime.tm_sec) | (firstdisplay) getchinacalendar(u16)systmtime.tm_year, (u8)systmtime.tm_mon, (u8)systmtime.tm_mday, str); printf("nrnr 今天农历:%0.2d%0.2d,%0.2d,%0.2d", str0, str1, str2, str3); getchinacalendarstr(u16)systmtime.tm_year,(u8)systmtime.tm_mon,(u8)systmtime.tm_mday,str); printf(" %s", str); printf("r 当前时
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 酒店促销策划技巧试题及答案
- 吊装安全操作规程
- 幼儿园安全工作总结模版
- 公司核安全文化宣贯
- 2025年医用超声治疗设备项目建议书
- 灭火器演练活动总结模版
- 2025年骨关节康复用品合作协议书
- 浮式风电机组尾流生成演化机理及机组间性能影响机制研究
- 散光儿童角膜生物力学参数特征的研究
- 基于DEMATEL-ISM法的既有建筑绿色改造影响因素分析研究
- 高一班守纪律讲规矩主题班会
- 危重患者的转运及注意事项
- 盾构机同步注浆及二次注浆施工技术总结
- 压面机机械结构设计
- 干熄焦工艺流程动画演示
- 多维阅读第15级Chichen Beat “动感小鸡”乐队
- Qingming-festival-清明节日英文介绍ppt
- SWIFT报文的结构与报文类型
- 专业技术人员年度(聘任期满)考核登记表
- 大动脉炎PPT学习教案
- 中西医结合康复治疗在冠心病PCI术后35例中的应用
评论
0/150
提交评论