<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>

新聞中心

STM32 之 KEY

作者: 時(shí)間:2016-12-03 來(lái)源:網(wǎng)絡(luò ) 收藏
在win7下的rcc始終不對,在xp下面就是正?!,F在還沒(méi)有明白原因。

包含文件

本文引用地址:http://dyxdggzs.com/article/201612/325134.htm

(1)Main

C語(yǔ)言:Codee#14612

/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ 實(shí)驗平臺 : ST 官方三合一套件
+ 硬件 : STM32F103C8T6
+ 開(kāi)發(fā)平臺 : IAR For ARM 5.40
+ 仿真器 : J-Link
+ 日期 : 2010-10-26
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

#include "includes.h"

/*******************************************************************************
== Main 函數 ==
*******************************************************************************/
intmain(void)
{
RCC_Configuration();//配置系統時(shí)鐘
NVIC_Configuration();//配置 NVIC 和 Vector Table

GPIO_Configuration();


LED1_HIGH;LED2_HIGH;LED3_HIGH;LED4_HIGH;// 初始化讓燈全滅

//主循環(huán)
while(1)
{
if(KEY_UP==0)
{LED1_LOW;}
if(KEY_DOWN==0)
{LED2_LOW;}
if(KEY_LEFT==0)
{LED3_LOW;}
if(KEY_RIGHT==0)
{LED4_LOW;}

if(KEY_SELECT==0x00)
{LED1_HIGH;LED2_HIGH;LED3_HIGH;LED4_HIGH;}

}
}

(2)Init_External_Device.c

C語(yǔ)言:Codee#14614

#include "includes.h"

/*******************************************************************************
* Function Name : RCC_Configuration
* Description : Configures the different system clocks.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
voidRCC_Configuration(void)
{
ErrorStatusHSEStartUpStatus;

//將外設 RCC寄存器重設為缺省值
RCC_DeInit();

//設置外部高速晶振(HSE)
RCC_HSEConfig(RCC_HSE_ON);

//等待 HSE 起振
HSEStartUpStatus=RCC_WaitForHSEStartUp();

if(HSEStartUpStatus==SUCCESS)
{
//預取指緩存使能
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

//設置代碼延時(shí)值
//FLASH_Latency_2 2 延時(shí)周期
FLASH_SetLatency(FLASH_Latency_2);

//設置 AHB 時(shí)鐘(HCLK)
//RCC_SYSCLK_Div1 AHB 時(shí)鐘 = 系統時(shí)鐘
RCC_HCLKConfig(RCC_SYSCLK_Div1);

//設置高速 AHB 時(shí)鐘(PCLK2)
//RCC_HCLK_Div2 APB1 時(shí)鐘 = HCLK / 2
RCC_PCLK2Config(RCC_HCLK_Div2);

//設置低速 AHB 時(shí)鐘(PCLK1)
//RCC_HCLK_Div2 APB1 時(shí)鐘 = HCLK / 2
RCC_PCLK1Config(RCC_HCLK_Div2);

// PLLCLK = 8MHz * 9 = 72 MHz
//設置 PLL 時(shí)鐘源及倍頻系數
RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9);

//使能或者失能 PLL
RCC_PLLCmd(ENABLE);

//等待指定的 RCC 標志位設置成功 等待PLL初始化成功
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY)==RESET)
{
}


//設置系統時(shí)鐘(SYSCLK) 設置PLL為系統時(shí)鐘源
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

//等待PLL成功用作于系統時(shí)鐘的時(shí)鐘源
// 0x00:HSI 作為系統時(shí)鐘
// 0x04:HSE作為系統時(shí)鐘
// 0x08:PLL作為系統時(shí)鐘
while(RCC_GetSYSCLKSource()!=0x08)
{
}
}

//RCC_APB2PeriphClockCmd(RCC_APB2Periph_ALL, ENABLE);


//使能或者失能 APB2 外設時(shí)鐘
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);

}


/*******************************************************************************
* Function Name : NVIC_Configuration
* Description : Configures NVIC and Vector Table base location.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
voidNVIC_Configuration(void)
{
#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
}

/*******************************************************************************
* Function Name : GPIO_Configuration
* Description : Configures the different GPIO ports.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
voidGPIO_Configuration(void)
{
GPIO_InitTypeDefGPIO_InitStructure_LED_PORTB;
GPIO_InitTypeDefGPIO_InitStructure_KEY_PORTA;
GPIO_InitTypeDefGPIO_InitStructure_KEY_PORTB;
GPIO_InitTypeDefGPIO_InitStructure_KEY_PORTC;

//==== LED =======================================================
GPIO_InitStructure_LED_PORTB.GPIO_Pin=GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;
GPIO_InitStructure_LED_PORTB.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure_LED_PORTB.GPIO_Mode=GPIO_Mode_Out_PP;//推挽輸出
GPIO_Init(GPIOB,&GPIO_InitStructure_LED_PORTB);

//==== KEY =======================================================
GPIO_InitStructure_KEY_PORTA.GPIO_Pin=GPIO_Pin_0;
GPIO_InitStructure_KEY_PORTA.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure_KEY_PORTA.GPIO_Mode=GPIO_Mode_IPU;//上拉輸入
GPIO_Init(GPIOA,&GPIO_InitStructure_KEY_PORTA);

GPIO_InitStructure_KEY_PORTB.GPIO_Pin=GPIO_Pin_7;
GPIO_InitStructure_KEY_PORTB.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure_KEY_PORTB.GPIO_Mode=GPIO_Mode_IPU;//上拉輸入
GPIO_Init(GPIOB,&GPIO_InitStructure_KEY_PORTB);

GPIO_InitStructure_KEY_PORTC.GPIO_Pin=GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;
GPIO_InitStructure_KEY_PORTC.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure_KEY_PORTC.GPIO_Mode=GPIO_Mode_IPU;//上拉輸入
GPIO_Init(GPIOC,&GPIO_InitStructure_KEY_PORTC);

}

/*******************************************************************************
* Function Name : 延時(shí)函數
*******************************************************************************/
voiddelay()
{
inti;
for(i=0;i<0xfffff;i++)
;
}

(3)includes.h

C語(yǔ)言:Codee#14615
#ifndef INCLUDES
#define INCLUDES 1

//==============================================================================
// ★★☆☆★★ 包含文件 ★★☆☆★★
//==============================================================================
#include "stm32f10x_lib.h"
#include "stm32f10x_type.h"
#include "stm32f10x_it.h"

//==============================================================================
// ★★☆☆★★ 全局變量 ★★☆☆★★
//==============================================================================

//==============================================================================
// ★★☆☆★★ 調用函數 ★★☆☆★★
//==============================================================================
//##### 時(shí)鐘部分 #############################################################
voidRCC_Configuration(void);//配置系統時(shí)鐘
voidNVIC_Configuration(void);//配置 NVIC 和 Vector Table

//##### I/O部分 ##############################################################
voidGPIO_Configuration(void);//配置使用的GPIO口

//##### 其他常用函數 #########################################################
voiddelay(void);


//==============================================================================
// ★★☆☆★★ IO口定義 ★★☆☆★★
//==============================================================================
#define LED1_HIGH ( GPIO_SetBits(GPIOB, GPIO_Pin_12) )
#define LED2_HIGH ( GPIO_SetBits(GPIOB, GPIO_Pin_13) )
#define LED3_HIGH ( GPIO_SetBits(GPIOB, GPIO_Pin_14) )
#define LED4_HIGH ( GPIO_SetBits(GPIOB, GPIO_Pin_15) )

#define LED1_LOW ( GPIO_ResetBits(GPIOB, GPIO_Pin_12) )
#define LED2_LOW ( GPIO_ResetBits(GPIOB, GPIO_Pin_13) )
#define LED3_LOW ( GPIO_ResetBits(GPIOB, GPIO_Pin_14) )
#define LED4_LOW ( GPIO_ResetBits(GPIOB, GPIO_Pin_15) )

#define KEY_UP ( GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_14) )
#define KEY_DOWN ( GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0) )
#define KEY_LEFT ( GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_15) )
#define KEY_RIGHT ( GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_13) )
#define KEY_SELECT ( GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_7) )


#endif



關(guān)鍵詞: STM32KE

評論


技術(shù)專(zhuān)區

關(guān)閉
国产精品自在自线亚洲|国产精品无圣光一区二区|国产日产欧洲无码视频|久久久一本精品99久久K精品66|欧美人与动牲交片免费播放
<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>