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.

PIC16f977 Keypad and Constants

Status
Not open for further replies.

Olshansk

New Member
I have two relatively short questions, so this is a two parter thread.

Part one:

Assuming I have this code at the top of my program:
Code:
Code_Char_One    	equ  	B'00000011'    ;code for keypad A 
        udata
Code_Sum		res	1

Is there any reason why this code gives me something weird:
Code:
movf		Code_Char_One
movwf		Code_Sum

while this code works as it was intended:
Code:
movlw		B'00001011'
Code_Sum		res	1

Part Two:

I am using a microcontroller board onto which the PIC, LCD, and the Keypad are mounted and internally connected. I found out that:

The*Microcontroller*implements*a*keypad*module*by*using*a*keypad*encoder*chip,*such*as*MM74C922N.*This*chip*translates*the*key pressed*on*the*4x4*keypad*into*a*4*bit*hex*code*which*would*
be*displayed*on*PORTB4‐7.*

That being said, I implement a subroutine to receive a key like this:
Code:
Read_Key 		btfss		PORTB,1     ;Wait until data is available from the keypad
				goto		$-1 
				swapf		PORTB,W     ;Read PortB<7:4> into W<3:0>
				andlw		0x0F
				call		KPHexToChar ;Convert keypad value to LCD character (value is still held in W)
				call		WR_DATA      ;Write the value in W to LCD
				btfsc		PORTB,1      ;Wait until key is released
				goto		$-1

				return

where the KPHexToChar table is the following:
Code:
KPHexToChar	
	addwf     PCL,F
    dt        "123A456B789C*0#D"

As a reference, I have linked the Keypad schematic at the bottom.
My issue is that only the keys in the first row are displayed. When I press the keys 1, 2 3 or A, everything works fine. However, if I press any key which is in the same column as any of the keys I mentioned above, only the respective keys in the first row of that column are displayed on the LCD.

Any help is really appreciated!


https://gyazo.com/df4f2554222fb352236db8c943ea3473
 
Part 1. Yes, in that first one, what you are doing is defining the LOCATION of Code_Char_One (and you also left out the "w" parameter), whereas in the other you are moving a literal into w. Since you aren't putting the literal into Code_Char_One, the movf instruction just loads the uninitialized contents to w.
 
Part 2. Are you using that MM74C922N chip? If so, it sounds like its internal oscillator isn't running. Check that "osc" and "kbm" cap.

If not, you need to do a "row scan". You need to turn on the rows, one at a time, on the keypad.
 
Last edited:
Thanks duffy!

I actually did not know what movf really does. I now understand that it can either be used to set the Z bit of the STATUS register or it can be used to mov the contents of register f into the working register

Also, after you mentioned that the MM74C922N chip needs to use an oscillator, I started looking into it and began understanding how the board I'm using works. It was indeed an oscillator setting that I had to change.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top