完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>
扫一扫,分享给好友
#include "delay.h"
vola tile u8 u8_app_flag =0; void main(void) { u16 flag; RCC_Configuration(); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE | RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOG | RCC_APB2Periph_GPIOC | RCC_APB2Periph_ADC1,ENABLE); GPIO_Configuration(); NVIC_Configuration(); TIM_Configuration(); //SysTick_Config(); while(1) { flag++; if(u8_app_flag) { GPIO_ResetBits(GPIOE,GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7); GPIO_SetBits(GPIOE,GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10); GPIO_ResetBits(GPIOE,GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10); } else { GPIO_SetBits(GPIOE,GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7); GPIO_SetBits(GPIOE,GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10); GPIO_ResetBits(GPIOE,GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10); } } } 下面为配置问价 #include "delay.h" void Delay_ms(u16 time) { u16 i; while(time--) { i=1200; while(i--); } } void RCC_Configuration(void) { ErrorStatus HSEStartUpStatus; //将外设 RCC寄存器重设为缺省值 RCC_DeInit(); //设置外部高速晶振(HSE) RCC_HSEConfig(RCC_HSE_ON); //等待 HSE 起振 HSEStartUpStatus = RCC_WaitForHSEStartUp(); if(HSEStartUpStatus == SUCCESS) { //预取指缓存使能 FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); //设置代码延时值 //FLASH_Latency_2 2 延时周期 FLASH_SetLatency(FLASH_Latency_2); //设置 AHB 时钟(HCLK) //RCC_SYSCLK_Div1 AHB 时钟 = 系统时钟 RCC_HCLKConfig(RCC_SYSCLK_Div1); //设置高速 AHB 时钟(PCLK2) //RCC_HCLK_Div2 APB1 时钟 = HCLK / 2 RCC_PCLK2Config(RCC_HCLK_Div2); //设置低速 AHB 时钟(PCLK1) //RCC_HCLK_Div2 APB1 时钟 = HCLK / 2 RCC_PCLK1Config(RCC_HCLK_Div2); //设置ADC时钟频率 RCC_ADCCLKConfig(RCC_PCLK2_Div2); // PLLCLK = 8MHz * 9 = 72 MHz //设置 PLL 时钟源及倍频系数 RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); //使能或者失能 PLL RCC_PLLCmd(ENABLE); //等待指定的 RCC 标志位设置成功 等待PLL初始化成功 while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) { } //设置系统时钟(SYSCLK) 设置PLL为系统时钟源 RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); //等待PLL成功用作于系统时钟的时钟源 // 0x00:HSI 作为系统时钟 // 0x04:HSE作为系统时钟 // 0x08:PLL作为系统时钟 while(RCC_GetSYSCLKSource() != 0x08) { } } // RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1 , ENABLE); // RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); // RCC_ADCCLKConfig(RCC_PCLK2_Div6); //72M/6=12,ADC最大时间不能超过14M RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE ); //使能ADC1通道时钟,各个管脚时钟 // RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);// Enable USART1 clocks // RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);// Enable USART1 clocks RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE); // Enable TIM clocks //RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 | RCC_APB1Periph_TIM3, ENABLE); // Enable TIM clocks } void NVIC_Configuration(void) { /* Enable the USART1 Interrupt */ NVIC_InitTypeDef NVIC_InitStructure; #ifdef VECT_TAB_RAM /* Set the Vector Table base location at 0x20000000 */ NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); #else /* VECT_TAB_FLASH */ /* Set the Vector Table base location at 0x08000000 */ NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); #endif NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); //选择中断分组2 //NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQChannel;//选择串口1中断 //NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;//抢占式中断优先级设置为0 //NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;//响应式中断优先级设置为0 //NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//使能中断 //NVIC_Init(&NVIC_InitStructure); //NVIC_InitStructure.NVIC_IRQChannel =TIM1_UP_IRQChannel; //40us定时器 //NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //NVIC_InitStructure.NVIC_IRQChannelCmd =ENABLE; //NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQChannel; //使能TIM3总中断 比较输出 具有最高的优先级 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); //NVIC_InitStructure.NVIC_IRQChannel =EXTI3_IRQChannel; //NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //NVIC_InitStructure.NVIC_IRQChannelCmd =ENABLE; //NVIC_Init(&NVIC_InitStructure); } //////////////////////////////////////////////////////////////////////////////中断的初始化 //////////////////////////////////////////////////////////////////////////////定时器的初始化 void TIM_Configuration(void) { /************************************** 定时器3,1ms基本时间单位,系统时间 ***************************************/ TIM_TimeBaseInitTypeDef TIM_BaseInitStructure; /************************************** 定时器3,10us基本时间单位,系统时间 ***************************************/ // TIM_BaseInitStructure.TIM_Period = 56000-1; //设置自动重装载值 // TIM_BaseInitStructure.TIM_Prescaler = 2; //暂不分频,下面再分频 TIM_BaseInitStructure.TIM_Period = 999; //设置自动重装载值 TIM_BaseInitStructure.TIM_Prescaler = 55; //暂不分频,下面再分频 TIM_BaseInitStructure.TIM_ClockDivision = 0; //时钟分割,无视之 TIM_BaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;//向上计数模式 TIM_TimeBaseInit(TIM3, &TIM_BaseInitStructure); TIM_ITConfig(TIM3,TIM_IT_Update, ENABLE); TIM_Cmd(TIM3, ENABLE); } void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10; 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_All; GPIO_InitStructure.GPIO_Speed=GPIO_Speed_2MHz; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOF,&GPIO_InitStructure); //初始化输入口F0--F15 GPIO_InitStructure.GPIO_Pin=GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; GPIO_Init(GPIOG,&GPIO_InitStructure); //初始化输入口G8--G15 //GPIO_SetBits(GPIOE,GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7); //GPIO_SetBits(GPIOE,GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10); //GPIO_ResetBits(GPIOE,GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10); } void SysTick_Configuration(void) //systick初始化函数 { /* Disable SysTick Counter */ SysTick_CounterCmd(SysTick_Counter_Disable); /* Disable the SysTick Interrupt */ SysTick_ITConfig(DISABLE); /* Configure HCLK clock as SysTick clock source */ SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8); //AHP时钟除以8,7M /* SysTick interrupt each 1000 Hz with HCLK equal to 72MHz */ SysTick_SetReload(7000); //设置 SysTick重装载值 /* Enable the SysTick Interrupt */ SysTick_ITConfig(ENABLE); //中断使能 SysTick_CounterCmd(SysTick_Counter_Enable); //使能计数器 } /******************************************************************************* * Function Name : SysTick_Config * Description : Configures SysTick * Input : None * Output : None * Return : None *******************************************************************************/ //SysTick设置 void SysTick_Config(void) { /* Disable SysTick Counter */ SysTick_CounterCmd(SysTick_Counter_Disable); /* Disable the SysTick Interrupt */ SysTick_ITConfig(DISABLE); /* Configure HCLK clock as SysTick clock source */ SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8); /* SysTick interrupt each 1000 Hz with HCLK equal to 72MHz */ SysTick_SetReload(9000); /* Enable the SysTick Interrupt */ SysTick_ITConfig(ENABLE); SysTick_CounterCmd(SysTick_Counter_Enable); } |
|
相关推荐
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
使用stm32l451片子,对ad7606进行3通道100k采样值跳动问题?
792 浏览1 评论
STM32进行DMA数据转运,为什么只有A组最后一位数据被转运到B组去?
1415 浏览2 评论
1733 浏览3 评论
1336 浏览0 评论
嵌入式开发 Win11安装ST-Link 提示 设备描述符请求失败 怎么处理?
1463 浏览0 评论
小黑屋|手机版|Archiver|德赢Vwin官网(湘ICP备2023018690号)
GMT+8, 2024-8-21 20:14, Processed in 0.534983 second(s), Total 69, Slave 53 queries .
Powered by德赢Vwin官网 网
© 2015bbs.elecfans.com
关注我们的微信
下载发烧友APP
德赢Vwin官网 观察
版权所有 © 湖南华秋数字科技有限公司
德赢Vwin官网 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号