开发板:正点原子 STM32F103 精英版
语言:C语言
开发环境:Keil5
使用了 KEY LED LCD RTC FLASH(用于存储闹钟信息) BEEP(充当闹铃)
代码参考:正点原子 源码RTC实验例程
1、LCD 显示当前时间和闹钟设定的时间 以及 停止闹钟的提示语。
2、按KEY0进入修改模式,分别可以对当前时间的时分秒和闹钟时间的时分进行修改(处于修改下的值会变红),最后退出修改模式。
3、在修改模式下:KEY1表示数值 +1,KEY_UP表示数值 -1。在普通模式下:当闹铃响起时,KEY1 和 KEY_UP可以停止闹铃。
4、闹铃在 当前时间和闹钟设定时间相同时响起,可以通过KEY1和KEY_UP结束闹铃,如果不按结束按键,闹铃则会一直响,直到到达count计数上限,才会模拟按下结束按键来停止闹铃。
5、闹钟响起时,会有闹钟标识字符串打印~
main.c
#include "led.h"
#include "delay.h"
#include "key.h"
#include "sys.h"
#include "lcd.h"
#include "usart.h"
#include "usmart.h"
#include "rtc.h"
#include "beep.h"
#include "stmflash.h"
#define FLASH_SAVE_ADDR 0X08070000 //设置FLASH 保存地址(必须为偶数,且其值要大于本代码所占用FLASH的大小+0X08000000)
/* 显示时间,index特殊处理 */
void show_index_time(u8 index, _calendar_obj calendar_temp, _calendar_obj alarm);
int main(void)
{
/* 按键返回值 */
u8 key = 0;
/* 修改指向下标 */
u8 index = 0;
/* 日历结构体 */
_calendar_obj calendar_temp;
_calendar_obj alarm;
// 修改模式标志
u8 mode = 0;
// 停止闹铃按键标志位
u8 flag = 0;
// 闹铃循环次数
u16 count = 0;
/* 延时函数初始化 */
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();
/* 初始化蜂鸣器端口 */
BEEP_Init();
/*
* 显示时间
* 设置字体为蓝色
*/
POINT_COLOR = BLUE;
LCD_ShowString(60, 130, 300, 16, 16, "N O W : : ");
LCD_ShowString(60, 162, 300, 16, 16, "ALARM : : ");
LCD_ShowString(20, 220, 200, 16, 16, "Press KEY1 or KEY_UP");
LCD_ShowString(20, 236, 200, 16, 16, "to STOP BEEP");
LCD_ShowString(20, 252, 200, 16, 16, "Press KEY0 to modify");
calendar_temp = calendar;
// 从指定地址开始读出指定长度的数据
// ReadAddr:起始地址
// pBuffer:数据指针
// NumToWrite:半字(16位)数
STMFLASH_Read(FLASH_SAVE_ADDR, (u16 *)&alarm.hour, 1);
STMFLASH_Read(FLASH_SAVE_ADDR + 0X2, (u16 *)&alarm.min, 1);
alarm.sec = 0;
while (1)
{
/* 根据index显示不同日历变量 */
if (0 == index)
show_index_time(index, calendar, alarm);
else
show_index_time(index, calendar_temp, alarm);
/*
* 键处理函数
* 返回按键值
* mode:0,不支持连续按;1,支持连续按;
* 0,没有任何按键按下
* 1,KEY0按下
* 2,KEY1按下
* 3,KEY3按下 WK_UP
*/
key = KEY_Scan(0);
/* KEY0 进入修改模式,依次顺序循环 */
if (1 == key)
{
index++;
index = index % 6;
/* 进入修改 */
if (1 == index)
{
calendar_temp = calendar;
mode = 1;
printf("Enter modify mode.\r\n");
}
/* 退出修改 */
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);
// 从指定地址开始写入指定长度的数据
// WriteAddr:起始地址(此地址必须为2的倍数!!)
// pBuffer:数据指针
// NumToWrite:半字(16位)数(就是要写入的16位数据的个数.)
STMFLASH_Write(FLASH_SAVE_ADDR, (u16 *)&alarm.hour, 1);
STMFLASH_Write(FLASH_SAVE_ADDR + 0X2, (u16 *)&alarm.min, 1);
mode = 0;
printf("modify finish! Enter normal mode.\r\n");
}
}
/* KEY1 选中值+1 */
else if (2 == key)
{
printf("KEY1 click!\r\n");
if (1 == index)
{
calendar_temp.hour++;
calendar_temp.hour = calendar_temp.hour > 23 ? 0 : calendar_temp.hour;
}
else if (2 == index)
{
calendar_temp.min++;
calendar_temp.min = calendar_temp.min > 59 ? 0 : calendar_temp.min;
}
else if (3 == index)
{
calendar_temp.sec++;
calendar_temp.sec = calendar_temp.sec > 59 ? 0 : calendar_temp.sec;
}
else if (4 == index)
{
alarm.hour++;
alarm.hour = alarm.hour > 23 ? 0 : alarm.hour;
}
else if (5 == index)
{
alarm.min++;
alarm.min = alarm.min > 59 ? 0 : alarm.min;
}
else if (0 == index)
{
// 按键标志位置1 停止蜂鸣器 计数归零
flag = 1;
BEEP = 0;
count = 0;
printf("flag = 1, BEEP = 0, count = 0\r\n");
}
}
/* KEY_UP 选中值-1 */
else if (3 == key)
{
printf("KEY_UP click!\r\n");
if (1 == index)
{
calendar_temp.hour = calendar_temp.hour == 0 ? 23 : calendar_temp.hour - 1;
}
else if (2 == index)
{
calendar_temp.min = calendar_temp.min == 0 ? 59 : calendar_temp.min - 1;
}
else if (3 == index)
{
calendar_temp.sec = calendar_temp.sec == 0 ? 59 : calendar_temp.sec - 1;
}
else if (4 == index)
{
alarm.hour = alarm.hour == 0 ? 23 : alarm.hour - 1;
}
else if (5 == index)
{
alarm.min = alarm.min == 0 ? 59 : alarm.min - 1;
}
else if (0 == index)
{
// 按键标志位置1 停止蜂鸣器 计数归零
flag = 1;
BEEP = 0;
count = 0;
printf("flag = 1, BEEP = 0, count = 0\r\n");
}
}
else if (0 == key)
{
// 普通模式下
if (0 == mode)
{
// 闹钟到点 && 蜂鸣器没叫 && 没有按下KEY1或KEY_UP键
if (calendar.hour == alarm.hour && calendar.min == alarm.min && BEEP == 0 && 0 == flag)
{
BEEP = 1;
printf("Start BEEP!\r\n");
}
// 闹钟没到点 && 按下了KEY1或KEY_UP键
else if ((calendar.hour != alarm.hour || calendar.min != alarm.min) && 1 == flag)
{
flag = 0;
}
}
}
// 闹铃循环次数计数
if (1 == BEEP)
{
POINT_COLOR = RED;
LCD_ShowString(20, 204, 200, 16, 16, "BEEP!!! (>__<) ");
POINT_COLOR = BLUE;
count++;
// printf("1 == BEEP, count++\r\n");
}
else
{
LCD_ShowString(20, 204, 200, 16, 16, " <(^ v ^)>");
}
// 闹铃循环次数达到峰值
if (5 * 6000 <= count)
{
// 按键标志位置1 停止蜂鸣器 计数归零
flag = 1;
BEEP = 0;
count = 0;
printf("5 * 6000 <= count, Stop BEEP, flag = 1, count = 0\r\n");
}
delay_ms(10);
}
}
/* 显示时间,index特殊处理 */
void show_index_time(u8 index, _calendar_obj calendar_temp, _calendar_obj alarm)
{
// 修改颜色
POINT_COLOR = BLUE;
// 修改模式下,显示红色
if (1 == index)
POINT_COLOR = RED;
/*
显示数字,高位为0,则不显示
x,y :起点坐标
num:数值(0~999999999);
len:长度(即要显示的位数)
size:字体大小
mode:
[7]:0,不填充;1,填充0.
[6:1]:保留
[0]:0,非叠加显示;1,叠加显示.
*/
// BIN 1000000 -> DEC 128
LCD_ShowxNum(116, 130, calendar_temp.hour, 2, 16, 128);
POINT_COLOR = BLUE;
if (2 == index)
POINT_COLOR = RED;
LCD_ShowxNum(140, 130, calendar_temp.min, 2, 16, 128);
POINT_COLOR = BLUE;
if (3 == index)
POINT_COLOR = RED;
LCD_ShowxNum(164, 130, calendar_temp.sec, 2, 16, 128);
POINT_COLOR = BLUE;
if (4 == index)
POINT_COLOR = RED;
LCD_ShowxNum(116, 162, alarm.hour, 2, 16, 128);
POINT_COLOR = BLUE;
if (5 == index)
POINT_COLOR = RED;
LCD_ShowxNum(140, 162, alarm.min, 2, 16, 128);
POINT_COLOR = BLUE;
LCD_ShowxNum(164, 162, alarm.sec, 2, 16, 128);
}
main.c
#include "led.h"
#include "delay.h"
#include "key.h"
#include "sys.h"
#include "lcd.h"
#include "usart.h"
#include "usmart.h"
#include "rtc.h"
#include "beep.h"
#include "stmflash.h"
#define FLASH_SAVE_ADDR 0X08070000 //设置FLASH 保存地址(必须为偶数,且其值要大于本代码所占用FLASH的大小+0X08000000)
/* 显示时间,index特殊处理 */
void show_index_time(u8 index, _calendar_obj calendar_temp, _calendar_obj alarm);
int main(void)
{
/* 按键返回值 */
u8 key = 0;
/* 修改指向下标 */
u8 index = 0;
/* 日历结构体 */
_calendar_obj calendar_temp;
_calendar_obj alarm;
// 修改模式标志
u8 mode = 0;
// 停止闹铃按键标志位
u8 flag = 0;
// 闹铃循环次数
u16 count = 0;
/* 延时函数初始化 */
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();
/* 初始化蜂鸣器端口 */
BEEP_Init();
/*
* 显示时间
* 设置字体为蓝色
*/
POINT_COLOR = BLUE;
LCD_ShowString(60, 130, 300, 16, 16, "N O W : : ");
LCD_ShowString(60, 162, 300, 16, 16, "ALARM : : ");
LCD_ShowString(20, 220, 200, 16, 16, "Press KEY1 or KEY_UP");
LCD_ShowString(20, 236, 200, 16, 16, "to STOP BEEP");
calendar_temp = calendar;
// 从指定地址开始读出指定长度的数据
// ReadAddr:起始地址
// pBuffer:数据指针
// NumToWrite:半字(16位)数
STMFLASH_Read(FLASH_SAVE_ADDR, (u16 *)&alarm.hour, 1);
STMFLASH_Read(FLASH_SAVE_ADDR + 0X2, (u16 *)&alarm.min, 1);
alarm.sec = 0;
while (1)
{
/* 根据index显示不同日历变量 */
if (0 == index)
show_index_time(index, calendar, alarm);
else
show_index_time(index, calendar_temp, alarm);
/*
* 键处理函数
* 返回按键值
* mode:0,不支持连续按;1,支持连续按;
* 0,没有任何按键按下
* 1,KEY0按下
* 2,KEY1按下
* 3,KEY3按下 WK_UP
*/
key = KEY_Scan(0);
/* KEY0 进入修改模式,依次顺序循环 */
if (1 == key)
{
index++;
index = index % 6;
/* 进入修改 */
if (1 == index)
{
calendar_temp = calendar;
mode = 1;
printf("Enter modify mode.\r\n");
}
/* 退出修改 */
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);
// 从指定地址开始写入指定长度的数据
// WriteAddr:起始地址(此地址必须为2的倍数!!)
// pBuffer:数据指针
// NumToWrite:半字(16位)数(就是要写入的16位数据的个数.)
STMFLASH_Write(FLASH_SAVE_ADDR, (u16 *)&alarm.hour, 1);
STMFLASH_Write(FLASH_SAVE_ADDR + 0X2, (u16 *)&alarm.min, 1);
mode = 0;
printf("modify finish! Enter normal mode.\r\n");
}
}
/* KEY1 选中值+1 */
else if (2 == key)
{
printf("KEY1 click!\r\n");
if (1 == index)
{
calendar_temp.hour++;
calendar_temp.hour = calendar_temp.hour > 23 ? 0 : calendar_temp.hour;
}
else if (2 == index)
{
calendar_temp.min++;
calendar_temp.min = calendar_temp.min > 59 ? 0 : calendar_temp.min;
}
else if (3 == index)
{
calendar_temp.sec++;
calendar_temp.sec = calendar_temp.sec > 59 ? 0 : calendar_temp.sec;
}
else if (4 == index)
{
alarm.hour++;
alarm.hour = alarm.hour > 23 ? 0 : alarm.hour;
}
else if (5 == index)
{
alarm.min++;
alarm.min = alarm.min > 59 ? 0 : alarm.min;
}
else if (0 == index)
{
// 按键标志位置1 停止蜂鸣器 计数归零
flag = 1;
BEEP = 0;
count = 0;
printf("flag = 1, BEEP = 0, count = 0\r\n");
}
}
/* KEY_UP 选中值-1 */
else if (3 == key)
{
printf("KEY_UP click!\r\n");
if (1 == index)
{
calendar_temp.hour = calendar_temp.hour == 0 ? 23 : calendar_temp.hour - 1;
}
else if (2 == index)
{
calendar_temp.min = calendar_temp.min == 0 ? 59 : calendar_temp.min - 1;
}
else if (3 == index)
{
calendar_temp.sec = calendar_temp.sec == 0 ? 59 : calendar_temp.sec - 1;
}
else if (4 == index)
{
alarm.hour = alarm.hour == 0 ? 23 : alarm.hour - 1;
}
else if (5 == index)
{
alarm.min = alarm.min == 0 ? 59 : alarm.min - 1;
}
else if (0 == index)
{
// 按键标志位置1 停止蜂鸣器 计数归零
flag = 1;
BEEP = 0;
count = 0;
printf("flag = 1, BEEP = 0, count = 0\r\n");
}
}
else if (0 == key)
{
// 普通模式下
if (0 == mode)
{
// 闹钟到点 && 蜂鸣器没叫 && 没有按下KEY1或KEY_UP键
if (calendar.hour == alarm.hour && calendar.min == alarm.min && BEEP == 0 && 0 == flag)
{
BEEP = 1;
printf("Start BEEP!\r\n");
}
// 闹钟没到点 && 按下了KEY1或KEY_UP键
else if ((calendar.hour != alarm.hour || calendar.min != alarm.min) && 1 == flag)
{
flag = 0;
}
}
}
// 闹铃循环次数计数
if (1 == BEEP)
{
POINT_COLOR = RED;
LCD_ShowString(20, 204, 200, 16, 16, "BEEP!!! (>__<) ");
POINT_COLOR = BLUE;
count++;
// printf("1 == BEEP, count++\r\n");
}
else
{
LCD_ShowString(20, 204, 200, 16, 16, " <(^ v ^)>");
}
// 闹铃循环次数达到峰值
if (5 * 6000 <= count)
{
// 按键标志位置1 停止蜂鸣器 计数归零
flag = 1;
BEEP = 0;
count = 0;
printf("5 * 6000 <= count, Stop BEEP, flag = 1, count = 0\r\n");
}
delay_ms(10);
}
}
/* 显示时间,index特殊处理 */
void show_index_time(u8 index, _calendar_obj calendar_temp, _calendar_obj alarm)
{
POINT_COLOR = BLUE;
if (1 == index)
POINT_COLOR = RED;
LCD_ShowNum(116, 130, calendar_temp.hour, 2, 16);
POINT_COLOR = BLUE;
if (2 == index)
POINT_COLOR = RED;
LCD_ShowNum(140, 130, calendar_temp.min, 2, 16);
POINT_COLOR = BLUE;
if (3 == index)
POINT_COLOR = RED;
LCD_ShowNum(164, 130, calendar_temp.sec, 2, 16);
POINT_COLOR = BLUE;
if (4 == index)
POINT_COLOR = RED;
LCD_ShowNum(116, 162, alarm.hour, 2, 16);
POINT_COLOR = BLUE;
if (5 == index)
POINT_COLOR = RED;
LCD_ShowNum(140, 162, alarm.min, 2, 16);
POINT_COLOR = BLUE;
LCD_ShowNum(164, 162, alarm.sec, 2, 16);
}
创建一个新的 Office 插件项目:在 Visual Studio 中,选择"文件" -> “新建项目”,然后在模板中选择"Office/SharePoint",选择适当的 Office 插件项目模板,如 Word 插件、Excel 插件或 PowerPoint 插件。设计用户界面:在解决方案资源管理器中,打开你的插件项目,并在其中打开相应的 Office 文件(如 Word 文件、Excel 文件或 PowerPoint 文件)。你可以在 Office 应用中测试插件的功能,并在开发过程中进行调试。
在应用场景方面,便携式IV功率测试仪广泛应用于光伏电站的日常运维、光伏组件生产过程中的质量控制以及光伏项目的前期评估等环节。在光伏电站运维中,定期对光伏组件进行IV测试,可以及时发现性能下降或损坏的组件,为电站的运维提供有力支持。首先,从工作原理来看,光伏电站便携式IV功率测试仪通过模拟太阳光照射光伏组件,并测量组件在不同电压下的电流输出,从而绘制出IV曲线。此外,测试仪还可以计算光伏组件的功率输出、转换效率等参数,为用户提供全面的性能评估。
文章浏览阅读3.6k次。os: ubuntu 16.04postgresql: 9.6.8ip 规划192.168.56.102 node2 postgresqlhelp create indexpostgres=# \h create indexCommand: CREATE INDEXDescription: define a new indexSyntax:CREATE [ UNIQUE ..._load_categories_hash postgres
文章浏览阅读4.8k次。使用face++,先获取key和secret下方是人脸识别,还添加了画出人脸轮廓的正方形下方是人脸识别,还添加了画出人脸轮廓的正方形 import requests#网络访问控件 from json import JSONDecoder#互联网数据交换标准格式 import cv2 as cv#图像处理控件 http_url =&amp;amp;quot;https://a..._face++人脸识别 html5
文章浏览阅读322次。很多时候要对秘要进行持久化加密,此时的加密采用md5。采用对称加密的时候就采用DES方法了import java.io.IOException;import java.security.MessageDigest;import java.security.SecureRandom;import javax.crypto.Cipher;import javax.crypto.SecretKey;im..._java desencrypt.encrypt(pass)
文章浏览阅读145次。题目链接:https://www.acwing.com/problem/content/description/222/给定整数N,求1<=x,y<=N且GCD(x,y)为素数的数对(x,y)有多少对。GCD(x,y)即求x,y的最大公约数。输入格式输入一个整数N输出格式输出一个整数,表示满足条件的数对数量。数据范围1≤N≤10^7输入样例:4..._线性筛预处理质数表, 并求出欧拉函数, 预处理前缀和即可 bzoj2818boj
文章浏览阅读1.2k次。fromhttps://towardsdatascience.com/finding-lane-lines-simple-pipeline-for-lane-detection-d02b62e7572bIdentifying lanes of the road is very common task that human driver performs. This is important ..._lanedetectionlite
文章浏览阅读4.1k次,点赞8次,收藏23次。通过一定的方法找出与给定关键字相同的数据元素的过程叫做查找。也就是根据给定的某个值,在查找表中确定一个关键字等于给定值的记录或数据元素。_读取表元是什么意思
文章浏览阅读8.3k次,点赞4次,收藏18次。我们在非撮合回测模式下,因为无法获知交易价格当时的真实盘口价差、挂单数量,常主观设定一个滑点均值,比如针对螺纹钢等合约,设置 1 跳,针对某些交易不活跃的品种,设置 2 跳。但是这种近乎拍脑袋的方法并不精确。我们今天尝试通过简单的辅助工具,实现尽可能接近准确的 tick 级别滑点设置,代码已写好,不用编程也可获得结果。_滑点设置多少合适
文章浏览阅读551次。尚硅谷大数据技术之 Azkaban—————————————————————————————更多 Java –大数据 –前端 –python 人工智能资料下载,可百度访问:尚硅谷官网尚硅谷大数据技术之 Azkaban(作者:尚硅谷大数据研发部)版本:V3.0一 概述1.1 什么是 AzkabanAzkaban 是由 Linkedin 公司推出的一个批量工作流任务调度器,主要用于在一个工作流内以一个特定的顺序运行一组工作和流程,它的配置是通过简单的 key:value 对的方式,通过配置中_azkaban要建立job之间的依赖关系需要使用
文章浏览阅读5k次,点赞2次,收藏9次。#! python3# encoding: utf-8import osimport chardetdef strJudgeCode(str1): return chardet.detect(str1)"""def readFile(path): with open(path,'r',encoding='utf-16 le') as f: filecontent ..._utf16le转换utf8
文章浏览阅读1.1k次。AppWidget 窗口小部件的开发思想和Demo 这篇文章讲一下android系统“窗口小部件”(也叫做,主屏幕部件)的开发过程。什么叫窗口小部件呢?是指在主屏幕上显示的独立视图(不过填充了数据)。这些视图的数据内容由后台进程顶起更新。要用到RemoteViews来显示部件,还要指派广播接收器更新这些RemoteViews. 既可以单独做个窗口小部件,也可在App中嵌入多个窗口小部_安卓小部件开发demo