單片機源程序如下:- /*******************************************************************************
- * 實 驗 名 : 庫函數(shù)模板創(chuàng)建
- * 實驗說明 :
- * 連接方式 :
- * 注 意 :
- *******************************************************************************/
- #include "stm32f4xx.h"
- /*******************************************************************************
- * 函 數(shù) 名 : delay_ms
- * 函數(shù)功能 : 延時函數(shù)(單位ms)
- * 輸 入 : time
- * 輸 出 : 無
- *******************************************************************************/
- void delay_ms(u32 time)
- {
- u32 i=0;
- while(time--)
- {
- i=32000;
- while(i--);
- }
- }
- /*******************************************************************************
- * 函 數(shù) 名 : led_Init
- * 函數(shù)功能 : led所接GPIO初始化
- * 輸 入 : 無
- * 輸 出 : 無
- *******************************************************************************/
- void led_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure; //定義結構體變量
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF,ENABLE); //使能端口F時鐘
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT; //輸出模式
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;//管腳設置F8-F13
- GPIO_InitStructure.GPIO_Speed=GPIO_Speed_100MHz;//速度為100M
- GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;//推挽輸出
- GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP;//上拉
- GPIO_Init(GPIOF,&GPIO_InitStructure); //初始化結構體
- GPIO_SetBits(GPIOF,GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15); //關閉LED
- }
- /*******************************************************************************
- * 函 數(shù) 名 : main
- * 函數(shù)功能 : 主函數(shù)
- * 輸 入 : 無
- * 輸 出 : 無
- *******************************************************************************/
- int main()
- {
- SystemInit(); //系統(tǒng)時鐘初始化
- led_Init(); //LED初始化
-
- while(1)
- {
- GPIO_Write(GPIOF,0xfeff);
- delay_ms(600);
- GPIO_Write(GPIOF,0xfdff);
- delay_ms(600);
- GPIO_Write(GPIOF,0xfbff);
- delay_ms(600);
- GPIO_Write(GPIOF,0xf7ff);
- delay_ms(600);
- GPIO_Write(GPIOF,0xefff);
- delay_ms(600);
- GPIO_Write(GPIOF,0xdfff);
- delay_ms(600);
- GPIO_Write(GPIOF,0xbfff);
- delay_ms(600);
- GPIO_Write(GPIOF,0x7fff);
- delay_ms(600);//0.6左流水
- }
- }
復制代碼
Keil代碼下載:
流水單循環(huán)亮.7z
(362.73 KB, 下載次數(shù): 22)
2023-6-29 02:34 上傳
點擊文件名下載附件
|