自己的USER文件组下有3个c文件,以后会按照这个程序结构写程序。 代码参考于 “ OPELC思蛻蒙 http://bbs.opelc.org/viewthread.php?tid=6441&extra=page%3D1 ” (1)Main.c 主函数 (2)Init_External_Device.c 外设初始化函数 (3)includes.h 自己的c文件用的包含头文件 下面是源码: (1)Main
C语言:
Codee#14359
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ 实验平台 : ST 官方三合一套件 + 硬件 : STM32F103C8T6 + 开发平台 : IAR For ARM 5.40 + 仿真器 : J-Link + 日期 : 2010-10-14 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ #include "includes.h" /******************************************************************************* == Main 函数 == *******************************************************************************/ int main( void) { RCC_Configuration(); //配置系统时钟 NVIC_Configuration(); //配置 NVIC 和 Vector Table GPIO_Configuration(); //主循环 while ( 1) { delay(); //设置指定的数据端口位——LED1熄灭 GPIO_SetBits( GPIOB , GPIO_Pin_12); delay(); //清除指定的数据端口位——LED1亮 GPIO_ResetBits( GPIOB , GPIO_Pin_12); delay(); GPIO_SetBits( GPIOB , GPIO_Pin_13); delay(); GPIO_ResetBits( GPIOB , GPIO_Pin_13); delay(); GPIO_SetBits( GPIOB , GPIO_Pin_14); delay(); GPIO_ResetBits( GPIOB , GPIO_Pin_14); delay(); GPIO_SetBits( GPIOB , GPIO_Pin_15); delay(); GPIO_ResetBits( GPIOB , GPIO_Pin_15); } } (2)Init_External_Device.c
C语言:
Codee#14361
#include "includes.h"
/******************************************************************************* * Function Name : RCC_Configuration * Description : Configures the different system clocks. * Input : None * Output : None * Return : None *******************************************************************************/ 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); // 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) { } } //使能或者失能 APB2 外设时钟 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 *******************************************************************************/ void NVIC_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 *******************************************************************************/ void GPIO_Configuration( void) { GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure . GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15 ; GPIO_InitStructure . GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure . GPIO_Mode = GPIO_Mode_Out_PP; //推挽 GPIO_Init( GPIOB , & GPIO_InitStructure); } /******************************************************************************* * Function Name : 延时函数 *******************************************************************************/ void delay() { int i; for ( i = 0; i < 0xfffff; i ++) ; } (3)includes.h
C语言:
Codee#14362
#ifndef INCLUDES |