找回密码
 立即注册

QQ登录

只需一步,快速开始

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

stm32定时器控制LED灯源码

[复制链接]
跳转到指定楼层
楼主
ID:277454 发表于 2018-1-19 11:19 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
stm32 定时器控制LED灯

单片机源程序如下:

  1. #include "stm32f10x.h"
  2. void init_led(void);
  3. void delay();
  4.    void Delay_us(__IO u32 nTime);
  5.   void SysTick_init(void);
  6.    void TimingDelay_Decrement(void);
  7.    static __IO u32 TimingDelay;

  8. int main(void)
  9. {
  10. init_led();
  11. SysTick_init()        ;
  12.   while(1)
  13.   {
  14.    GPIO_ResetBits (GPIOC,GPIO_Pin_4);
  15.    GPIO_SetBits (GPIOC,GPIO_Pin_5);
  16.    GPIO_SetBits (GPIOB,GPIO_Pin_0);
  17.    GPIO_SetBits (GPIOB,GPIO_Pin_1);
  18.         delay(50);
  19. //        Delay_us(1000);
  20.    GPIO_ResetBits (GPIOC,GPIO_Pin_5);
  21.    GPIO_SetBits (GPIOC,GPIO_Pin_4);
  22.    GPIO_SetBits (GPIOB,GPIO_Pin_0);
  23.    GPIO_SetBits (GPIOB,GPIO_Pin_1);
  24.         delay(50);
  25. //        Delay_us(1000);
  26.         GPIO_ResetBits (GPIOB,GPIO_Pin_0);
  27.    GPIO_SetBits (GPIOC,GPIO_Pin_4);
  28.    GPIO_SetBits (GPIOC,GPIO_Pin_5);
  29.    GPIO_SetBits (GPIOB,GPIO_Pin_1);
  30.         delay(50);
  31. //        Delay_us(1000);
  32.         GPIO_ResetBits (GPIOB,GPIO_Pin_1);
  33.    GPIO_SetBits (GPIOC,GPIO_Pin_4);
  34.    GPIO_SetBits (GPIOC,GPIO_Pin_5);
  35.    GPIO_SetBits (GPIOB,GPIO_Pin_0);
  36.         delay(50);
  37. //        Delay_us(1000);
  38.   }
  39. }
  40. void init_led(void)
  41. {
  42.    GPIO_InitTypeDef GPIO_InitStructure;
  43.    RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOB, ENABLE );

  44.    GPIO_InitStructure.GPIO_Pin=        GPIO_Pin_4|GPIO_Pin_5;
  45.    GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
  46.    GPIO_InitStructure.GPIO_Speed= GPIO_Speed_50MHz;
  47.    GPIO_Init (GPIOC,&GPIO_InitStructure);

  48.    GPIO_InitStructure.GPIO_Pin=        GPIO_Pin_0|GPIO_Pin_1;
  49.    GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
  50.    GPIO_InitStructure.GPIO_Speed= GPIO_Speed_50MHz;
  51.    GPIO_Init (GPIOB,&GPIO_InitStructure);
  52. }

  53. void delay(int n)
  54. {
  55. int i,j;
  56. for(i=0;i<n;i++)
  57. for(j=0;j<5000;j++);
  58. }

  59. void SysTick_init(void)
  60. {       
  61.         if (SysTick_Config(SystemCoreClock / 1000))
  62.   {  
  63.     while (1);
  64.   }
  65. }


  66. void Delay_us(__IO u32 nTime)
  67. {
  68.   TimingDelay = nTime;

  69.   while(TimingDelay != 0);
  70. }

  71. ……………………

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

所有资料51hei提供下载:
stm32-time_led.rar (285.37 KB, 下载次数: 25)


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

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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