用最新板MDK库玩转智林STM32众所周知智林的板子是不用固件库的,本人想用库行不行,昨天一试还真行,且为最新的库,环境为
我只写了一个主程序,main.c 其余两个:一个启动代码,一个是编译过的库文件 程序十分简捷:我根本就没调直接用串口下载一次成功,不亦乐乎! 现把主程序传上来大家来分享: #include "stm32f10x_lib.h" /*----------------------------------------------------------*\ | RCC_Configuration | | 时钟初始化 | | 一般不用改 | | | \*----------------------------------------------------------*/ 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); FLASH_SetLatency(FLASH_Latency_0); //FLASH_SetLatency(FLASH_Latency_1); // Enable Prefetch Buffer FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); // PLLCLK = 8MHz * 2 = 16 MHz RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_2); // 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) { } } // Enable peripheral clocks -------------------------------------------------- } /*----------------------------------------------------------*\ | LedInit | | 出始化管脚 | | 因为[url=http://bbs.eeworld.com.cn/thread-74209-1-1.html]开发板LED接在第PB5上,所以初始化PB5 | | | \*----------------------------------------------------------*/ void LedInit(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);//使能外设时钟 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //激活PB5脚 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz; //设管脚速率 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //设输出方式 GPIO_Init(GPIOB, &GPIO_InitStructure); //管脚B其余默认定义 } /*----------------------------------------------------------*\ | Delay | | 延时 Inserts a delay time. | | nCount: 延时时间 | | nCount: specifies the delay time length. | \*----------------------------------------------------------*/ void Delay(vu32 nCount) { for(; nCount != 0; nCount--); } /*----------------------------------------------------------*\ | Delay | | 延时 Inserts a delay time. | | nCount: 延时时间 | | nCount: specifies the delay time length. | \*----------------------------------------------------------*/ main() { RCC_Configuration(); LedInit(); while(1) { GPIO_ResetBits(GPIOB,GPIO_Pin_5); Delay(2000000); GPIO_SetBits(GPIOB,GPIO_Pin_5); Delay(2000000); } } 我把HEX文件和原main.c压缩,另两个是编译环境的只三个文件就实现了。呵呵 欢迎大家去我那溜达:http://shop35738797.taobao.com[/url]开发板(之一)-----只写一个文件点亮LED |
RE:用最新板MDK库玩转智林STM32开发板(之一)-----只写一个文件点亮LED