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

          新聞中心

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

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

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




          評(píng)論


          技術(shù)專(zhuān)區(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); })();