<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 按鍵開關(guān)消抖程序

          按鍵開關(guān)消抖程序

          作者: 時間:2016-11-25 來源:網(wǎng)絡(luò) 收藏
          實踐中,單片機端口在連接開關(guān)器件時都要考慮消抖的問題,或在硬件上增加延遲,或是增加軟件延遲查詢的功能模塊。這里,我們考慮這樣一個檢測電路:單片機連接一個開關(guān)和兩個LED。程序是這樣的,如果開關(guān)的消抖正確,就點亮LED1,否則就閃亮LED2。按下開關(guān),點亮LED1,釋放開關(guān),LED1即熄滅。我們加入20毫秒的消抖延遲時間。當檢測到開關(guān)為低電平時,單片機在延遲20毫秒后再次檢測開關(guān)的狀態(tài)。如果此時開關(guān)狀態(tài)為高,則LED2就閃亮,如為低則點亮LED1。

          源代碼:

          本文引用地址:http://www.ex-cimer.com/article/201611/321250.htm

          led1bitP2.0
          led2bitP2.1
          switch1bitP1.0
          ORG 0000h
          setb switch1//initialize switch 1 as input
          setb led1//Turn OFF LED1
          setb led2//Turn OFF LED2

          wait:
          jb switch1,wait// Wait till switch1 has been pressed
          call debounce_delay
          jb switch1,c1_wait
          //switch low even after debouncing period
          //switch has been succesfully debounced
          clr led1//Turn ON LED1
          jnb switch1,$//wait till switch has been released
          setb led1//Turn OFF LED1
          ajmp wait

          c1_wait:
          //Switch PIN high after debounce period so error in debouncing
          cpl led2
          ajmp wait

          debounce_delay://Subroutine for generating 20ms delay
          mov r7,#245
          l1_debounce_delay:
          mov r6,#40
          djnz r6,$
          djnz r7,l1_debounce_delay
          ret

          END




          關(guān)鍵詞: 按鍵開關(guān)消抖程

          評論


          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();