#include <stm32f10x_map.h> #include "main.h" 由于学习初没有找到中文资料,翻译了点,不管好坏,贴上来和大家分享吧!!! /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /******************************************************************************* * Function Name : RCC_DeInit * Description : Deinitializes the RCC peripheral registers to their default * reset values. * - The HSITRIM[4:0] bits in RCC_CR register are not modified * by this function. * - The RCC_BDCR and RCC_CSR registers are not reset by this * function. * Input : None * Output : None * Return : None *******************************************************************************/ void RCC_DeInit(void) { // Disable APB2 Peripheral Reset RCC->APB2RSTR = 0x00000000; // Disable APB1 Peripheral Reset RCC->APB1RSTR = 0x00000000; // FLITF and SRAM Clock ON RCC->AHBENR = 0x00000014; //Disable APB2 Peripheral Clock RCC->APB2ENR = 0x00000000; // Disable APB1 Peripheral Clock RCC->APB1ENR = 0x00000000; // Set HSION bit RCC->CR |= (u32)0x00000001; // Reset SW[1:0], HPRE[3:0], PPRE1[2:0], PPRE2[2:0], ADCPRE[1:0] and MCO[2:0] bits RCC->CFGR &= 0xF8FF0000; // Reset HSEON, CSSON and PLLON bits RCC->CR &= 0xFEF6FFFF; // Reset HSEBYP bit RCC->CR &= 0xFFFBFFFF; // Reset PLLSRC, PLLXTPRE, PLLMUL[3:0] and USBPRE bits RCC->CFGR &= 0xFF80FFFF; //Disable all interrupts RCC->CIR = 0x00000000; } void SetupClock(void) { /* Reset HSEON and HSEBYP bits before configuring the HSE ------------------*/ /* Reset HSEON bit */ RCC->CR &= 0xfffeffff; //HSEON清零 /* Reset HSEBYP bit */ RCC->CR &= 0xfffbffff; //清除HSEBYP /* Set HSEON bit */ RCC->CR |= 0x00010000; //置位HSEON /* Wait till HSE is ready */ while ((RCC->CR&0x00020000)== 0); //清除HPRE AHB precxaler RCC->CFGR&=0xffffff0f; //SYSCLK not divided HCLK = SYSCLK RCC->CFGR|=0; //清除PPRE2 APB high speed precxaler RCC->CFGR&=0xffffc7ff; //HCLK not divided PCLK2=HCLK RCC->CFGR|=0; //清除PPRE1 APB low speed precxaler RCC->CFGR&=0xfffff8ff; //HCLK divided by 2 PCLK1=HCLK/2 RCC->CFGR|=0x00000400; *(vu32 *)0x40022000 = 0x01; /* Flash 2 wait state */ /* PLLCLK = 8MHz * 9 = 72 MHz */ /* Clear PLLSRC, PLLXTPRE and PLLMUL[21:18] bits */ RCC->CFGR&= 0xffc0ffff; //选择HSE作为PLL时钟输入 PLLMUL选择9倍频 RCC->CFGR|=0x00010000|0x001c0000; RCC->CR|=0X01000000; //置位PLLON位 while((RCC->CR&0x02000000)== 0); //wait till PLL is ready //清除 SW System clock Switch RCC->CFGR&=0xfffffffc; //选择 PLL作为系统时钟 RCC->CFGR|=0x00000002; //等待 PLL作为系统时钟标志置位 while((RCC->CFGR&0x0000000c)!=0x08); // SysTick event each 10 ms with input clock equal to 9MHz (HCLK/8) //SysTick->LOAD=90000; //SysTick->CTRL |= 0x00000002; } void delay(void) { uint i,j; for(i=0;i<10;i++) for(j=0;j<30000;j++); } int main(void) { RCC_DeInit(); SetupClock(); RCC->APB2ENR|=0X08; GPIOB->CRH=0X33333333; GPIOB->BRR|=0XFFFF; /**********MCO******************/ RCC->APB2ENR|=0X04; GPIOA->CRH&=0xf0; GPIOA->CRH|=0x0b; RCC->CFGR|=0X07000000; //RCC->APB2ENR|=0x01; while(1) { //GPIOB->BSRR=0X80000000; //GPIOB->BSRR=0X00008000; GPIOB->ODR|=0X8000; //delay(); GPIOB->ODR&=0X7FFF; // delay(); } //while(1); } #ifndef MAIN_H #define MAIN_H //#define _RCC /*#include <stm32f10x_lib.h> */ #define uchar unsigned char #define uint unsigned int void RCC_DeInit(void); void SetupClock(void); #endif 相关链接:https://bbs.eeworld.com.cn/upfiles/img/200710/20071024165215319.pdf