Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

I have a problem with the keypad 4*4

Status
Not open for further replies.

didyi

Newbie level 4
Joined
Apr 30, 2016
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
64
I have a little problem with the keyboard 16 keys
I have a model where it's planted a pic 16f690 a 16 * 4 LCD and keyboard (keypad) 4 * 4
I wrote a script that displays on the LCD any texts
now I want to use the keyboard to display by exemple '1' if I press it shows 1 on the lcd ..ect
so for now I have not really started this script
I just tried to find the logic to do it
I know that the keypad is a 4 * 4 matrix
I put the bits associated with the input lines
and those of the columns as outputs
I have the Keypad is linked with the port C
I did
main
...
bsf PORTC, 0
btfsc PORTC, 4
call LWD_Write1
goto hand
this script is just to test if what i want to do is going to work or no,
if any one of you have ideas or scripts that can help me I will be grateful
Have a nice week end
 

Hi,

I put the bits associated with the input lines
and those of the columns as outputs
Enable the pullups at the inputs.
Then set all outputs to high impedance
Set one output low, wait a bit, then read the inputs.
Then set the next output low and all other outputs to high impedance.
Wait. Read....and so on.

Every pressed button will result in a low.

Only one button may be pressed.

Klaus
 
  • Like
Reactions: didyi

    didyi

    Points: 2
    Helpful Answer Positive Rating
Hello

HTML:
	bsf STATUS,RP0 				;bank 1
		bcf STATUS,RP1
		bcf OPTION_REG,7	; Enable the pull up
		bsf		STATUS,RP0	
		bsf		STATUS,RP1	; Selection bank 3
		movlw	0xF0			;configuration du port			
		movwf	TRISC	
		bcf	STATUS,RP0
		movlw	0xF0			; 
		movwf	PORTC
		
		bcf PORTC,Col1
		call Wait5us
		btfsc	PORTC,Lin1
		call Ecrire

This is what i did

HTML:
Lin1	EQU	0
Lin2	EQU	1
Col1	EQU	4
Col2	EQU	5
Col3	EQU	6
Col4	EQU	7	
Lin3	EQU	3
Lin4	EQU	2


and i made those subroutines
Ecrire
HTML:
		movlw '*'
		call LCD_Write
                return
Wait5us
HTML:
nop
		nop
		nop
		return


i did that just to test before doing the code to scan all the keypad
Thank you
 

Keypad 4*4 pic16f690

Hi everyone
i wrote a script to scan a keypad normaly it woorks
i only have one probleme is for exemple if i press 1 it appears a lot of 1's it depends about how much i let my finger on the button.
i wanted to enable the pull ups i found that on OPTION_REG but it only enables the pull up for the portB and A but my keypad is attatched with the port C
so if any one of you have an idea about how i'm going to fix that i'll be greatful.
its a week now that i'm trying to fix it.
this the code that i wrote
Code:
#include p16f690.inc
#include Adressage.inc

		extern	LCD_CLEAR,INITLCD,LCD_Position,LCD_Write,Cycle_Write,Conv_ASCII,LCD_Position

	org 0x00
			CMP		equ		0x34
			call		INIT
			call		INITLCD			
		
			call			LCD_CLEAR
			movlw		0x00
			call			LCD_Position



		

		bsf STATUS,RP0 				;bank 1
		bcf STATUS,RP1
		;bcf OPTION_REG,7	; Enable the pull up
		;bcf		STATUS,RP0 ; en mettant les pin en entrée analogique active le pull up
		;movlw	0xFF
		;movwf	ANSEL
		bsf		STATUS,RP0	
		bsf		STATUS,RP1	; Selection bank 3
		movlw	0xF0			;configuration du port			
		movwf	TRISC	
		bcf	STATUS,RP0

debut
	

		movlw	0xFF			; 
		movwf	PORTC
		call	Wait2s
		
	
		bcf PORTC,Lin1			;
		call Wait2s
		goto test_cols
Ligne2
		bsf PORTC,Lin1
		bcf PORTC,Lin2
		call Wait2s
		goto test_cols2
Ligne3
		bsf PORTC,Lin2
		bcf PORTC,Lin3
		call Wait2s
		goto test_cols3
Ligne4
		bsf PORTC,Lin3
		bcf PORTC,Lin4
		call Wait2s
		goto test_cols4
tout_à_1
		bsf  PORTC,Lin4
		goto debut



Ecrire1
	
	
		
		movlw	'1'
		call	LCD_Write
	
		goto debut
		
		
Ecrire2
		
		movlw	'2'
		call LCD_Write
		
		
		goto debut
Ecrire3
		movlw	'3'
		call LCD_Write
		goto debut

Ecrire4
		movlw	'4'
		call	LCD_Write
		goto debut
		
Ecrire5
		movlw	'5'
		call LCD_Write
		goto debut
Ecrire6
		movlw	'6'
		call LCD_Write
		goto debut
Ecrire7
		movlw	'7'
		call	LCD_Write
		goto debut
		
Ecrire8
		movlw	'8'
		call LCD_Write
		goto debut
Ecrire9
		movlw	'9'
		call LCD_Write
		goto debut

Ecrire0
		movlw '0'
		call LCD_Write
		goto debut
dep_cur_droit
		addlw	0x02
		call	LCD_Position
		goto debut

dep_cur_gauche
		sublw	0x01
		call	LCD_Position
		goto debut
dep_cur_haut
		addlw	0x40
		call	LCD_Position
		goto debut
dep_cur_bas
		sublw	0x40
		call	LCD_Position
		goto debut
		

		
		

test_cols
		btfss PORTC,Col1
		goto	Ecrire1
		;btfss	PORTC,Col2
		;goto	Ecrire2
		btfss	PORTC,Col4
		goto	dep_cur_droit
		btfss	PORTC,Col3
		goto	Ecrire3
		btfsc	PORTC,Col3
		goto	Ligne2


test_cols2

		btfss PORTC,Col1
		goto	Ecrire4
		;btfss	PORTC,Col2
		;goto	Ecrire5
		btfss	PORTC,Col4
		goto	dep_cur_gauche

		btfss	PORTC,Col3
		goto	Ecrire6
		btfsc	PORTC,Col3
		goto	Ligne3

test_cols3
		btfss PORTC,Col1
		goto	Ecrire7
		;btfss	PORTC,Col2
		;goto	Ecrire8
		btfss	PORTC,Col4
		goto	dep_cur_haut
		btfss	PORTC,Col3
		goto	Ecrire9
		btfsc	PORTC,Col3
		goto	Ligne4


test_cols4
		;btfss	PORTC,Col2
		;call	Ecrire0
		;btfsc	PORTC,Col2
		btfss	PORTC,Col4
		goto	dep_cur_bas
		goto	tout_à_1



	
		
		
	


		
		
		
		
		
			


	


Fin
			goto	Fin

; ------------------------ INIT


INIT
		bcf		STATUS,RP0
		bcf		STATUS,RP1	; Selection bank 
		
		clrf    	PORTA			; init PORTA
		clrf		PORTB			; Init PORTB
		clrf		PORTC			; Init PORTC


		
		bsf		STATUS,RP0	
		bsf		STATUS,RP1	; Selection bank 3

		movlw	0x00			;Parametrage PORTA
		movwf	TRISA
		movlw	0x00			; Parametrage PORTB	0x_0
		movwf 	TRISB
		movlw	0xF0			; Parametrage PORTC 0xF_
		movwf	TRISC
		bcf		STATUS,RP0	; Bank 2
		
		clrf		ANSEL
		clrf		ANSELH

		bcf		STATUS,RP1	
		
		return
Ecrire
		movlw '*'
		call LCD_Write
		movlw 0x43
		call LCD_Write
		return

Wait2s	
		movlw	0xFF
		movwf	CMP

		
loop	nop	
		nop
		nop
		nop
		nop					;1u
		decfsz	CMP,1		;1us  2 si CMP=0
		goto loop			;3us
		
		return





		


	end
 

Hi,

i only have one probleme is for exemple if i press 1 it appears a lot of 1's it depends about how much i let my finger on the button.
This is quite expectable. You run a loop.. and every time it scans the keys.. it detects the key "1" pressed .. and outputs the "1" to the display.


***
With the pullups I can´t help you, because I don´t know details about the PICs.

Klaus
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top