用的火牛的板子 原电路图中PA8接button ,LED1 -> PD8 , LED2 -> PD9 , LED3 -> PD10 , LED4 -> PD11想通过按键产生中断,打印信息才串口或超级中断观察,现在情况是进入main后,led灯先闪烁,只要一按下button,led等也不闪烁了,也不打印任何信息程序如下:
#include "stm32f10x.h"
#include <stdio.h>
#ifdef __GNUC__
/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
set to 'Yes') calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
/* Private function prototypes -----------------------------------------------*/
void GPIO_Configuration(void);
void USART_Configuration(void);
void NVIC_Configuration(void);
void EXTI_Configuration(void);
/*******************************************************************************
* Function Name : Delay
* Description : Delay Time
* Input : - nCount: Delay Time
* Output : None
* Return : None
* Attention : None
*******************************************************************************/
void Delay (uint32_t nCount)
{
for(; nCount != 0; nCount--);
}
/*******************************************************************************
* Function Name : main
* Description : Main program
* Input : None
* Output : None
* Return : None
* Attention : None
*******************************************************************************/
int main(void)
{
GPIO_Configuration();
USART_Configuration();
NVIC_Configuration();
EXTI_Configuration();
//RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
printf("******************************************************************
");
printf("* *
");
printf("* Thank you for using HY-FireBull V1.0 Development Board ! ^_^ *
");
printf("* *
");
printf("******************************************************************
");
/* Infinite loop */
while (1){
if( !GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_8) )
{
Delay(0xffff); /* 按键防抖动 */
if( !GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_8) )
printf("User Button is Press
");
}
/*====LED-ON=======*/
GPIO_SetBits(GPIOD , GPIO_Pin_8);
GPIO_SetBits(GPIOD , GPIO_Pin_9);
GPIO_SetBits(GPIOD , GPIO_Pin_10);
GPIO_SetBits(GPIOD , GPIO_Pin_11);
Delay(0xfffff);
Delay(0xfffff);
/*====LED-OFF=======*/
GPIO_ResetBits(GPIOD , GPIO_Pin_8);
GPIO_ResetBits(GPIOD , GPIO_Pin_9);
GPIO_ResetBits(GPIOD , GPIO_Pin_10);
GPIO_ResetBits(GPIOD , GPIO_Pin_11);
Delay(0xfffff);
Delay(0xfffff);
}
}
/*******************************************************************************
* Function Name : GPIO_Configuration
* Description : Configures the different GPIO ports.
* Input : None
* Output : None
* Return : None
* Attention : None
*******************************************************************************/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
//RCC->APB2ENR |=0x09;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOD | RCC_APB2Periph_AFIO, ENABLE);
/**
*
* User Button -> PA8
*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/**
* LED1 -> PD8 , LED2 -> PD9 , LED3 -> PD10 , LED4 -> PD11
*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; ;
GPIO_Init(GPIOD, &GPIO_InitStructure);
}
/*******************************************************************************
* Function Name : USART_Configuration
* Description : Configure USART1
* Input : None
* Output : None
* Return : None
* Attention : None
*******************************************************************************/
void USART_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_USART1,ENABLE);
/*
* USART1_TX -> PA9 , USART1_RX -> PA10
*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = 115200;
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_ITConfig(USART1, USART_IT_TXE, ENABLE);
USART_Cmd(USART1, ENABLE);
}
/*******************************************************************************
* Function Name : EXTI_Configuration
* Description : Configures the different EXTI lines.
* Input : None
* Output : None
* Return : None
* Attention : None
*******************************************************************************/
void EXTI_Configuration(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource8);
EXTI_ClearITPendingBit(EXTI_Line8);
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_Line = EXTI_Line8;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
EXTI_GenerateSWInterrupt(EXTI_Line8);
}
/*******************************************************************************
* Function Name : NVIC_Configuration
* Description : Configures the nested vectored interrupt controller.
* Input : None
* Output : None
* Return : None
* Attention : None
*******************************************************************************/
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
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);
// NVIC_SetVectorTable(NVIC_VectTab_FLASH,0x0);
}
void EXTI9_5IRQHandler(void)
{ printf("开始进入中段
");
if ( EXTI_GetITStatus(EXTI_Line8) != RESET ) {
EXTI_ClearITPendingBit(EXTI_Line8);
printf("进入中段
");
}
}
/**
* @brief Retargets the C library printf function to the USART.
* @param None
* @retval None
*/
PUTCHAR_PROTOTYPE
{
/* Place your implementation of fputc here */
/* e.g. write a character to the USART */
USART_SendData(USART1, (uint8_t) ch);
/* Loop until the end of transmission */
while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
{}
return ch;
}
#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 can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d
", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
/*********************************************************************************************************
END FILE
*********************************************************************************************************/
[
本帖最后由 echozhang110 于 2011-4-13 21:26 编辑 ]
此帖出自
小平头技术问答
再自己查一下吧 ,附件是智林板子的中断程序,里面有中断的例子,希望能对你有些帮助!
[ 本帖最后由 jishuaihu 于 2011-4-14 10:12 编辑 ]
一周热门 更多>