by Bob Axtell of
http://www.platinumtechnical.com
;********************************************************; ; Code snippet for reading 7 switches on a single PIN ; Routine assumes that ADCON0 and ADCON1 are set to ; appropriate values for the PIC used. ; The routine tests 8bit ADC value against the voltage ; level presented. If it is LOWER than the test then ; that switch is grounded. NOTE: This can be minimized ; further. NOTE: this should be executed during an ; interrupt to make sure that the snippet is not missed. ;********************************************************; ;process keyboard: inside ints only keybd: clrf status rrf adresh,w movwf tmp1_ bank1 rrf adresl,w clrf status movwf tmp_ rrf tmp1_,f rrf tmp_,f ;now fixed to 8 bits, NOT 10 bits clrf tmp1_ ;used to locate switch number incf tmp1_,f ;=SW1 movlw -d'18' ; 0.0V + 0.7V/2 = 0.35V Test limit addwf tmp_,w ;OK Pressed? btfss status,c ;check if LESS goto keybd0 ;jump if OK SW pressed incf tmp1_,f movlw -d'54' ; 0.7V + 0.35V = 1.05V addwf tmp_,w ;DN Pressed? btfss status,c ;check if LESS goto keybd0 ;jump if DN SW pressed incf tmp1_,f movlw -d'90' ; 1.4v + 0.35V = 1.75V addwf tmp_,w ;<< Pressed? btfss status,c ;check if LESS goto keybd0 ;jump if << SW pressed incf tmp1_,f movlw -d'125' ; 2.1V + 0.35V = 2.45V addwf tmp_,w ;< pressed? btfss status,c ;check if LESS goto keybd0 ;jump if < SW pressed incf tmp1_,f movlw -d'161' ;2.8V + 0.35V = 3.15V addwf tmp_,w ;> pressed? btfss status,c ;check if LESS goto keybd0 ;jump if > SW pressed incf tmp1_,f movlw -d'197' ;3.5V + 0.35V = 3.85V addwf AN0,w ;>> pressed? btfss status,c ;check if LESS goto keybd0 ;jump if >> SW pressed incf tmp1_,f movlw -d'233' ;4.2V + 0.35V = 4.55V addwf AN0,w ;UP pressed? btfsc status,c ;check if LESS ; no switches are pressed, so done goto keybd1 ; now process the switches keybd0: incf tmp1_,w movwf KEY ;value will read 1 to 7 for appropriate SW bsf flags,KYPRESS ;tell system it is time to service keypress keybd1: bsf adcon0,GO ;read for next time return ;********************************************************; ; end of snippet ;********************************************************;
file: /Techref/microchip/sw7_on_1pin.htm, 2KB, , updated: 2012/1/31 23:21, local time: 2024/8/14 15:32,
18.119.102.55:LOG IN
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://piclist.com/techref/microchip/sw7_on_1pin.htm"> PIC Microcontroler based Keyboards: 7 switches with 1 A/D pin by Bob Axtell</A> |
Did you find what you needed? |
![]() o List host: MIT, Site host massmind.org, Top posters @none found - Page Editors: James Newton, David Cary, and YOU! * Roman Black of Black Robotics donates from sales of Linistep stepper controller kits. * Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters. * Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated! * Contributors: Richard Seriani, Sr. |
Ashley Roll has put together a really nice little unit here. Leave off the MAX232 and keep these handy for the few times you need true RS232! |
.