1. <th id="uou7b"></th>
        2. <tbody id="uou7b"></tbody>
          <tbody id="uou7b"></tbody>
        3. <span id="uou7b"></span>

          <tbody id="uou7b"></tbody>
          <em id="uou7b"></em>

          專注電子技術學習與研究
          當前位置:單片機教程網 >> STM32 >> 瀏覽文章

          關于STM32庫中 __IO 修飾符(volatile修飾符)

          作者:明浩   來源:磁動力論壇   點擊數:  更新時間:2014年05月19日   【字體:

            STM32例子代碼中會有像這樣的代碼 static __IO uint32_t TimingDelay;  這里邊的__IO修飾符不好理解,單從字面可以看出是為IO相關,查其標準庫可以得知這個__IO原來是在Core_cm3.h中被重定義,其實就是volatile,句子如下

          /* IO definitions (access restrictions to peripheral registers) */
          #ifdef __cplusplus
            #define   __I     volatile             /*!< defines 'read only' permissions                 */
          #else
            #define   __I     volatile const       /*!< defines 'read only' permissions                 */
          #endif
          #define     __O     volatile             /*!< defines 'write only' permissions                */
          #define     __IO    volatile             /*!< defines 'read / write' permissions              */ 
           
          不難看出這些修飾管是用于指示編譯器在編譯時如何對變量進行操作。volatile 的作用就是指示編譯器不要因優化而省略此指令,必須每次都直接讀寫其值。
          寫一段測試代碼如下
            u8 test;
           
            test = 1;
            test = 2;
            test = 3;
          設置優化級別中級
          運行后test會被直接取值為3 只有最后一個語句被編譯
          如用volatile
            volatile u8 test;
           
            test = 1;
            test = 2;
            test = 3;
          則所有語句都會被編譯。test先后被設置成1、2、3
          由此可以看出這個作用在IO操作,寄存器操作,特殊變量,多線程變量讀寫都是很重要。
          關閉窗口

          相關文章

          日日噜噜夜夜狠狠久久无码区

              1. <th id="uou7b"></th>
              2. <tbody id="uou7b"></tbody>
                <tbody id="uou7b"></tbody>
              3. <span id="uou7b"></span>

                <tbody id="uou7b"></tbody>
                <em id="uou7b"></em>