标题: STM32单片机LED流水灯程序(循环亮) [打印本页]

作者: 元元元。。。    时间: 2023-6-26 18:50
标题: STM32单片机LED流水灯程序(循环亮)
单片机源程序如下:
  1. /*******************************************************************************                                
  2. * 实 验 名                 : 库函数模板创建
  3. * 实验说明       :
  4. * 连接方式       :
  5. * 注    意                 :        
  6. *******************************************************************************/

  7. #include "stm32f4xx.h"

  8. /*******************************************************************************
  9. * 函 数 名         : delay_ms
  10. * 函数功能                     : 延时函数(单位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. * 函 数 名         : led_Init
  25. * 函数功能                     : 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. * 函 数 名         : main
  43. * 函数功能                   : 主函数
  44. * 输    入         : 无
  45. * 输    出         : 无
  46. *******************************************************************************/
  47. int main()
  48. {
  49.   SystemInit();  //系统时钟初始化
  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代码下载: 流水单循环亮.7z (362.73 KB, 下载次数: 22)





欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1