Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 26th July 2007, 07:50 AM   (permalink)
Default Keypad Routine

Mr Goodwin, I was checking your keypad routine in your tutorials. Could you explain the following subroutine.

call Scan_Keys
movlw 0x10 ;check for no key pressed
subwf key, w
btfss STATUS, Z
goto Key_Found
call Delay20
goto Keys
__________________
People perish because of lack of knowledge
emufambirwi is offline   Reply With Quote
Old 26th July 2007, 05:40 PM   (permalink)
Default

Pretty self explanitory really?, the first line scans the keypad, and the next two check if any pressed key was found. If one was, then it jumps to Key_Found to process the key, otherwise it loops back round.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline   Reply With Quote
Old 27th July 2007, 06:36 AM   (permalink)
Default

Quote:
Originally Posted by emufambirwi

movlw 0x10 ;check for no key pressed
goto Keys
Why in particular movlw 0x10 and not movlw 0x00 because I thought that this would ensure we test all the keys
__________________
People perish because of lack of knowledge
emufambirwi is offline   Reply With Quote
Old 27th July 2007, 06:42 AM   (permalink)
Default

Quote:
Originally Posted by emufambirwi
Why in particular movlw 0x10 and not movlw 0x00 because I thought that this would ensure we test all the keys
Because the routine 'walks' a bit along the rows (or columns), and it only gets to that point if no key was pressed.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline   Reply With Quote
Old 27th July 2007, 08:16 AM   (permalink)
Default

Quote:
Originally Posted by Nigel Goodwin
Because the routine 'walks' a bit along the rows (or columns), and it only gets to that point if no key was pressed.
Code:
Keys    call       Scan_Keys 
              movlw   0x10         	;check for no key pressed 
              subwf   key, w 
              btfss    STATUS, Z 
              goto     Key_Found 
              call   	Delay20 
              goto   	Keys
I understand that we are comparing the contents of 'key' with binary '00010000'.
Does this then mean that for 'no key pressed', in 'key' there should be 0x10 or 00010000
__________________
People perish because of lack of knowledge
emufambirwi is offline   Reply With Quote
Old 27th July 2007, 08:45 AM   (permalink)
Default

Quote:
Originally Posted by emufambirwi
Code:
Keys    call       Scan_Keys 
              movlw   0x10         	;check for no key pressed 
              subwf   key, w 
              btfss    STATUS, Z 
              goto     Key_Found 
              call   	Delay20 
              goto   	Keys
I understand that we are comparing the contents of 'key' with binary '00010000'.
Does this then mean that for 'no key pressed', in 'key' there should be 0x10 or 00010000
Yes, that's right - any other result means there's a key pressed.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline   Reply With Quote
Old 27th July 2007, 12:53 PM   (permalink)
Default

Would you explain what happens in terms of voltage levels when I press say key '1' and scan that row? In my case, which I suppose is similar to yours, the columns are tied to Vcc through resistors, and I scan the rows. Initially, the rows are all high
__________________
People perish because of lack of knowledge
emufambirwi is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
Keypad Code gregmcc Micro Controllers 5 11th May 2006 08:01 AM
keypad encoder Mel_noypi Datasheet/Parts Requests 5 22nd February 2006 02:01 PM
16f628 keypad interface scarab Micro Controllers 2 21st April 2004 05:15 AM
PicBasic Keypad program Sora Micro Controllers 0 20th April 2004 07:01 PM
pic keypad nevada Electronic Projects Design/Ideas/Reviews 2 25th November 2003 03:45 PM



All times are GMT. The time now is 01:16 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.