天行健,君子以自强不息
分类: C/C++
2010-09-06 21:16:05
/******************************************************************************* /* Includes ------------------------------------------------------------------*/
unsigned short int ADC_ConvertedValue; /******************************************************************************* /* Configure the GPIO ports */ /* Configure EXTI Line9 to generate an interrupt on falling edge */ for(;;) } /******************************************************************************* /* Set SysTick Priority to 3 */ /* Enable the SysTick Interrupt */
/******************************************************************************* /* Enable HSE */ /* Wait till HSE is ready */ if(HSEStartUpStatus == SUCCESS) /* PCLK1 = HCLK/2 */ /* Flash 2 wait state */ /* PLLCLK = 8MHz * 9 = 72 MHz */ /* Enable PLL */ /* Wait till PLL is ready */ /* Select PLL as system clock source */ /* Wait till PLL is used as system clock source */ /******************************************************************************* /* Configure one bit for preemption priority */
while(TimingDelay != 0); /* Disable the SysTick Counter */ /******************************************************************************* */
#ifdef DEBUG /* Infinite loop */ /******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/ |
配置GPIO GPIO_InitTypeDef GPIO_InitStructure; I/O操作 GPIO_WriteBit(GPIOA,GPIO_Pin_0,(BitAction)0X01); //向GPIOA0写入1 |
/******************************************************************************* /* Includes ------------------------------------------------------------------*/
unsigned short int ADC_ConvertedValue; /******************************************************************************* /* Configure the GPIO ports */ /* Configure EXTI Line9 to generate an interrupt on falling edge */ /******************************************************************************* /* Set SysTick Priority to 3 */ /* Enable the SysTick Interrupt */
/******************************************************************************* /* Enable HSE */ /* Wait till HSE is ready */ if(HSEStartUpStatus == SUCCESS) /* PCLK1 = HCLK/2 */ /* Flash 2 wait state */ /* PLLCLK = 8MHz * 9 = 72 MHz */ /* Enable PLL */ /* Wait till PLL is ready */ /* Select PLL as system clock source */ /* Wait till PLL is used as system clock source */ /******************************************************************************* /* Configure one bit for preemption priority */
while(TimingDelay != 0); /* Disable the SysTick Counter */ /******************************************************************************* */
#ifdef DEBUG /* Infinite loop */ /******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/ |
/******************** (C) COPYRIGHT 2007 STMicroelectronics ******************** /* Includes ------------------------------------------------------------------*/ /* Private typedef -----------------------------------------------------------*/ /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* GPIOC->ODR = 0xffffffff; /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /*******************************************************************************
/******************************************************************************* /******************************************************************************* /******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/ |
1.初始化 /* Connect EXTI Line3 to PA.3 */ /* Configure EXTI Line3 to generate an interrupt on falling edge */
2.NVIC void NVIC_Configuration(void) /* Configure one bit for preemption priority */
3.GPIO void GPIO_Configuration(void)
4.中断服务子函数 void EXTI3_IRQHandler(void) GPIOC->ODR = 0xffffffff; |
/******************************************************************************* /* Includes ------------------------------------------------------------------*/ /* Private typedef -----------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /* System Clocks Configuration ---------------------------------------------*/ /* Check if the system has resumed from IWDG reset -------------------------*/ /* Clear reset flags */ /* Configure EXTI Line9 to generate an interrupt on falling edge -----------*/ /* NVIC configuration ------------------------------------------------------*/ /* Configure SysTick to generate an interrupt each 250ms -------------------*/ /* IWDG timeout equal to 350ms (the timeout may varies due to LSI frequency /* IWDG counter clock: 32KHz(LSI) / 32 = 1KHz */ /* Set counter reload value to 349 */ /* Reload IWDG counter */ /* Enable IWDG (the LSI oscillator will be enabled by hardware) */ while(1) /******************************************************************************* /* Enable HSE */ /* Wait till HSE is ready */ if(HSEStartUpStatus == SUCCESS) /* PCLK1 = HCLK */ /* Flash 0 wait state */ /* Select HSE as system clock source */ /* Wait till HSE is used as system clock source */ /******************************************************************************* /* Configure PA.0 and PA.1 as Output push-pull */ /* Configure PB9 as input floating (EXTI Line9) */ /******************************************************************************* /* Connect EXTI Line9 to PA.3 */ /* Configure EXTI Line9 to generate an interrupt on falling edge */ /******************************************************************************* /* 2 bits for Preemption Priority and 2 bits for Sub Priority */ NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQChannel; /* Set SysTick interrupt vector Preemption Priority to 1 */ #ifdef DEBUG /* Infinite loop */ /******************************************************************************* /* Enable the SysTick Counter */ /* Enable the SysTick Interrupt */ /******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/ |
/******************** (C) COPYRIGHT 2007 STMicroelectronics ******************** /* Includes ------------------------------------------------------------------*/ /* Private typedef -----------------------------------------------------------*/ /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* } /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /* As EXTI line9 pending bit is not cleared, the CPU will execute indefinitely /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************************************************************************* /******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/ |
/******************************************************************************* /* Includes ------------------------------------------------------------------*/ /* Private typedef -----------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /* System Clocks Configuration ---------------------------------------------*/ /* Check if the system has resumed from WWDG reset -------------------------*/ /* Clear reset flags */ /* Configure EXTI Line9 to generate an interrupt on falling edge -----------*/ /* NVIC configuration --------------------------------------------------------*/ /* WWDG configuration --------------------------------------------------------*/ /* WWDG clock counter = (PCLK1/4096)/8 = 244 Hz (~4 ms) */ /* Set Window value to 0x41 */ /* Enable WWDG and set counter value to 0x7F, WWDG timeout = ~4 ms * 64 = 262 ms */ /* Clear EWI flag */ /* Enable EW interrupt */ while (1) /******************************************************************************* /* Enable HSE */ /* Wait till HSE is ready */ if(HSEStartUpStatus == SUCCESS) /* PCLK1 = HCLK */ /* Flash 0 wait state */ /* Select HSE as system clock source */ /* Wait till HSE is used as system clock source */ /******************************************************************************* /* Configure PC.06 and PC.07 as Output push-pull */ /* Configure PB9 as input floating (EXTI Line9) */ /******************************************************************************* /* Connect EXTI Line9 to PB.9 */ /* Configure EXTI Line9 to generate an interrupt on falling edge */ /******************************************************************************* /* 2 bits for Preemption Priority and 2 bits for Sub Priority */ NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQChannel; NVIC_InitStructure.NVIC_IRQChannel = WWDG_IRQChannel; #ifdef DEBUG /* Infinite loop */ /******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/ /******************************************************************************* void EXTI9_5_IRQHandler(void) /* As EXTI line9 pending bit is not cleared, the CPU will execute indefinitely |
LED的宏定义: #ifndef HAL_H //硬件初始化 //
//输出宏定义 #define LED2_OFF GPIO_ResetBits(GPIOA, GPIO_Pin_7) #define LED3_OFF GPIO_ResetBits(GPIOC, GPIO_Pin_7) #define LED4_OFF GPIO_ResetBits(GPIOC, GPIO_Pin_5) #define LED5_OFF GPIO_ResetBits(GPIOB, GPIO_Pin_9) #define LED6_OFF GPIO_ResetBits(GPIOB, GPIO_Pin_8) #define LED7_OFF GPIO_ResetBits(GPIOB, GPIO_Pin_5) #define LED8_OFF GPIO_ResetBits(GPIOB, GPIO_Pin_0)
AD转换驱动: /************************************************************** #include "STM32Lib\\stm32f10x.h" void ADC_Configuration(void) RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); /* PB1*/ //设置成模拟量输入 /* ADC1 */
u16 TestAdc(void)
|