STM32外部中程序断2.docx
《STM32外部中程序断2.docx》由会员分享,可在线阅读,更多相关《STM32外部中程序断2.docx(24页珍藏版)》请在冰豆网上搜索。
![STM32外部中程序断2.docx](https://file1.bdocx.com/fileroot1/2023-1/2/95d4a01b-29d9-471f-a722-d11aa1ec4465/95d4a01b-29d9-471f-a722-d11aa1ec44651.gif)
STM32外部中程序断2
///***********************************************************************
//
//火牛开发板基础实验
//外部中断实验
//
//分别按下S3、S4,在串口1打印出相关信息
//
//************************************************************************/
//
//
//#include"stm32f10x.h"
//#include"string.h"
//
//
//
///***********************************************************************
//
//外设时钟使能
//
//
//************************************************************************/
//voidRCC_Configuration(void)
//{
///*使能外设时钟*/
//RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_AFIO|
//RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC|
//RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOE,ENABLE);
//
//RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
//}
//
///*******************************************************************************
//
//全部用到的引脚将在在配置
//
//*******************************************************************************/
//voidGPIO_Configuration(void)
//{
//GPIO_InitTypeDefGPIO_InitStructure;
//
///*配置串口1引脚*/
////GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9|GPIO_8;
////GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
////GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
////GPIO_Init(GPIOB,&GPIO_InitStructure);
//
//GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0;
//GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
//GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
//GPIO_Init(GPIOE,&GPIO_InitStructure);
//
///*外部中断引脚*/
//GPIO_InitStructure.GPIO_Pin=GPIO_Pin_2|GPIO_Pin_3;
//GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
//GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;
//GPIO_Init(GPIOE,&GPIO_InitStructure);
//}
//
///*******************************************************************************
//
//全部中断在此配置
//
//*******************************************************************************/
//voidNVIC_Configuration(void)
//{
//NVIC_InitTypeDefNVIC_InitStructure;
///*ConfiguretheNVICPreemptionPriorityBits*/
//NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
//
///*EnabletheUSART1Interrupt*/
//NVIC_InitStructure.NVIC_IRQChannel=EXTI2_IRQn;
//NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;
//NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;
//NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
//NVIC_Init(&NVIC_InitStructure);
//
//NVIC_InitStructure.NVIC_IRQChannel=EXTI3_IRQn;
//NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;
//NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;
//NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
//NVIC_Init(&NVIC_InitStructure);
//
//
////NVIC_InitStructure.NVIC_IRQChannel=EXTI9_5_IRQn;//S4中断入口
////NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;
////NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
////NVIC_Init(&NVIC_InitStructure);
//
////NVIC_InitStructure.NVIC_IRQChannel=EXTI0_IRQn;//S3中断入口
////NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;
////NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
////NVIC_Init(&NVIC_InitStructure);
//
//}
//
///*******************************************************************************
//
//外部中断在此配置
//
//*******************************************************************************/
//voidEXTI_Configuration(void)
//{
//EXTI_InitTypeDefEXTI_InitStructure;
//
//GPIO_EXTILineConfig(GPIO_PortSourceGPIOE,GPIO_PinSource2);//S4中断
//GPIO_EXTILineConfig(GPIO_PortSourceGPIOE,GPIO_PinSource3);
//EXTI_ClearITPendingBit(EXTI_Line2);
//EXTI_ClearITPendingBit(EXTI_Line3);
//EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt;
//EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Falling;
//EXTI_InitStructure.EXTI_Line=EXTI_Line2|EXTI_Line3;
//EXTI_InitStructure.EXTI_LineCmd=ENABLE;
//EXTI_Init(&EXTI_InitStructure);
//
////GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource0);//S3中断
////EXTI_InitStructure.EXTI_Line=EXTI_Line0;
////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_Line13);
//
//}
//
///*******************************************************************************
//
//初始化时钟晶振72MHZ
//
//*******************************************************************************/
//voidSysClock_Init(void)
//{
//ErrorStatusHSEStartUpStatus;
//RCC_DeInit();
//RCC_HSEConfig(RCC_HSE_ON);
//HSEStartUpStatus=RCC_WaitForHSEStartUp();
//if(HSEStartUpStatus==SUCCESS){
//FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
//FLASH_SetLatency(FLASH_Latency_2);
//RCC_HCLKConfig(RCC_SYSCLK_Div1);
//RCC_PCLK2Config(RCC_HCLK_Div1);
//RCC_PCLK1Config(RCC_HCLK_Div2);
//RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9);
//RCC_PLLCmd(ENABLE);
//while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY)==RESET){
//;
//}
//RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
//while(RCC_GetSYSCLKSource()!
=0x08){
//;
//}
//}
//}
//
///*****************************************************************
//
//USART1初始化baud波特率
//
//
//*****************************************************************/
//voidUSART1_Init(unsignedintbaud)
//{
//USART_InitTypeDefUSART_InitStructure;
//
//USART_InitStructure.USART_BaudRate=baud;
//USART_InitStructure.USART_WordLength=USART_WordLength_8b;
//USART_InitStructure.USART_StopBits=USART_StopBits_1;
//USART_InitStructure.USART_Parity=USART_Parity_No;
//USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
//USART_InitStructure.USART_Mode=USART_Mode_Rx|USART_Mode_Tx;
//
//USART_Init(USART1,&USART_InitStructure);
//USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
//USART_Cmd(USART1,ENABLE);
//}
//
///*****************************************************************
//
//从USART1发送一个字节
//
//*****************************************************************/
//voidUSART1_SendByte(unsignedchartemp)
//{
//USART_SendData(USART1,temp);
//while(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET);
//}
//
///*****************************************************************
//
//从USART1发送字符串
//
//*****************************************************************/
//voidUSART1_Printf(char*pch)
//{
//while(*pch!
='\0'){
//USART1_SendByte(*(unsignedchar*)pch);
//pch++;
//}
//}
//
///******************************************
//*
//*延时程序ms
//*
//****************************************/
//voidDelay(unsignedshorttime)
//{
//unsignedshorti,j;
//
//for(;time>0;time--){
//for(j=0;j<10;j++){
//for(i=0;i<1000;i++);
//}
//}
//
//}
//
//
///*******************************************************
//
//MAIN函数
//
//*******************************************************/
//intmain(void)
//{
//SysClock_Init();//初始化系统时钟72MHZ
//RCC_Configuration();//使能外设
//GPIO_Configuration();//配置引脚
//EXTI_Configuration();
//NVIC_Configuration();//配置中断
//USART1_Init(9600);//配置串口1,波特率9600
//
//while
(1){
////GPIO_ResetBits(GPIOE,GPIO_Pin_0);
////Delay(1000);
////GPIO_SetBits(GPIOE,GPIO_Pin_0);
////Delay(1000);
//}
//}
//
//
//
//
//
//
//
/***********************************************************************
火牛开发板基础实验
外部中断实验
分别按下S3、S4,在串口1打印出相关信息
************************************************************************/
#include"stm32f10x.h"
#include"string.h"
/***********************************************************************
外设时钟使能
************************************************************************/
voidRCC_Configuration(void)
{
/*使能外设时钟*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_AFIO|
RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC|
RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOE,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
}
/*******************************************************************************
全部用到的引脚将在在配置
*******************************************************************************/
voidGPIO_Configuration(void)
{
GPIO_InitTypeDefGPIO_InitStructure;/*配置串口1引脚*/
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_Init(GPIOD,&GPIO_InitStructure);
/*外部中断引脚*/
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_8;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_Init(GPIOD,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_Init(GPIOD,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_11;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_Init(GPIOD,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10|GPIO_Pin_12;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;
GPIO_Init(GPIOC,&GPIO_InitStructure);
}
/*******************************************************************************
全部中断在此配置
*******************************************************************************/
voidNVIC_Configuration(void)
{
NVIC_InitTypeDefNVIC_InitStructure;
/*ConfiguretheNVICPreemptionPriorityBits*/
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
/*EnabletheUSART1Interrupt*/
NVIC_InitStructure.NVIC_IRQChannel=EXTI15_10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;
NVIC_InitStruc