找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1353|回復: 0
收起左側

STM32單片機LED流水燈程序(循環(huán)亮)

[復制鏈接]
ID:1077459 發(fā)表于 2023-6-26 18:50 | 顯示全部樓層 |閱讀模式
單片機源程序如下:
  1. /*******************************************************************************                                
  2. * 實 驗 名                 : 庫函數(shù)模板創(chuàng)建
  3. * 實驗說明       :
  4. * 連接方式       :
  5. * 注    意                 :        
  6. *******************************************************************************/

  7. #include "stm32f4xx.h"

  8. /*******************************************************************************
  9. * 函 數(shù) 名         : delay_ms
  10. * 函數(shù)功能                     : 延時函數(shù)(單位ms)
  11. * 輸    入         : time
  12. * 輸    出         : 無
  13. *******************************************************************************/



  14. void delay_ms(u32 time)
  15. {
  16.   u32 i=0;
  17.         while(time--)
  18.         {
  19.     i=32000;
  20.     while(i--);               
  21.         }
  22. }

  23. /*******************************************************************************
  24. * 函 數(shù) 名         : led_Init
  25. * 函數(shù)功能                     : led所接GPIO初始化
  26. * 輸    入         : 無
  27. * 輸    出         : 無
  28. *******************************************************************************/

  29. void led_Init(void)
  30. {
  31.         GPIO_InitTypeDef GPIO_InitStructure; //定義結構體變量       
  32.         RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF,ENABLE); //使能端口F時鐘       
  33.         GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT; //輸出模式
  34.         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
  35.         GPIO_InitStructure.GPIO_Speed=GPIO_Speed_100MHz;//速度為100M
  36.         GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;//推挽輸出
  37.         GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP;//上拉
  38.         GPIO_Init(GPIOF,&GPIO_InitStructure); //初始化結構體       
  39.         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       
  40. }
  41. /*******************************************************************************
  42. * 函 數(shù) 名         : main
  43. * 函數(shù)功能                   : 主函數(shù)
  44. * 輸    入         : 無
  45. * 輸    出         : 無
  46. *******************************************************************************/
  47. int main()
  48. {
  49.   SystemInit();  //系統(tǒng)時鐘初始化
  50.         led_Init();    //LED初始化
  51.        
  52.         while(1)
  53.         {
  54.                 GPIO_Write(GPIOF,0xfeff);
  55.                 delay_ms(600);
  56.                 GPIO_Write(GPIOF,0xfdff);
  57.                 delay_ms(600);
  58.                 GPIO_Write(GPIOF,0xfbff);
  59.                 delay_ms(600);
  60.                 GPIO_Write(GPIOF,0xf7ff);
  61.                 delay_ms(600);
  62.                 GPIO_Write(GPIOF,0xefff);
  63.                 delay_ms(600);
  64.                 GPIO_Write(GPIOF,0xdfff);
  65.                 delay_ms(600);
  66.                 GPIO_Write(GPIOF,0xbfff);
  67.                 delay_ms(600);
  68.                 GPIO_Write(GPIOF,0x7fff);
  69.                 delay_ms(600);//0.6左流水
  70.                 }
  71.         }



復制代碼

Keil代碼下載: 流水單循環(huán)亮.7z (362.73 KB, 下載次數(shù): 22)
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表