久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 4324|回復: 0
打印 上一主題 下一主題
收起左側

LED雙燈閃爍實驗 寄存器版程序分享 51單片機到STM32過渡

[復制鏈接]
跳轉到指定樓層
樓主
51單片機到STM32單片機的過渡,寄存器版程序分享!
本例程使用MDK4.12版本編譯好,進入MDK文件夾點擊project.uvproj即可打開例程

1.MDK文件夾
     --- MDK啟動軟件

2.obj文件夾
     --- 包含編譯產生的中間文件
     --- 最終可執行的HEX文件程序

3.src文件夾(包含所有的源代碼)
     ---包含main.c文件


  1. /*  本實驗使得GPIOD8和GPIOD9管腳控制STM32VCT6的LED1和LED2兩個燈進行閃爍 */

  2. #define     __IO    volatile            
  3. typedef unsigned           int uint32_t;
  4. typedef __IO uint32_t  vu32;
  5. typedef unsigned short     int uint16_t;

  6. #define GPIO_Pin_0                 ((uint16_t)0x0001)  /*!< Pin 0 selected */
  7. #define GPIO_Pin_1                 ((uint16_t)0x0002)  /*!< Pin 1 selected */
  8. #define GPIO_Pin_2                 ((uint16_t)0x0004)  /*!< Pin 2 selected */
  9. #define GPIO_Pin_3                 ((uint16_t)0x0008)  /*!< Pin 3 selected */
  10. #define GPIO_Pin_4                 ((uint16_t)0x0010)  /*!< Pin 4 selected */
  11. #define GPIO_Pin_5                 ((uint16_t)0x0020)  /*!< Pin 5 selected */
  12. #define GPIO_Pin_6                 ((uint16_t)0x0040)  /*!< Pin 6 selected */
  13. #define GPIO_Pin_7                 ((uint16_t)0x0080)  /*!< Pin 7 selected */
  14. #define GPIO_Pin_8                 ((uint16_t)0x0100)  /*!< Pin 8 selected */
  15. #define GPIO_Pin_9                 ((uint16_t)0x0200)  /*!< Pin 9 selected */
  16. #define GPIO_Pin_10                ((uint16_t)0x0400)  /*!< Pin 10 selected */
  17. #define GPIO_Pin_11                ((uint16_t)0x0800)  /*!< Pin 11 selected */
  18. #define GPIO_Pin_12                ((uint16_t)0x1000)  /*!< Pin 12 selected */
  19. #define GPIO_Pin_13                ((uint16_t)0x2000)  /*!< Pin 13 selected */
  20. #define GPIO_Pin_14                ((uint16_t)0x4000)  /*!< Pin 14 selected */
  21. #define GPIO_Pin_15                ((uint16_t)0x8000)  /*!< Pin 15 selected */
  22. #define GPIO_Pin_All               ((uint16_t)0xFFFF)  /*!< All pins selected */

  23. #define RCC_APB2Periph_AFIO              ((uint32_t)0x00000001)
  24. #define RCC_APB2Periph_GPIOA             ((uint32_t)0x00000004)
  25. #define RCC_APB2Periph_GPIOB             ((uint32_t)0x00000008)
  26. #define RCC_APB2Periph_GPIOC             ((uint32_t)0x00000010)
  27. #define RCC_APB2Periph_GPIOD             ((uint32_t)0x00000020)

  28. /************ GPIOD <*************/
  29. typedef struct
  30. {
  31.   __IO uint32_t CRL;
  32.   __IO uint32_t CRH;
  33.   __IO uint32_t IDR;
  34.   __IO uint32_t ODR;
  35.   __IO uint32_t BSRR;
  36.   __IO uint32_t BRR;
  37.   __IO uint32_t LCKR;
  38. } GPIO_TypeDef;

  39. typedef struct
  40. {
  41.   __IO uint32_t CR;
  42.   __IO uint32_t CFGR;
  43.   __IO uint32_t CIR;
  44.   __IO uint32_t APB2RSTR;
  45.   __IO uint32_t APB1RSTR;
  46.   __IO uint32_t AHBENR;
  47.   __IO uint32_t APB2ENR;
  48.   __IO uint32_t APB1ENR;
  49.   __IO uint32_t BDCR;
  50.   __IO uint32_t CSR;
  51. } RCC_TypeDef;

  52. /********* GPIOD管腳的內存對應地址 *******/
  53. #define PERIPH_BASE           ((uint32_t)0x40000000)
  54. #define APB2PERIPH_BASE       (PERIPH_BASE + 0x10000)
  55. #define GPIOD_BASE            (APB2PERIPH_BASE + 0x1400)
  56. #define GPIOD               ((GPIO_TypeDef *) GPIOD_BASE)

  57. /************ RCC時鐘 <*************/
  58. #define AHBPERIPH_BASE        (PERIPH_BASE + 0x20000)
  59. #define RCC_BASE              (AHBPERIPH_BASE + 0x1000)
  60. #define RCC                 ((RCC_TypeDef *) RCC_BASE)


  61. void Delay(vu32 nCount);

  62. int main(void)         //main是程序入口
  63. {
  64.           /* 使能APB2總線的時鐘,對GPIO的端口D時鐘使能 */
  65.           RCC->APB2ENR |= RCC_APB2Periph_GPIOD;        

  66.         /*-- GPIO Mode Configuration速度,輸入或輸出 -----------------------*/
  67.         /*-- GPIO CRL Configuration 設置IO端口低8位的模式(輸入還是輸出)---*/
  68.         /*-- GPIO CRH Configuration 設置IO端口高8位的模式(輸入還是輸出)---*/
  69.         GPIOD->CRH &=  0xFFFFFF00;    //清除對位8位9的配置
  70.         GPIOD->CRH |=  0x00000033;         /* 設置GPIOD的PD8和PD9配置為通用推挽模式輸出50MHZ(PD.8和PD.9的推挽輸出)*/

  71.           while (1)
  72.           {        
  73.                         /* 對BSRR設置為1,則GPIO輸出為1 */
  74.                 GPIOD->BSRR = GPIO_Pin_8;
  75.             GPIOD->BSRR = GPIO_Pin_9;
  76.                 Delay(0x2FFFFF);
  77.                         
  78.                         
  79.           /* 對BRR設置為1,則GPIO輸出為0 */
  80.                   GPIOD->BRR = GPIO_Pin_8;
  81.                 GPIOD->BRR = GPIO_Pin_9;
  82.                 Delay(0x2FFFFF);
  83.         

  84.           }
  85. }

  86. void Delay(vu32 nCount)                 //通過不斷for循環nCount次,達到延時的目的口
  87. {
  88.   for(; nCount != 0; nCount--);
  89. }
復制代碼


完整代碼下載:
LED雙燈閃爍實驗(STM32-寄存器版).7z (12.36 KB, 下載次數: 9)

評分

參與人數 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

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

使用道具 舉報

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

本版積分規則

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

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 天天激情综合 | 欧美日韩久久精品 | 婷婷久久综合 | 二区在线观看 | 91色视频在线观看 | 青青青伊人 | 久久久成人一区二区免费影院 | 好好的日在线视频 | 欧美激情精品久久久久久 | 精品成人免费视频 | 看真人视频一级毛片 | 九九综合| 日韩欧美中文字幕在线视频 | 国产精品毛片一区二区三区 | 97色在线观看免费视频 | 国产成人精品一区二区三区视频 | 国产成人午夜高潮毛片 | 亚洲视频在线看 | 成人三级在线观看 | 国产一区二区精品自拍 | 天天射色综合 | 三级国产三级在线 | 99热在线观看精品 | 亚洲网站在线观看 | 久久精品美女 | 成人三区四区 | 久久精品小视频 | 天天天插 | 日韩一区二区三区在线视频 | 久久久久久中文字幕 | 青青草一区二区三区 | 日韩毛片在线视频 | 久久精品一区 | 国产一区二区 | 国产精品视频免费观看 | 亚洲一在线 | 欧美成人精品欧美一级 | 操操操av| 一级做a爰片性色毛片 | 国产成人精品一区二区三区 | 国产精品波多野结衣 |