按键中断总结
来源:互联网 发布:三星s7解网络锁工具 编辑:程序博客网 时间:2024/05/29 19:25
一、RCC初始化
- /****************************************************************************
- * Function Name : RCC_Configuration
- * Description : Sets System clock frequency to 72MHz and configure HCLK, PCLK2
- * and PCLK1 prescalers.
- * Input : None
- * Output : None
- * Return : None
- ****************************************************************************/
- void RCC_Configuration(void)
- {
- /* Deinitialize the RCC registers */
- RCC_DeInit();
-
- /* Enable the HSE */
- RCC_HSEConfig(RCC_HSE_ON);
-
- /* Wait till HSE is ready and if Time out is reached exit */
- HSEStartUpStatus = RCC_WaitForHSEStartUp();
- if(HSEStartUpStatus == SUCCESS)
- {
- /* Add here PLL ans system clock config */
-
- /* Enable The Prefetch Buffer */
- FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
-
- /* Configure Tthe Latency cycle: Set 0 Latency cycles */
- FLASH_SetLatency(FLASH_Latency_2);
-
- /* Configure HCLK such as HCLK = SYSCLK */
- RCC_HCLKConfig(RCC_SYSCLK_Div1);
-
- /* PCLK2 = HCLK */
- RCC_PCLK2Config(RCC_HCLK_Div1);
-
- /* PCLK1 = HCLK/2 */
- RCC_PCLK1Config(RCC_HCLK_Div2);
-
- /* Select HSE as system clock source*/
- RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE);
-
- /* PLLCLK = 8MHz * 9 = 72MHz */
- RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
-
- /* ADCCLK = PCLK/4 */
- RCC_ADCCLKConfig(RCC_PCLK2_Div4);
-
- /* Enable PLL */
- RCC_PLLCmd(ENABLE);
-
- /* Wait till PLL is ready */
- while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
-
- /* Select PLL as system clock source */
- RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); /* Wait till HSE is used as system clock source */
- while(RCC_GetSYSCLKSource() != 0x08)
- {
-
- }
- }
- else
- {
- /* If HSE fails to start-up. */
- while(1)
- {
- }
- }
- }
二、GPIO初始化
- /****************************************************************************
- * Function Name : GPIO_Configuration
- * Description :
- * Input : None
- * Output : None
- * Return : None
- ****************************************************************************/
- void GPIO_Configuration(void)
- {
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- }
三、NVIC初始化
- /****************************************************************************
- * Function Name : NVIC_Configuration
- * Description : Configures Vector Table base location.
- * Input : None
- * Output : None
- * Return : None
- ****************************************************************************/
- void NVIC_Configuration(void)
- {
- NVIC_InitTypeDef NVIC_InitStructure;
- #ifdef VET_TAB_RAM
- /* Set the Vector Table base location at 0x2000 0000 */
- NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
- #else
- /* Set the Vector Table base location at 0x8000 0000 */
- NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
- #endif
-
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
-
- NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- }
四、EXTI初始化
- /****************************************************************************
- * Function Name : EXTI_PE6_Config
- * Description :
- * Input : None
- * Output : None
- * Return : None
- ****************************************************************************/
- void EXTI_PE6_Config(void)
- {
- GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource6);
-
- EXTI_InitStructure.EXTI_Line = EXTI_Line6;
- EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
- EXTI_InitStructure.EXTI_LineCmd = ENABLE;
- EXTI_Init(&EXTI_InitStructure);
-
- EXTI_GenerateSWInterrupt(EXTI_Line6);
- }
EXTI_GenerateSWInterrupt是触发一次软件中断。
同时需要编写中断函数在stm32f10x_it.c中:
- /*******************************************************************************
- * Function Name : EXTI9_5_IRQHandler
- * Description : This function handles External lines 9 to 5 interrupt request.
- * Input : None
- * Output : None
- * Return : None
- *******************************************************************************/
- void EXTI9_5_IRQHandler(void)
- {
- if(EXTI_GetITStatus(EXTI_Line6) != RESET)
- {
- GPIO_WriteBit(GPIOB, GPIO_Pin_8, (BitAction)(1-GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_8)));
-
- EXTI_ClearITPendingBit(EXTI_Line6);
- }
- }
五、main函数
- /****************************************************************************
- * Function Name : main
- * Description : Main program.
- * Input : None
- * Output : None
- * Return : None
- ****************************************************************************/
- int main(void)
- {
- RCC_Configuration();
-
- NVIC_Configuration();
-
- GPIO_Configuration();
-
- EXTI_PE6_Config();
-
- while(1)
- {
- }
- }
0
上一篇:RCC初始化学习
下一篇:STM32串口USART通信总结
相关热门文章
- SHTML是什么_SSI有什么用...
- 查看linux中某个端口(port)...
- 卡尔曼滤波的原理说明...
- shell中字符串操作
- 关于java中的“错误:找不到或...
给主人留下些什么吧!~~
评论热议
阅读全文
0 0
- s3c2440中断总结+按键中断
- 按键中断总结
- 按键中断
- 按键中断
- 按键 中断
- 按键中断
- 按键中断
- 中断-----按键中断驱动程序
- linux按键驱动模块(中断方式) 程序和调试总结
- STM32按键扫描/按键中断/外部中断
- CC2530 按键中断--中断向量
- NIOS按键中断程序
- 2440 按键中断
- 外部中断按键驱动
- LINUX 按键中断
- 按键中断 定时器
- 按键INT0 INT1中断
- fl2440按键中断驱动
- 电源控制和备份区域
- 复位和时钟控制(RCC)
- PCB一些设置记录
- RCC初始化学习
- 通过Ajax方式上传文件
- 按键中断总结
- STM32串口USART通信总结
- codeforces 839B Game of the Rows(思路题)
- DMA实验总结
- C/C++时间函数
- I2C_24c02实验
- 开始新的征程~~~~从第一个python 的机器学习实验开始~~~~~SVM实验
- sysTick系统定时器
- MOSFET学习
原创粉丝点击
热门IT博客
热门问题
老师的惩罚
人脸识别
我在镇武司摸鱼那些年
重生之率土为王
我在大康的咸鱼生活
盘龙之生命进化
天生仙种
凡人之先天五行
春回大明朝
姑娘不必设防,我是瞎子
应届毕业生找工作
双峰招聘
阜康招聘
崇州招聘网
找i工作
小时工招聘
广州招聘网
微山招聘
51彩虹
招聘智联网
上海宝山招聘
养殖招聘
58招聘网
无忧招聘
护士招聘网
林甸招聘
附近找工作保安
招聘网站有哪些
丰城招聘
台儿庄招聘
剧组招聘
彭州招聘
信息招聘网
仁怀招聘
三台在线招聘
智联卓聘
51网站
峡山招聘网
58同安招聘网
临平招聘
51空间登录
www,51
唐海招聘
化州招聘
叶县招聘
义乌招聘
义务招聘
开原招聘
枞阳招聘网
泸县招聘
云阳招聘网