這是我修改的一部分主程序里的點亮LED的程序
單片機源程序如下:
- /********************************************************************************/
- /* 2017年9月15日STM32F103ZET6最小系統開發板 LED3閃爍 PE5-->LED3 */
- /********************************************************************************/
- #include "stm32f10x_lib.h"
- ErrorStatus HSEStartUpStatus;
- void Delay(vu32 nTime);
- void RCC_Configuration(void);
- void GPIO_Configuration(void);
-
- int main(void)
- {
- RCC_Configuration(); /* 配置系統時鐘 */
- GPIO_Configuration(); /* 配置GPIO IO口初始化 */
-
-
- while(1)
- {
- GPIO_ResetBits(GPIOB,GPIO_Pin_5);
- Delay(0XFFFFF);
- GPIO_SetBits(GPIOB,GPIO_Pin_5);
- Delay(0XFFFFF);
- GPIO_ResetBits(GPIOE,GPIO_Pin_5);
- Delay(0XFFFFF);
- GPIO_SetBits(GPIOE,GPIO_Pin_5);
- Delay(0XFFFFF);
- GPIO_ResetBits(GPIOE,GPIO_Pin_6);
- Delay(0XFFFFF);
- GPIO_SetBits(GPIOE,GPIO_Pin_6);
- Delay(0XFFFFF);
-
- }
- }
- /*******************************************************************************
- * Function Name : RCC_Configuration
- * Description : Configures the different system clocks.
- *******************************************************************************/
- void RCC_Configuration(void)
- {
- RCC_DeInit(); /* RCC system reset(for debug purpose) */
- RCC_HSEConfig(RCC_HSE_ON); /*打開外部高速晶振(HSE)*/
- /*等待HSE起振 該函數將等待直到HSE就緒,或者在超時的情況下退出*/
- HSEStartUpStatus = RCC_WaitForHSEStartUp();
- if(HSEStartUpStatus == SUCCESS)
- {
- RCC_HCLKConfig(RCC_SYSCLK_Div1); /* 設置AHB時鐘(HCLK),AHB時鐘 = 系統時鐘 */
- RCC_PCLK2Config(RCC_HCLK_Div1); /* 設置高速AHB時鐘(PCLK2),APB2時鐘 = HCLK */
- RCC_PCLK1Config(RCC_HCLK_Div2); /* 設置低速AHB時鐘(PCLK1),APB1時鐘 = HCLK/2 */
- FLASH_SetLatency(FLASH_Latency_2); /* Flash 2 wait state */
- FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); /* 使能或者失能預取指緩存,預取指緩存使能 */
- /* 設置PLL時鐘源及倍頻系數PLL的輸入時鐘 = HSE時鐘頻率 PLL輸入時鐘 x 9 */
- RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
- RCC_PLLCmd(ENABLE); /*使能PLL*/
- /* Wait till PLL is ready 檢查指定的RCC標志位設置與否PLL就緒 */
- while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
- RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); /* 設置系統時鐘(SYSCLK)選擇PLL作為系統時鐘 */
- /* Wait till PLL is used as system clock source 返回用作系統時鐘的時鐘源0x08:PLL作為系統時鐘 */
- while(RCC_GetSYSCLKSource() != 0x08);
- }
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOE, ENABLE); /* 定義輸出端口*/
- }
- /*******************************************************************************
- * Function Name : GPIO_Configuration PB5-->LD2 PE5-->LD3 PE6-->LD4
- * Description : Configures the different GPIO ports.
- *******************************************************************************/
- void GPIO_Configuration(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- /* PB5口配置為輸出 */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- /* PE5~PE6口配置為輸出 */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOE, &GPIO_InitStructure);
- }
- void Delay(vu32 nCount) /* 延時 */
- {
- for(; nCount != 0; nCount--);
- }
- //while(1)
- //{
- // GPIOE->BSSRR = 0xffdf;
- // Delay(5000000);
- //GPIOE->ODR = 0xffff; /* PE5=1 --> 熄滅LED3 */
- //Delay(5000000);
- //
- //}
- //
復制代碼
所有資料51hei提供下載:
LED234.rar
(220.28 KB, 下載次數: 60)
2017-10-8 15:28 上傳
點擊文件名下載附件
stm32中的流水燈 下載積分: 黑幣 -5
|