{"id":65,"date":"2012-02-29T14:47:23","date_gmt":"2012-02-29T14:47:23","guid":{"rendered":"http:\/\/www.electronic-products-development.com\/?p=65"},"modified":"2022-02-18T15:37:50","modified_gmt":"2022-02-18T15:37:50","slug":"debounce-switches","status":"publish","type":"post","link":"https:\/\/ibex.tech\/embedded\/microchip\/mplab\/assembler\/debounce-switches","title":{"rendered":"Debounce Switches"},"content":{"rendered":"<h4>Simple Debounce Only<\/h4>\n<pre><code>\r\n;debounce the switches\r\n\tmovf sw_inputs_0,w\r\n\tandwf sw_inputs_0_last,w\r\n\tmovwf switches_debounced_0\r\n\tmovf sw_inputs_0,w\r\n\tmovwf sw_inputs_0_last\r\n<\/code><\/pre>\n<h4>Detect New Keypresses Too<\/h4>\n<pre><code>\r\n;----- DEBOUNCED SWITCHES -----\r\n#define\tSW_LCD_BRIGHTNESS_UP_PRESSED\tb0_switches_debounced_0,0\r\n#define\tSW_LCD_BRIGHTNESS_DOWN_PRESSED\tb0_switches_debounced_0,1\r\n\r\n;----- NEW KEYPRESSES -----\r\n#define\tSW_LCD_BRIGHTNESS_UP_NEW\tb0_switches_new_0,0\r\n#define\tSW_LCD_BRIGHTNESS_DOWN_NEW\tb0_switches_new_0,1\r\n\r\n\r\n\r\n\r\n;***********************************\r\n;***********************************\r\n;********** READ SWITCHES **********\r\n;***********************************\r\n;***********************************\r\nread_switches\r\n\tclrf\tb0_switches_new_0\r\n\t\r\n\tbtfss\tb0_do_sw_read\t\t\t;Set by heartbeat timer every 10mS\r\n\treturn\r\n\tbcf\tb0_do_sw_read\r\n\r\n;Get switch input states\r\n\tclrf\tb0_temp\r\n\tbtfss\tporta,3\r\n\tbsf\tb0_temp,0\r\n\tbtfss\tporta,4\r\n\tbsf\tb0_temp,1\r\n;Debounce\r\n\tmovf\tb0_temp,w\r\n\tandwf\tb0_sw_inputs_0_last,w\r\n\tmovwf\tb0_switches_debounced_0\r\n;Flag new button presses\r\n\txorwf\tb0_switches_debounced_last_0,w\r\n\tandwf\tb0_switches_debounced_0,w\r\n\tmovwf\tb0_switches_new_0\r\n;Store last registers\r\n\tmovf\tb0_switches_debounced_0,w\r\n\tmovwf\tb0_switches_debounced_last_0\r\n\tmovf\tb0_temp,w\r\n\tmovwf\tb0_sw_inputs_0_last\r\n\r\n\treturn\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Simple Debounce Only ;debounce the switches movf sw_inputs_0,w andwf sw_inputs_0_last,w movwf switches_debounced_0 movf sw_inputs_0,w movwf sw_inputs_0_last Detect New Keypresses Too ;&#8212;&#8211; DEBOUNCED SWITCHES &#8212;&#8211; #define SW_LCD_BRIGHTNESS_UP_PRESSED b0_switches_debounced_0,0 #define SW_LCD_BRIGHTNESS_DOWN_PRESSED b0_switches_debounced_0,1 ;&#8212;&#8211; NEW KEYPRESSES &#8212;&#8211; #define SW_LCD_BRIGHTNESS_UP_NEW b0_switches_new_0,0 #define SW_LCD_BRIGHTNESS_DOWN_NEW b0_switches_new_0,1 ;*********************************** ;*********************************** ;********** READ SWITCHES ********** ;*********************************** ;*********************************** read_switches clrf b0_switches_new_0 btfss b0_do_sw_read ;Set by [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[],"class_list":["post-65","post","type-post","status-publish","format-standard","hentry","category-assembler"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/posts\/65","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/comments?post=65"}],"version-history":[{"count":17,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/posts\/65\/revisions"}],"predecessor-version":[{"id":558,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/posts\/65\/revisions\/558"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/media?parent=65"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/categories?post=65"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/tags?post=65"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}