STM32学习笔记6(TIM模块定时器)
//Step4.中断服务子程序:void TIM1_UP_IRQHandler(void){GPIOC-> int fputc(int ch, FILE *f){//USART_SendData(USART1, (u8) ch);USART1-> SENSE:温度传感器的当前输出电压,与ADC_DR 寄存器中的结果ADC_ConvertedValue之间的转换关系为://ADC_ConvertedValue * Vdd// VSENSE = --------------------------//Vdd_convert_value(0xFFF)// Avg_Slope:温度传感器输出电压和温度的关联参数,典型值4.3 mV/℃。 Vtemp_sensor = advalue * 330 / 4096;Current_Temp = (s32)(143 - Vtemp_sensor)*10000/43 + 2500;return (s16)Current_Temp;} u16 GetVolt(u16 advalue){return (u16)(advalue * 330 / 4096);} void RCC_Configuration(void){ErrorStatus HSEStartUpStatus; //使能外部晶振RCC_HSEConfig(RCC_HSE_ON);//等待外部晶振稳定HSEStartUpStatus = RCC_WaitForHSEStartUp();//如果外部晶振启动成功,则进行下一步操作if(HSEStartUpStatus==SUCCESS){//设置HCLK(AHB时钟)=SYSCLKRCC_HCLKConfig(RCC_SYSCLK_Div1); //PCLK1(APB1) = HCLK/2RCC_PCLK1Config(RCC_HCLK_Div2); //PCLK2(APB2) = HCLKRCC_PCLK2Config(RCC_HCLK_Div1);//设置ADC时钟频率RCC_ADCCLKConfig(RCC_PCLK2_Div2); //FLASH时序控制//推荐值:SYSCLK = 0~24MHzLatency=0//SYSCLK = 24~48MHz Latency=1//SYSCLK = 48~72MHz Latency=2FLASH_SetLatency(FLASH_Latency_2);//开启FLASH预取指功能FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); //PLL设置 SYSCLK/1 * 9 = 8*1*9 = 72MHzRCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);//启动PLLRCC_PLLCmd(ENABLE);//等待PLL稳定while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);//系统时钟SYSCLK来自PLL输出RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);//切换时钟后等待系统时钟稳定while(RCC_GetSYSCLKSource()!=0x08); } //下面是给各模块开启时钟//启动GPIORCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD,ENABLE);//启动AFIORCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);//启动USART1RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);//启动DMA时钟RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);//启动ADC1时钟RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); } void GPIO_Configuration(void){GPIO_InitTypeDef GPIO_InitStructure; //PC口4567脚设置GPIO输出,推挽 2MGPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;GPIO_Init(GPIOC, &GPIO_InitStructure); //KEY2 KEY3 JOYKEY//位于PD口的3 4 11-15脚,使能设置为输入GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_11 | GPIO_Pin_12 |GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;GPIO_Init(GPIOD, &GPIO_InitStructure); //USART1_TXGPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;GPIO_Init(GPIOA, &GPIO_InitStructure);//USART1_RXGPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;GPIO_Init(GPIOA, &GPIO_InitStructure);//ADC_CH10--> PC0GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;GPIO_Init(GPIOC, &GPIO_InitStructure); } void NVIC_Configuration(void){NVIC_InitTypeDef NVIC_InitStructure; #ifdef VECT_TAB_RAM// Set the Vector Table base location at 0x20000000NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);#else// Set the Vector Table base location at 0x08000000NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);#endif //设置NVIC优先级分组为Group2:0-3抢占式优先级,0-3的响应式优先级NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//串口中断打开NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQChannel;NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;NVIC_Init(&NVIC_InitStructure);} void USART1_Configuration(void){USART_InitTypeDef USART_InitStruc
STM32学习笔记TIM模块定时 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)