在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<menu id="6qfwx"><li id="6qfwx"></li></menu>
    1. <menu id="6qfwx"><dl id="6qfwx"></dl></menu>

      <label id="6qfwx"><ol id="6qfwx"></ol></label><menu id="6qfwx"></menu><object id="6qfwx"><strike id="6qfwx"><noscript id="6qfwx"></noscript></strike></object>
        1. <center id="6qfwx"><dl id="6qfwx"></dl></center>

            新聞中心

            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)題,或在硬件上增加延遲,或是增加軟件延遲查詢的功能模塊。這里,我們考慮這樣一個(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.biyoush.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ù)專區(qū)

            關(guān)閉