Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Keypad Routine

Status
Not open for further replies.
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
 
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.
 
emufambirwi said:

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
 
emufambirwi said:
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.
 
Nigel Goodwin said:
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
 
emufambirwi said:
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.
 
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
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top