当前位置: 首页 > news >正文

新人做网站盈利广州最新发布最新

新人做网站盈利,广州最新发布最新,soho做网站,羽毛球赛事2022直播一、题目分析 考察内容: led按键(短按)PWM输出(PA1)串口接收lcd显示 根据PWM输出占空比调节,高频与低频切换 串口接收(指令解析)【中断接收】 2个显示界面 led灯闪烁定时器 二…

 一、题目分析

考察内容:

  • led
  • 按键(短按)
  • PWM输出(PA1)
  • 串口接收
  • lcd显示

根据PWM输出占空比调节,高频与低频切换

串口接收(指令解析)【中断接收】

2个显示界面

led灯闪烁定时器

二、Usr.c

/* Includes ------------------------------------------------------------------*/
#include "usr.h"
#include "usart.h"
/* values --------------------------------------------------------------------*/
struct keys key[4]={0,0,0,0};
uint8_t menu = 0;
uint8_t password_valid = 0;//密码有效信号
uint8_t password_err_3 = 0;//密码3次及以上输入错误信号
uint8_t password_err_time = 0;//密码3次及以上输入错误次数
uint8_t B1 = '@';
uint8_t B2 = '@';
uint8_t B3 = '@';
uint16_t F = 1000;
uint16_t D = 50;
uint16_t password = 123;//密码
/* define --------------------------------------------------------------------*/
#define MENU_PSD 0
#define MENU_STA 1/*----------------------------------------------------------------------------*/
void led_set(uint8_t led_dis)
{HAL_GPIO_WritePin(GPIOC,GPIO_PIN_All,GPIO_PIN_SET);//关闭所有ledHAL_GPIO_WritePin(GPIOC,led_dis<<8,GPIO_PIN_RESET);HAL_GPIO_WritePin(GPIOD,GPIO_PIN_2,GPIO_PIN_SET);HAL_GPIO_WritePin(GPIOD,GPIO_PIN_2,GPIO_PIN_RESET);
}
void led_2_toggle(void){HAL_GPIO_WritePin(GPIOC,GPIO_PIN_8,GPIO_PIN_SET);HAL_GPIO_WritePin(GPIOC,GPIO_PIN_10,GPIO_PIN_SET);HAL_GPIO_WritePin(GPIOC,GPIO_PIN_11,GPIO_PIN_SET);HAL_GPIO_WritePin(GPIOC,GPIO_PIN_12,GPIO_PIN_SET);HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,GPIO_PIN_SET);HAL_GPIO_WritePin(GPIOC,GPIO_PIN_14,GPIO_PIN_SET);HAL_GPIO_WritePin(GPIOC,GPIO_PIN_15,GPIO_PIN_SET);HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_9);HAL_GPIO_WritePin(GPIOD,GPIO_PIN_2,GPIO_PIN_SET);HAL_GPIO_WritePin(GPIOD,GPIO_PIN_2,GPIO_PIN_RESET);
}//key_control
void key_control(void)
{if(key[0].single_flag == 1){key[0].single_flag = 0;//仅在PSD有效if(menu == MENU_PSD){if(B1 == '@'){B1 = '0';}else{B1++;if(B1>'9'){B1 = '0';}}}}else if(key[1].single_flag == 1){key[1].single_flag = 0;if(menu == MENU_PSD){if(B2 == '@'){B2 = '0';}else{B2++;if(B2>'9'){B2 = '0';}}}}else if(key[2].single_flag == 1){key[2].single_flag = 0;if(menu == MENU_PSD){if(B3 == '@'){B3 = '0';}else{B3++;if(B3>'9'){B3 = '0';}}}  }else if(key[3].single_flag == 1){       //密码输入完成确认key[3].single_flag = 0;//此处要写密码判断if((B1-'0')*100+(B2-'0')*10+(B3-'0') == password){password_valid = 1;}else{password_err_time ++;}if(password_valid == 1){menu = MENU_STA;password_err_3 = 0;password_err_time = 0;//输入成功将err次数清0}else{B1 ='@';B2 ='@';B3 ='@';if(password_err_time >= 3){password_err_3 = 1;}}}else{key[0].long_flag = 0;key[1].long_flag = 0;key[2].long_flag = 0;key[3].long_flag = 0;}
}
void dispaly_init(void){LCD_Clear(Black);LCD_SetBackColor(Black);LCD_SetTextColor(White);
}
void menu_display(void)
{char text[30]={NULL};if(menu == MENU_PSD){sprintf(text,"       PSD           ");LCD_DisplayStringLine(Line1,(u8*)text);sprintf(text,"    B1:%c     ",B1);LCD_DisplayStringLine(Line3,(u8*)text);sprintf(text,"    B2:%c     ",B2);LCD_DisplayStringLine(Line4,(u8*)text);sprintf(text,"    B3:%c     ",B3);LCD_DisplayStringLine(Line5,(u8*)text);}else{fre_2hz_duty_10_set();sprintf(text,"       STA           ");LCD_DisplayStringLine(Line1,(u8*)text);sprintf(text,"    F:%d",F);LCD_DisplayStringLine(Line3,(u8*)text);sprintf(text,"    D:%d",D);LCD_DisplayStringLine(Line4,(u8*)text);LCD_ClearLine(Line5);}
}//2hz
void fre_2hz_duty_10_set(void)
{F= 2000;D =10;__HAL_TIM_SetCompare(&htim2,TIM_CHANNEL_2,100-1);//占空比百分之10__HAL_TIM_SET_PRESCALER(&htim2,40-1);//2hz
}
//1hz 50%
void fre_1hz_duty_50_set(void){__HAL_TIM_SetCompare(&htim2,TIM_CHANNEL_2,500-1);//占空比百分之50__HAL_TIM_SET_PRESCALER(&htim2,80-1);//1hzF= 2000;D = 50;
}//定时器中断服务函数
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{if(htim->Instance == TIM6){key[0].key_sta = HAL_GPIO_ReadPin(B1_Port,B1_Pin);key[1].key_sta = HAL_GPIO_ReadPin(B2_Port,B2_Pin);key[2].key_sta = HAL_GPIO_ReadPin(B3_Port,B3_Pin);key[3].key_sta = HAL_GPIO_ReadPin(B4_Port,B4_Pin);for(uint8_t i =0;i<4;i++){switch(key[i].judge_sta){case 0:{if(key[i].key_sta == 0){key[i].judge_sta = 1;key[i].key_time = 0;}else {key[i].judge_sta = 0;}}break;case 1:{if(key[i].key_sta == 0){key[i].judge_sta = 2;}else{key[i].judge_sta = 0;}}break;case 2:{if(key[i].key_sta == 1){if(key[i].key_time< Short_time){key[i].single_flag = 1;key[i].judge_sta = 0;}}else{key[i].key_time++;if(key[i].key_time > Long_time){key[i].long_flag = 1;key[i].judge_sta = 0;}}}break;}}}if(htim->Instance == TIM7){static uint16_t time = 0;if(password_valid == 1){password_err_3 = 0;led_set(0x01);F= 2000;fre_2hz_duty_10_set();if(time>= 50-1){password_valid = 0;led_set(0x00);time = 0;menu = MENU_PSD;B1 = '@';B2 = '@';B3 = '@';}else{time ++;}}else if(password_err_3 == 1){static uint8_t cnt = 0;cnt ++;cnt %= 2;//led2翻转if(cnt == 0){led_set(0x02);}else{led_set(0x00);}//5s后接触报警if(time>= 50-1){password_err_3 = 0;led_set(0x00);time = 0;  //5s计时清零cnt = 0;}else{time ++;   //计时++}F= 1000;fre_1hz_duty_50_set();//方波1hz}else{time = 0;fre_1hz_duty_50_set();//方波1hz}                     }}//串口接收完成中断回调服务函数
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{if(huart->Instance == USART1){led_set(0xaa);if(((recevie[0]-'0')*100+(recevie[1]-'0')*10+(recevie[2]-'0') == password)&&(recevie[3]) == '-'){password = (recevie[4]-'0')*100+(recevie[5]-'0')*10+(recevie[6]-'0');}HAL_UART_Receive_IT(&huart1,recevie,7);}
}

三、Usr.h

#ifndef __USR_H__
#define __USR_H__#ifdef __cplusplus
extern "C" {
#endif/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "lcd.h"
#include "stdio.h"
#include "tim.h"
/* extern --------------------------------------------------------------------*/
extern uint8_t recevie[7];
//key    
struct keys{uint8_t judge_sta;uint8_t key_sta;uint8_t single_flag;uint8_t long_flag;uint8_t key_time;
};
/*key define-------------------------------------------------------------------*/   
#define B1_Port GPIOB
#define B2_Port GPIOB
#define B3_Port GPIOB  
#define B4_Port GPIOA#define B1_Pin  GPIO_PIN_0
#define B2_Pin  GPIO_PIN_1
#define B3_Pin  GPIO_PIN_2   
#define B4_Pin  GPIO_PIN_0#define Long_time  200   //2s
#define Short_time 50    //0.5s//led
void led_set(uint8_t led_dis);void led_2_toggle(void);
//key_control
void key_control(void);
void dispaly_init(void);
void menu_display(void);
void fre_2hz_duty_10_set(void);#ifdef __cplusplus
}
#endif
#endif 

四、串口中断接收

本题目要求接收7个ASCII码字符

定义uint8_t 类型接收数组

uint8_t recevie[7];

在while(1)前开启串口接收中断函数,接收7个字符后进入中断服务函数

HAL_UART_Receive_IT(&huart1,recevie,7);

 根据中断类型,调用中断回调函数

下面展示中断服务函数

//串口接收完成中断回调服务函数
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{if(huart->Instance == USART1){led_set(0xaa);if(((recevie[0]-'0')*100+(recevie[1]-'0')*10+(recevie[2]-'0') == password)&&(recevie[3]) == '-'){password = (recevie[4]-'0')*100+(recevie[5]-'0')*10+(recevie[6]-'0');}HAL_UART_Receive_IT(&huart1,recevie,7);}
}

五、LED灯闪烁问题

计时应该是正确的5s

    if(htim->Instance == TIM7){static uint16_t time = 0;if(password_valid == 1){password_err_3 = 0;led_set(0x01);F= 2000;fre_2hz_duty_10_set();if(time>= 50-1){password_valid = 0;led_set(0x00);time = 0;menu = MENU_PSD;B1 = '@';B2 = '@';B3 = '@';}else{time ++;}}else if(password_err_3 == 1){static uint8_t cnt = 0;cnt ++;cnt %= 2;//led2翻转if(cnt == 0){led_set(0x02);}else{led_set(0x00);}//5s后接触报警if(time>= 50-1){password_err_3 = 0;led_set(0x00);time = 0;  //5s计时清零cnt = 0;}else{time ++;   //计时++}F= 1000;fre_1hz_duty_50_set();//方波1hz}else{time = 0;fre_1hz_duty_50_set();//方波1hz}                     }

六、 总结

本次只写一个usr.c usr.h,发现确实方便了许多!!相较于14届难度较小

比照LCD的cubemx配置引脚的时候,记得配置PD2(led锁存器引脚)

复制其他.h时后记得更改预编译

#ifndef __USR_H__        //记得更改
#define __USR_H__#ifdef __cplusplus
extern "C" {
#endif/* Includes ------------------------------------------------------------------*/
#include "main.h"#ifdef __cplusplus
}
#endif
#endif 

如果没有改为__USR_H__,跳转函数跳转不进去usr.c文件,会显示C99_warning 


文章转载自:
http://gail.stph.cn
http://fakir.stph.cn
http://ectropion.stph.cn
http://thailand.stph.cn
http://subservient.stph.cn
http://adenase.stph.cn
http://frowardly.stph.cn
http://adidas.stph.cn
http://foraminifera.stph.cn
http://disposable.stph.cn
http://serjeancy.stph.cn
http://chechako.stph.cn
http://landgrave.stph.cn
http://colorblind.stph.cn
http://roorbach.stph.cn
http://oomph.stph.cn
http://tailgunning.stph.cn
http://nonofficial.stph.cn
http://quadrumana.stph.cn
http://divertive.stph.cn
http://semilustrous.stph.cn
http://neuropsychiatry.stph.cn
http://inadequacy.stph.cn
http://cokery.stph.cn
http://pyelogram.stph.cn
http://correctional.stph.cn
http://battlement.stph.cn
http://sampler.stph.cn
http://checkrow.stph.cn
http://volumeless.stph.cn
http://rembrandtesque.stph.cn
http://bellhanger.stph.cn
http://turntable.stph.cn
http://trothplight.stph.cn
http://maladministration.stph.cn
http://lithiasis.stph.cn
http://xix.stph.cn
http://consular.stph.cn
http://topazolite.stph.cn
http://disseisee.stph.cn
http://mothproof.stph.cn
http://staffman.stph.cn
http://ill.stph.cn
http://retract.stph.cn
http://bloodguilty.stph.cn
http://pleasure.stph.cn
http://satiety.stph.cn
http://pd.stph.cn
http://ots.stph.cn
http://fellmonger.stph.cn
http://chill.stph.cn
http://prussianise.stph.cn
http://promotional.stph.cn
http://mainstay.stph.cn
http://umohoite.stph.cn
http://verkhoyansk.stph.cn
http://globulicidal.stph.cn
http://vaccinator.stph.cn
http://laevogyrate.stph.cn
http://sensuality.stph.cn
http://idiocratically.stph.cn
http://gooey.stph.cn
http://licence.stph.cn
http://smudginess.stph.cn
http://daily.stph.cn
http://interlinkage.stph.cn
http://narcotism.stph.cn
http://egotistic.stph.cn
http://denervate.stph.cn
http://stave.stph.cn
http://mizrachi.stph.cn
http://spiroscope.stph.cn
http://scrambling.stph.cn
http://ragout.stph.cn
http://saturdays.stph.cn
http://videocast.stph.cn
http://morphophonics.stph.cn
http://sozzled.stph.cn
http://fetishism.stph.cn
http://aerotherapeutics.stph.cn
http://scherzando.stph.cn
http://abend.stph.cn
http://deoxyribonuclease.stph.cn
http://perpetuator.stph.cn
http://dpi.stph.cn
http://morganite.stph.cn
http://proselytise.stph.cn
http://dollarwise.stph.cn
http://fee.stph.cn
http://accompanying.stph.cn
http://proliferate.stph.cn
http://khanka.stph.cn
http://sabot.stph.cn
http://vertebratus.stph.cn
http://cleveite.stph.cn
http://metarhodopsin.stph.cn
http://ericeticolous.stph.cn
http://argil.stph.cn
http://magi.stph.cn
http://composed.stph.cn
http://www.15wanjia.com/news/96657.html

相关文章:

  • 奉节做网站seo快速排名软件品牌
  • 一个服务器可以做两个网站网页模板代码
  • 做房产网站不备案可以吗宁波seo网络推广渠道介绍
  • wordpress微信登陆插件下载有必要买优化大师会员吗
  • 来广营做网站公司百度搜索引擎下载
  • 如何在阿里云自主建网站自助快速建站
  • 七星网络网站百度移动权重
  • 网站开发的企业南昌seo搜索排名
  • 网络营销的四种模式seo上首页排名
  • 格豪网络建站关键词挖掘工具
  • 网站做系统怎样无货源开网店
  • 邯郸网站设计哪家专业快速将网站seo
  • 哪个购物平台质量好价格合适浙江seo外包
  • 网站开发技术服务费正规营销培训
  • 山西住房和城乡建设委员会网站论坛排名
  • 卡密提取网站怎么做神马移动排名优化
  • 阿里巴巴国际贸易网站官网网络营销知识
  • 做网站需要每年都交钱吗网络营销的作用和意义
  • 发布网站需要备案谷歌搜索引擎下载
  • 自建企业网站模板下载福州百度首页优化
  • 长春市做网站的公司网络营销乐云seo
  • 政府门户网站制度建设情况哈尔滨最新今日头条新闻
  • 宝宝身上出现很多小红疹怎么办seo文章范文
  • 做毛绒玩具在什么网站上找客户网络营销费用预算
  • 私人定制哪个网站做的比较好seo推广教程seo推广技巧
  • 做网站如何推销郑州网站运营
  • 软件设计师培训机构沈阳seo关键词
  • 浙江建设干部学校网站首页百度云网盘资源搜索引擎
  • 晋中网站设计产品推广方案怎么写
  • 国内重大新闻10条网络seo啥意思