在好例子网,分享、交流、成长!
您当前所在位置:首页C/C++ 开发实例嵌入式开发 → STM32F103的一个日历

STM32F103的一个日历

嵌入式开发

下载此实例
  • 开发语言:C/C++
  • 实例大小:6.16M
  • 下载次数:10
  • 浏览次数:160
  • 发布时间:2021-06-12
  • 实例类别:嵌入式开发
  • 发 布 人:我滴名字七个字
  • 文件格式:.zip
  • 所需积分:2
 相关标签: 日历

实例介绍

【实例简介】

1、LCD显示年月日 时分秒 星期 信息。

2、KEY0 进入修改模式,分别可以修改 年月日时分秒(处于修改状态下,对应值会变红),最后退出修改模式。

3、在KEY0的修改模式下,按KEY1为数字 1,按KEY_UP为数字-1。


【实例截图】
【核心代码】
#include "led.h" #include "delay.h" #include "key.h" #include "sys.h" #include "lcd.h" #include "usart.h" #include "usmart.h" #include "rtc.h"  /* 显示时间,index特殊处理 */ void show_index_time( u8 index, _calendar_obj calendar_temp );  int main( void ) {  /* 按键返回值 */  u8 key = 0;  /* 修改指向下标 */  u8 index = 0;  /* 日历结构体 */  _calendar_obj calendar_temp;  /* 延时函数初始化 */  delay_init();  /* 设置中断优先级分组为组2:2位抢占优先级,2位响应优先级 */  NVIC_PriorityGroupConfig( NVIC_PriorityGroup_2 );  /* 串口初始化为115200 */  uart_init( 115200 );  /* LED端口初始化 */  LED_Init();  /* LCD初始化 */  LCD_Init();  /* 按键初始化 */  KEY_Init();  /* 初始化USMART */  usmart_dev.init( SystemCoreClock / 1000000 );  /* RTC初始化 */  RTC_Init();  /*  * 显示时间  * 设置字体为蓝色  */  POINT_COLOR = BLUE;  LCD_ShowString( 60, 130, 200, 16, 16, "    -  -  " );  LCD_ShowString( 60, 162, 200, 16, 16, "  :  :  " );  calendar_temp = calendar;  while ( 1 )  {  /* 根据index显示不同日历变量 */  if ( 0 == index )  show_index_time( index, calendar );  else show_index_time( index, calendar_temp );  /*  * 键处理函数  * 返回按键值  * mode:0,不支持连续按;1,支持连续按;  * 0,没有任何按键按下  * 1,KEY0按下  * 2,KEY1按下  * 3,KEY3按下 WK_UP  */  key = KEY_Scan( 0 );  /* KEY0 进入修改模式,依次顺序循环 */  if ( 1 == key )  {  index  ;  index = index % 7;  /* 进入修改 */  if ( 1 == index )  {  calendar_temp = calendar;  }  /* 退出修改 else if(0 == index) */  {  calendar = calendar_temp;  RTC_Set( calendar_temp.w_year, calendar_temp.w_month, calendar_temp.w_date, calendar_temp.hour, calendar_temp.min, calendar_temp.sec );  }  }  /* KEY1 选中值 1 */  else if ( 2 == key )  {  if ( 1 == index )  {  calendar_temp.w_year  ;  } else if ( 2 == index )  {  calendar_temp.w_month  ;  calendar_temp.w_month = calendar_temp.w_month > 12 ? 1 : calendar_temp.w_month;  } else if ( 3 == index )  {  /* 判断闰年 */  if ( Is_Leap_Year( calendar_temp.w_year ) )  {  calendar_temp.w_date  ;  calendar_temp.w_date = calendar_temp.w_date > (calendar_temp.w_month == 2 ? (mon_table[calendar_temp.w_month - 1]   1) : mon_table[calendar_temp.w_month - 1]) ? 1 : calendar_temp.w_date;  } else {  calendar_temp.w_date  ;  calendar_temp.w_date = calendar_temp.w_date > mon_table[calendar_temp.w_month - 1] ? 1 : calendar_temp.w_date;  }  } else if ( 4 == index )  {  calendar_temp.hour  ;  calendar_temp.hour = calendar_temp.hour > 23 ? 0 : calendar_temp.hour;  } else if ( 5 == index )  {  calendar_temp.min  ;  calendar_temp.min = calendar_temp.min > 59 ? 0 : calendar_temp.min;  } else if ( 6 == index )  {  calendar_temp.sec  ;  calendar_temp.sec = calendar_temp.sec > 59 ? 0 : calendar_temp.sec;  }  }  /* KEY_UP 选中值-1 */  else if ( 3 == key )  {  if ( 1 == index )  {  calendar_temp.w_year--;  calendar_temp.w_year = calendar_temp.w_year > 0 ? calendar_temp.w_year : 0;  } else if ( 2 == index )  {  calendar_temp.w_month--;  calendar_temp.w_month = calendar_temp.w_month > 0 ? calendar_temp.w_month : 12;  } else if ( 3 == index )  {  if ( Is_Leap_Year( calendar_temp.w_year ) )  {  calendar_temp.w_date--;  calendar_temp.w_date = calendar_temp.w_date > 0 ? calendar_temp.w_date : (calendar_temp.w_month == 2 ? (mon_table[calendar_temp.w_month - 1]   1) : mon_table[calendar_temp.w_month - 1]);  } else {  calendar_temp.w_date--;  calendar_temp.w_date = calendar_temp.w_date > 0 ? calendar_temp.w_date : mon_table[calendar_temp.w_month - 1];  }  } else if ( 4 == index )  {  calendar_temp.hour = calendar_temp.hour == 0 ? 23 : calendar_temp.hour - 1;  } else if ( 5 == index )  {  calendar_temp.min = calendar_temp.min == 0 ? 59 : calendar_temp.min - 1;  } else if ( 6 == index )  {  calendar_temp.sec = calendar_temp.sec == 0 ? 59 : calendar_temp.sec - 1;  }  }  delay_ms( 10 );  } }   /* 显示时间,index特殊处理 */ void show_index_time( u8 index, _calendar_obj calendar_temp ) {  POINT_COLOR = BLUE;  if ( 1 == index )  POINT_COLOR = RED;  LCD_ShowNum( 60, 130, calendar_temp.w_year, 4, 16 );  POINT_COLOR = BLUE;  if ( 2 == index )  POINT_COLOR = RED;  LCD_ShowNum( 100, 130, calendar_temp.w_month, 2, 16 );  POINT_COLOR = BLUE;  if ( 3 == index )  POINT_COLOR = RED;  LCD_ShowNum( 124, 130, calendar_temp.w_date, 2, 16 );  POINT_COLOR = BLUE;  if ( 4 == index )  POINT_COLOR = RED;  LCD_ShowNum( 60, 162, calendar_temp.hour, 2, 16 );  POINT_COLOR = BLUE;  if ( 5 == index )  POINT_COLOR = RED;  LCD_ShowNum( 84, 162, calendar_temp.min, 2, 16 );  POINT_COLOR = BLUE;  if ( 6 == index )  POINT_COLOR = RED;  LCD_ShowNum( 108, 162, calendar_temp.sec, 2, 16 );  POINT_COLOR = RED; }

标签: 日历

实例下载地址

STM32F103的一个日历

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警