?? main.c
字號:
#include"stm32f10x_lib.h"
void RCC_Configuration(void);
void GPIO_Configuration(void);
void delay()
{
vu32 i,j;
for(i=0;i<50;i++)
for(j=0;j<50000;j++);
}
int main(void)
{
vu16 n;
u16 i;
RCC_Configuration();
GPIO_Configuration();
n=0xff00;
while(1)
{
for(i=0;i<8;i++)
{
GPIO_Write(GPIOA,n);
n>>=1;
delay();
}
for(i=0;i<8;i++)
{
GPIO_Write(GPIOA,n);
n<<=1;
delay();
}
n=0xff00;
}
}
void RCC_Configuration(void)
{
ErrorStatus HSEStartUpStatus;/* RCC system reset(for debug purpose) */
RCC_DeInit();
/* Enable HSE */
RCC_HSEConfig(RCC_HSE_ON);
/* Wait till HSE is ready */
HSEStartUpStatus = RCC_WaitForHSEStartUp();
if(HSEStartUpStatus == SUCCESS)
{
/* HCLK = SYSCLK */
RCC_HCLKConfig(RCC_SYSCLK_Div1);
/* PCLK2 = HCLK */
RCC_PCLK2Config(RCC_HCLK_Div1);
/* PCLK1 = HCLK/2 */
RCC_PCLK1Config(RCC_HCLK_Div2);
/* Flash 2 wait state */
FLASH_SetLatency(FLASH_Latency_2);
/* Enable Prefetch Buffer */
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
/* PLLCLK = 8MHz * 9 = 72 MHz */
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
/* Enable PLL */
RCC_PLLCmd(ENABLE);
/* Wait till PLL is ready */
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
{
}
/* Select PLL as system clock source */
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
/* Wait till PLL is used as system clock source */
while(RCC_GetSYSCLKSource() != 0x08)
{
}
}
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA |
RCC_APB2Periph_GPIOB |
RCC_APB2Periph_GPIOC ,ENABLE );
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_Pin_11 |
GPIO_Pin_12 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // 推挽輸出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // 最高輸出速率50MHz
GPIO_Init(GPIOA, &GPIO_InitStructure); // 選擇A端口
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 |
GPIO_Pin_1 |
GPIO_Pin_2 |
GPIO_Pin_5 |
GPIO_Pin_6 |
GPIO_Pin_7 |
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_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // 推挽輸出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // 最高輸出速率50MHz
GPIO_Init(GPIOB, &GPIO_InitStructure); // 選擇B端口
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_Pin_11 |
GPIO_Pin_12 |
GPIO_Pin_13 |
GPIO_Pin_15 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // 推挽輸出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // 最高輸出速率50MHz
GPIO_Init(GPIOC, &GPIO_InitStructure); // 選擇C端口
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -