找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 8480|回复: 0
打印 上一主题 下一主题
收起左侧

STM32F407跑马灯实验程序 DS0和DS1交替闪烁

[复制链接]
跳转到指定楼层
楼主
ID:257164 发表于 2017-12-4 13:52 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
2黑币
F407 跑马灯实验工程,好大作用
本实验将实现如下功能:本实验通过代码控制STM32F407开发板上的两个LED:DS0和DS1交替闪烁,实现类似跑马灯的效果。

单片机源程序如下:
  1. #include "sys.h"
  2. #include "delay.h"
  3. #include "usart.h"
  4. #include "led.h"


  5. //跑马灯实验 -库函数版本
  6. //STM32F4工程-库函数版本               

  7. int main(void)
  8. {

  9.         delay_init(168);                  //初始化延时函数
  10.         LED_Init();                        //初始化LED端口
  11.         
  12.   /**下面是通过直接操作库函数的方式实现IO控制**/        
  13.         
  14.         while(1)
  15.         {
  16.         GPIO_ResetBits(GPIOF,GPIO_Pin_9);  //LED0对应引脚GPIOF.9拉低,亮  等同LED0=0;
  17.         GPIO_SetBits(GPIOF,GPIO_Pin_10);   //LED1对应引脚GPIOF.10拉高,灭 等同LED1=1;
  18.         delay_ms(500);                     //延时300ms
  19.         GPIO_SetBits(GPIOF,GPIO_Pin_9);           //LED0对应引脚GPIOF.0拉高,灭  等同LED0=1;
  20.         GPIO_ResetBits(GPIOF,GPIO_Pin_10); //LED1对应引脚GPIOF.10拉低,亮 等同LED1=0;
  21.         delay_ms(500);                     //延时300ms
  22.         }
  23. }


  24. /**
  25. *******************下面注释掉的代码是通过 位带 操作实现IO口控制**************************************
  26.         
  27. int main(void)
  28. {

  29.         delay_init(168);                  //初始化延时函数
  30.         LED_Init();                        //初始化LED端口
  31.   while(1)
  32.         {
  33.      LED0=0;                          //LED0亮
  34.            LED1=1;                                //LED1灭
  35.                  delay_ms(500);
  36.                  LED0=1;                                //LED0灭
  37.                  LED1=0;                                //LED1亮
  38.                  delay_ms(500);
  39.          }
  40. }
  41. **************************************************************************************************
  42. **/        
  43.         
  44. /**
  45. *******************下面注释掉的代码是通过 直接操作寄存器 方式实现IO口控制**************************************
  46. int main(void)
  47. {

  48.         delay_init(168);                  //初始化延时函数
  49.         LED_Init();                        //初始化LED端口
  50.         while(1)
  51.         {
  52.      GPIOF->BSRRH=GPIO_Pin_9;//LED0亮
  53.            GPIOF->BSRRL=GPIO_Pin_10;//LED1灭
  54.                  delay_ms(500);
  55.      GPIOF->BSRRL=GPIO_Pin_9;//LED0灭
  56.            GPIOF->BSRRH=GPIO_Pin_10;//LED1亮
  57.                  delay_ms(500);

  58.          }
  59. }         
  60. **************************************************************************************************
  61. **/        




  62. #include "sys.h"
  63. #include "delay.h"
  64. #include "usart.h"
  65. #include "led.h"


  66. //跑马灯实验 -库函数版本
  67. //STM32F4工程-库函数版本
  68. //淘宝店铺:http://mcudev.taobao.com               

  69. int main(void)
  70. {

  71.         delay_init(168);                  //初始化延时函数
  72.         LED_Init();                        //初始化LED端口
  73.         
  74.   /**下面是通过直接操作库函数的方式实现IO控制**/        
  75.         
  76.         while(1)
  77.         {
  78.         GPIO_ResetBits(GPIOF,GPIO_Pin_9);  //LED0对应引脚GPIOF.9拉低,亮  等同LED0=0;
  79.         GPIO_SetBits(GPIOF,GPIO_Pin_10);   //LED1对应引脚GPIOF.10拉高,灭 等同LED1=1;
  80.         delay_ms(500);                     //延时300ms
  81.         GPIO_SetBits(GPIOF,GPIO_Pin_9);           //LED0对应引脚GPIOF.0拉高,灭  等同LED0=1;
  82.         GPIO_ResetBits(GPIOF,GPIO_Pin_10); //LED1对应引脚GPIOF.10拉低,亮 等同LED1=0;
  83.         delay_ms(500);                     //延时300ms
  84.         }
  85. }


  86. /**
  87. *******************下面注释掉的代码是通过 位带 操作实现IO口控制**************************************
  88.         
  89. int main(void)
  90. {

  91.         delay_init(168);                  //初始化延时函数
  92.         LED_Init();                        //初始化LED端口
  93.   while(1)
  94.         {
  95.      LED0=0;                          //LED0亮
  96.            LED1=1;                                //LED1灭
  97.                  delay_ms(500);
  98.                  LED0=1;                                //LED0灭
  99.                  LED1=0;                                //LED1亮
  100.                  delay_ms(500);
  101.          }
  102. }
  103. **************************************************************************************************
  104. **/        
  105.         
  106. /**
  107. *******************下面注释掉的代码是通过 直接操作寄存器 方式实现IO口控制**************************************
  108. int main(void)
  109. {

  110.         delay_init(168);                  //初始化延时函数
  111.         LED_Init();                        //初始化LED端口
  112.         while(1)
  113.         {
  114.      GPIOF->BSRRH=GPIO_Pin_9;//LED0亮
  115.            GPIOF->BSRRL=GPIO_Pin_10;//LED1灭
  116.                  delay_ms(500);
  117.      GPIOF->BSRRL=GPIO_Pin_9;//LED0灭
  118.            GPIOF->BSRRH=GPIO_Pin_10;//LED1亮
  119.                  delay_ms(500);
  120. ……………………

  121. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码

所有资料51hei提供下载:
F407 跑马灯实验.rar (506.11 KB, 下载次数: 23)


评分

参与人数 2黑币 +55 收起 理由
lumancy + 5 共享资料的黑币奖励!
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表