程序使用庫函數編寫,不直接操作寄存器
庫版本STM32F10x_StdPeriph_Lib_V3.5.0,開發環境MDK4.12,調試工具是JLINK v8.0,芯片STM32F103C8T6
注意:如果使用3.5的庫開發的話,RCC的配置簡單了很多,系統默認的情況下調用SystemInit()函數,自動初始化了時鐘,只需使能對應的GPIO端口。
- #include "stm32f10x.h"
- //定義GPIO結構體
- GPIO_InitTypeDef GPIO_InitStructure;
- //main函數
- int main()
- {
- //使能GPIO時鐘
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB , ENABLE);
- //GPIO結構體配置
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- //GPIO初始化
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- //點亮小燈
- GPIO_SetBits(GPIOB, GPIO_Pin_5);
- //無限循環
- while(1);
- }