微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 我的ARM编程技巧---积累

我的ARM编程技巧---积累

时间:11-26 来源:互联网 点击:
随着学习的深入,渐渐发现,编程时更多的工作是不断的配置寄存器,做着许多重复的工作。所以就感觉很有必要把经常使用的寄存器、配置结构罗列出来,以方便使用!!这是其中的一部分,其他的慢慢来

本页所包含的配置函数有:
void SysTick_Configuration(void);
void GPIO_Configuration(void);
void EXTI_Configuration(void);
void NVIC_Configuration(void);
void RCC_Configuration(void);
void IWDG_Configuration(void);

//同时需要配置的结构体变量
GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;

*******//Cortex系统定时器(SysTick)*********************
*******************************************************
*******************************************************
void SysTick_Configuration(void)
{
/
//选择系统定时器(SysTick)的时钟源
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);


SysTick_SetReload(72000);


SysTick_ITConfig(ENABLE);
}
*********///GPIO的配置程序***************************************
******************************************************************
*******************************************************************
void GPIO_Configuration(void) void RCC_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;


GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);


GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
//中断线路初始化
void EXTI_Configuration(void)
{

EXTI_InitStructure.EXTI_Line = EXTI_Line9;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);


EXTI_InitStructure.EXTI_Line = EXTI_Line13;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
}
///嵌套中断向量NVIC**********************************
/
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource9);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel=EXTI0_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);

//为EXTI_Line9使能并配置中断向量

//为EXTI_Line0使能并配置中断向量
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource9);
NVIC_InitStructure.NVIC_IRQChannel=EXTI9_5_IRQChannel;
NVIC_Init(&NVIC_InitStructure);

//为EXTI_Line9使能并配置中断向量

//为EXTI_Line13使能并配置中断向量
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource9);
NVIC_InitStructure.NVIC_IRQChannel=EXTI15_10_IRQChannel;
NVIC_Init(&NVIC_InitStructure);

}

********************************************************************
**************系统时钟的配置RCC_Configuration**********************
********************************************************************
********************************************************************
********************************************************************
void RCC_Configuration(void)
{

RCC_DeInit();

RCC_HSEConfig(RCC_HSE_ON);

HSEStartUpStatus = RCC_WaitForHSEStartUp();
if(HSEStartUpStatus == SUCCESS)
{

RCC_HCLKConfig(RCC_SYSCLK_Div1);

RCC_PCLK2Config(RCC_HCLK_Div1);

RCC_PCLK1Config(RCC_HCLK_Div2);

FLASH_SetLatency(FLASH_Latency_2);

FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
*/
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)
{
}
}
*****************//初始化独立看门狗******************************
********************************************************************
********************************************************************
********************************************************************
void IWDG_Configuration(void)
{


//是能或者失能对寄存器IWDG_PR和IWDG_RLR
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top