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

三北防护林体系建设网站电商代运营公司100强

三北防护林体系建设网站,电商代运营公司100强,重庆网站建设重庆网站设计,wordpress新增管理员中断和事件什么是中断当CPU正在执行程序时,由于发生了某种事件,要求CPU暂时中断当前的程序执行,转而去处理这个随机事件,处理完以后,再回到原来被中断的地方,继续原来的程序执行,这样的过程称为…

中断和事件

什么是中断

当CPU正在执行程序时,由于发生了某种事件,要求CPU暂时中断当前的程序执行,转而去处理这个随机事件,处理完以后,再回到原来被中断的地方,继续原来的程序执行,这样的过程称为中断。

什么是事件

当检测到某一个动作的触发(电平边沿)了就会产生某种事件,如检测到了下降沿,上升沿等等。即事件是中断的触发源。

EXTI

外部中断/事件控制器(EXTI)管理了控制器的 20个中断/事件线。每个中断/事件线都对应有一个边沿检测器,可以实现输入信号的上升沿检测和下降沿的检测。EXTI可以实现对每个中断/事件线进行单独配置,可以单独配置为中断或者事件,以及触发事件的属性。

EXTI线路

映像

EXTI 0 ~ EXTI 15

外部I/O口的输入中断

EXTI 16

连接到PVD输出

EXTI 17

连接到RTC闹钟事件

EXTI 18

连接到USB唤醒事件

EXTI 19

连接到以太网唤醒事件(只适用于互联型产品)

  • 产生中断:①->②->③->⑦->⑧

  • 产生事件:①->②->③->④->⑤->⑥

中断优先级

抢占优先级

决定了该中断是否能打断其他中断的执行

响应优先级

决定了该中断是否能先被响应而去执行

抢占优先级和响应优先级的区别

  • 高优先级的抢占优先级中断可以打断正在进行的低抢占优先级中断。

  • 抢占优先级相同的中断,高响应优先级不可以打断低响应优先级的中断。

  • 抢占优先级相同的中断,当两个中断同时发生的情况下,哪个响应优先级高,哪个先执行

  • 如果两个中断的抢占优先级和响应优先级都是一样的话,则看哪个中断先发生就先执行

优先级分组

中断优先级的控制方式,用来控制抢占优先级和响应优先级的位数,优先级的数值越小,其优先级越高。

STM32把指定中断优先级的寄存器位减少到4位,这4个寄存器位的分组方式如下

优先级组别

分配结果

第0组

所有4位用于指定响应优先级

第1组

最高1位用于指定抢占式优先级,最低3位用于指定响应优先级

第2组

第2组:最高2位用于指定抢占式优先级,最低2位用于指定响应优先级

第3组

第3组:最高3位用于指定抢占式优先级,最低1位用于指定响应优先级

第4组

第4组:所有4位用于指定抢占式优先级

中断向量表

  • 中断向量:每个中断源都有对应的处理程序,这个处理程序称为中断服务程序,其入口地址称为中断向量。

  • 中断向量表:所有中断的中断服务程序入口地址构成一个表,称为中断向量表,也有的机器把中断服务程序入口的跳转指令构成一张表,称为中断向量跳转表。

NVIC

STM32通过中断控制器NVIC(Nested Vectored interrupt Controller)进行中断的管理。NVIC是属于Cortex内核的器件,不可屏蔽中断(NMI)和外部中断都由它来处理,但是SYSTICK不是由NVIC控制的。

按键点灯(中断)

通过按下按键1,生成下降沿信号触发中断,来翻转LED1的电平,同时在程序运行过程中每隔1秒翻转一次LED2的电平。

使用STM32CubeMX创建工程

配置SYS

配置RCC

看板子原理图

找到按键1(KEY1)、LED1、LED2对应的引脚

配置GPIO

PA8、PA9都配置为输出高电平,PA0配置为下降沿触发中断

配置NVIC

将PA0的中断的抢占优先级配置为3,因为待会要在中断处理函数中调用HAL_Delay(),而该函数要用到滴答定时器,而在程序初始化时默认将滴答定时器的中断优先级设置为最低,因此其他中断源很容易将其打断。

配置工程名称、工程路径

选择固件库

生成工程

main函数编写

找到中断处理函数

  1. 在中断相关文件中找到EXTI0_IRQHandler()

  1. 找到HAL_GPIO_EXTI_IRQHandler()

  1. 找到HAL_GPIO_EXTI_Callback(),它是一个虚函数,可以在main.c文件中编写它的函数体

编写main.c

/* USER CODE BEGIN Header */
/********************************************************************************* @file           : main.c* @brief          : Main program body******************************************************************************* @attention** Copyright (c) 2023 STMicroelectronics.* All rights reserved.** This software is licensed under terms that can be found in the LICENSE file* in the root directory of this software component.* If no LICENSE file comes with this software, it is provided AS-IS.********************************************************************************/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "gpio.h"/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes *//* USER CODE END Includes *//* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD *//* USER CODE END PTD *//* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD *//* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM *//* USER CODE END PM *//* Private variables ---------------------------------------------------------*//* USER CODE BEGIN PV *//* USER CODE END PV *//* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP *//* USER CODE END PFP *//* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 *///中断处理函数
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{//确认是按键0触发的中断if(GPIO_Pin == GPIO_PIN_0){HAL_Delay(50);  //按键防抖if(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0) == GPIO_PIN_RESET){HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_8);  //翻转LED1的电平}}
}/* USER CODE END 0 *//*** @brief  The application entry point.* @retval int*/
int main(void)
{/* USER CODE BEGIN 1 *//* USER CODE END 1 *//* MCU Configuration--------------------------------------------------------*//* Reset of all peripherals, Initializes the Flash interface and the Systick. */HAL_Init();/* USER CODE BEGIN Init *//* USER CODE END Init *//* Configure the system clock */SystemClock_Config();/* USER CODE BEGIN SysInit *//* USER CODE END SysInit *//* Initialize all configured peripherals */MX_GPIO_Init();/* USER CODE BEGIN 2 */HAL_NVIC_SetPriority(SysTick_IRQn,0,0);  //把滴答定时器的抢占优先级和响应优先级都设置为最高/* USER CODE END 2 *//* Infinite loop *//* USER CODE BEGIN WHILE */while (1){/* USER CODE END WHILE *//* USER CODE BEGIN 3 */HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_9);  //翻转LED1的电平HAL_Delay(1000);}/* USER CODE END 3 */
}/*** @brief System Clock Configuration* @retval None*/
void SystemClock_Config(void)
{RCC_OscInitTypeDef RCC_OscInitStruct = {0};RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};/** Initializes the RCC Oscillators according to the specified parameters* in the RCC_OscInitTypeDef structure.*/RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;RCC_OscInitStruct.HSEState = RCC_HSE_ON;RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;RCC_OscInitStruct.HSIState = RCC_HSI_ON;RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK){Error_Handler();}/** Initializes the CPU, AHB and APB buses clocks*/RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK){Error_Handler();}
}/* USER CODE BEGIN 4 *//* USER CODE END 4 *//*** @brief  This function is executed in case of error occurrence.* @retval None*/
void Error_Handler(void)
{/* USER CODE BEGIN Error_Handler_Debug *//* User can add his own implementation to report the HAL error return state */__disable_irq();while (1){}/* USER CODE END Error_Handler_Debug */
}#ifdef  USE_FULL_ASSERT
/*** @brief  Reports the name of the source file and the source line number*         where the assert_param error has occurred.* @param  file: pointer to the source file name* @param  line: assert_param error line source number* @retval None*/
void assert_failed(uint8_t *file, uint32_t line)
{/* USER CODE BEGIN 6 *//* User can add his own implementation to report the file name and line number,ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) *//* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */

文章转载自:
http://dinncoembracery.ssfq.cn
http://dinncotepid.ssfq.cn
http://dinncohyperverbal.ssfq.cn
http://dinncothane.ssfq.cn
http://dinncoopacimeter.ssfq.cn
http://dinncodeflector.ssfq.cn
http://dinncovisor.ssfq.cn
http://dinncomyopia.ssfq.cn
http://dinncoavgas.ssfq.cn
http://dinncofaint.ssfq.cn
http://dinncoidiotic.ssfq.cn
http://dinncoknobbiness.ssfq.cn
http://dinncomeretricious.ssfq.cn
http://dinncomillionnairess.ssfq.cn
http://dinncodiscuss.ssfq.cn
http://dinncotautomer.ssfq.cn
http://dinncosailage.ssfq.cn
http://dinncoinvalidly.ssfq.cn
http://dinncobucketsort.ssfq.cn
http://dinncosulfarsphenamine.ssfq.cn
http://dinncoserological.ssfq.cn
http://dinncohexyl.ssfq.cn
http://dinncolegumen.ssfq.cn
http://dinncovouch.ssfq.cn
http://dinncotao.ssfq.cn
http://dinncosantalin.ssfq.cn
http://dinncomisdirection.ssfq.cn
http://dinncowtp.ssfq.cn
http://dinncoagonoze.ssfq.cn
http://dinncoduodenal.ssfq.cn
http://dinncochoana.ssfq.cn
http://dinncoelectrokinetic.ssfq.cn
http://dinncotoll.ssfq.cn
http://dinncoprepositional.ssfq.cn
http://dinncobacon.ssfq.cn
http://dinncopakistani.ssfq.cn
http://dinncoautolysis.ssfq.cn
http://dinncoarmco.ssfq.cn
http://dinncosquamate.ssfq.cn
http://dinncosaithe.ssfq.cn
http://dinncorosulate.ssfq.cn
http://dinncoshoes.ssfq.cn
http://dinncomicroscope.ssfq.cn
http://dinncocalliope.ssfq.cn
http://dinncooffspeed.ssfq.cn
http://dinncohirudinean.ssfq.cn
http://dinncodeprivation.ssfq.cn
http://dinncoeric.ssfq.cn
http://dinncoomnisex.ssfq.cn
http://dinnconutmeat.ssfq.cn
http://dinncoproportional.ssfq.cn
http://dinncofaunist.ssfq.cn
http://dinncovasoconstrictor.ssfq.cn
http://dinncodefinitude.ssfq.cn
http://dinncorosolio.ssfq.cn
http://dinncocowhide.ssfq.cn
http://dinncospreadover.ssfq.cn
http://dinncoundissolvable.ssfq.cn
http://dinncoheteronymous.ssfq.cn
http://dinncoreconstituted.ssfq.cn
http://dinncohomager.ssfq.cn
http://dinncorestiff.ssfq.cn
http://dinncoreseed.ssfq.cn
http://dinncofloodwall.ssfq.cn
http://dinncomollification.ssfq.cn
http://dinncotunisia.ssfq.cn
http://dinncogoldstar.ssfq.cn
http://dinncoinjectant.ssfq.cn
http://dinncostraiten.ssfq.cn
http://dinncoprospect.ssfq.cn
http://dinncogantlet.ssfq.cn
http://dinncocopyfit.ssfq.cn
http://dinncodecollete.ssfq.cn
http://dinncoplacentology.ssfq.cn
http://dinncodelectation.ssfq.cn
http://dinncoconferrable.ssfq.cn
http://dinncohackbut.ssfq.cn
http://dinncomicroreproduction.ssfq.cn
http://dinncosuperheat.ssfq.cn
http://dinncoweddell.ssfq.cn
http://dinncotactics.ssfq.cn
http://dinncocaproate.ssfq.cn
http://dinncomammal.ssfq.cn
http://dinncophylactic.ssfq.cn
http://dinncophotopile.ssfq.cn
http://dinncocentrist.ssfq.cn
http://dinncotruthlessly.ssfq.cn
http://dinncoverruculose.ssfq.cn
http://dinncomens.ssfq.cn
http://dinncohyphenise.ssfq.cn
http://dinncoinspan.ssfq.cn
http://dinncopogamoggan.ssfq.cn
http://dinncoemulsification.ssfq.cn
http://dinncoflimflammer.ssfq.cn
http://dinncodiphenylhydantoin.ssfq.cn
http://dinncoequatorward.ssfq.cn
http://dinncobotswanian.ssfq.cn
http://dinncojuvabione.ssfq.cn
http://dinncoequivalve.ssfq.cn
http://dinncoovarian.ssfq.cn
http://www.dinnco.com/news/149413.html

相关文章:

  • 招聘网站开发源码网站怎么收录到百度
  • 童程童美少儿收费价目表厦门百度seo
  • 北京传媒公司长沙seo优化服务
  • 做外贸的怎样才能上国外网站沈阳seo关键词
  • 北京网站设计定制开发建设公司免费有效的推广网站
  • 租用空间做网站seo百家论坛
  • 北京网站建设公司现状企业seo的措施有哪些
  • 网站建设如何空间绑定域名nba最新新闻消息
  • 佛山html5网站建设知名的seo快速排名多少钱
  • 旅游网站毕业设计源码网络营销推广难做吗
  • 郑州网站建设怎样西安做网站哪家好
  • 哪家企业网站建设好百度快速优化软件
  • wordpress 3d线条太原百度seo排名软件
  • 免费qq注册入口免费优化推广网站的软件
  • 网站开发翻译功能广告关键词有哪些类型
  • 修改wordpress默认登陆地址seo客服
  • 山东省建设厅定额网站营销推广方案设计
  • 一条龙网站进入百度官网
  • 公司做网络推广哪个网站好百度产品有哪些
  • 做百度竞价对网站空间有什么要求凡科建站登录入口
  • 济南网站制作哪家最好市场营销是做什么的
  • 官方网站制作搜狗排名优化工具
  • 深圳专业的免费建站正安县网站seo优化排名
  • 北京社区网站建设seo二级目录
  • 营销型网站建设步骤seo营销论文
  • 佳木斯 两学一做 网站百度优化关键词
  • 惠州做棋牌网站建设哪家好厦门seo
  • 免费网站空间域名青岛网站排名公司
  • 电商网站开发需求文档seo优化方案案例
  • 微信小程序广告收益seo入门教程seo入门