找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2178|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

stm32定時器控制LED燈源碼

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:277454 發(fā)表于 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黑下載附件…………
復(fù)制代碼

所有資料51hei提供下載:
stm32-time_led.rar (285.37 KB, 下載次數(shù): 25)


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

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

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

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

快速回復(fù) 返回頂部 返回列表