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.

3x4 Keypad Bug

Status
Not open for further replies.

birdman0_o

Active Member
Hey guys I'm using a 3x4 keypad and a PIC16f628A. As well I'm using PORTB interrupt to tell when a key has been pressed. The problem is One of the Rows (The pins I'm toggeling) is more sensitive then the rest. The columns are all fine (The portB interrupts). Furthermore, The two other rows when I press and hold down on the button one number stays displayed until I press it again. With the sensative one it is the equivalent of holding down a key on the keyboard.

I appreciate any help! Here is my code:

Code:
;*************************************
; Author  : Mike Baird
; Program : 3x4 Keypad
; Date    : September 7th, 2009
;*************************************

	List	P=16F628a
	#include	"P16F628a.INC"
	__config	_PWRTE_ON  & _WDT_OFF & _INTRC_OSC_NOCLKOUT & _BODEN_ON & _LVP_OFF & _CP_OFF & _MCLRE_OFF

;*** Cblock ***

	CBLOCK	0x20		 
	d1									; 
	d2									;
	Number1								;
	Number2								;
	Number3								;
	Number4								;
	Numb1								;
	Numb2								;
	Numb3								;
	Numb4								;
	W_TEMP								;
	STATUS_TEMP							;
	X									;
	Y									;
	ENDC

;*** Defines ***

#Define 	Bits 		PORTA,0
#Define 	Clock		PORTA,7
#Define 	Latch		PORTA,6
#Define 	MinLow		PORTA,3
#Define 	MinHigh		PORTA,2
#Define		HourLow		PORTA,1
#Define 	HourHigh	PORTB,3

;*** Macro ***

HC595 MACRO Var,Var1

	Local 	Loop						; Local Label
	MOVLW 	.8							; Transfer 8 bits
  	MOVWF 	Var1						; Initializing counter

Loop	
	RLF 	Var,f						; Rotate "Var" one place to the left
	BTFSS 	STATUS,C					; Is carry 1?
	BCF 	Bits						; If not set data line to 0
	BTFSC 	STATUS,C					; Is carry 0?
	BSF 	Bits						; If not set data line to 1

	BSF 	Clock						; Generate one clock
	BCF 	Clock						;

	DECFSZ 	Var1,f						; Has 8 bits been sent?
	GOTO 	Loop						; If not, repeat

	BSF 	Latch						; If all 8 bits have been sent, set latch
	BCF 	Latch

	RLF		Var,f						; Reset orginal variable 
	ENDM

;*** START OF RAM ***
	ORG	0x000							; Start of program vector
	GOTO	Start						;
	ORG	0x004							; Interrupt vector

;*** ISR ***

ISR:
	MOVWF W_TEMP						; 	
	SWAPF STATUS,W   					; Context Saving
	MOVWF STATUS_TEMP					;
	BCF INTCON,RBIF						; RB Port Change Interrupt Flag bit
	BCF INTCON,GIE
	BCF	INTCON,RBIE
;*** Code Insert ***
	
Col1	
	BTFSC 	PORTB,2						;
	GOTO 	Col2						;
	BTFSS	PORTB,4						;
	MOVLW	d'2'						;
	BTFSS	PORTB,4						;
	MOVWF	X							;
	BTFSS	PORTB,5						;
	MOVLW	d'5'						;
	BTFSS	PORTB,5						;
	MOVWF	X							;
	BTFSS	PORTB,6						;
	MOVLW	d'8'						;
	BTFSS	PORTB,6						;
	MOVWF	X							;
	BTFSS	PORTB,7						;
	MOVLW	d'11'						;
	BTFSS	PORTB,7						;
	MOVWF	X							;
	
Col2
	BTFSC 	PORTB,1						;
	GOTO 	Col3						;
	BTFSS	PORTB,4						;
	MOVLW	d'3'						;
	BTFSS	PORTB,4						;
	MOVWF	X							;
	BTFSS	PORTB,5						;
	MOVLW	d'6'						;
	BTFSS	PORTB,5						;
	MOVWF	X							;
	BTFSS	PORTB,6						;
	MOVLW	d'9'						;
	BTFSS	PORTB,6						;
	MOVWF	X							;
	BTFSS	PORTB,7						;
	MOVLW	d'1'						;
	BTFSS	PORTB,7						;
	MOVWF	X							;

Col3
	BTFSC 	PORTB,0						;
	GOTO 	XTest						;
	BTFSS	PORTB,4						;	
	MOVLW	d'4'						;
	BTFSS	PORTB,4						;
	MOVWF	X							;
	BTFSS	PORTB,5						;
	MOVLW	d'7'						;
	BTFSS	PORTB,5						;
	MOVWF	X							;
	BTFSS	PORTB,6						;
	MOVLW	d'10'						;
	BTFSS	PORTB,6						;
	MOVWF	X							;
	BTFSS	PORTB,7						;
	GOTO	XTestReset					;

XTest

	MOVF	Number4,W					;
	XORLW	0x0							;
	BTFSS	STATUS,Z					;
	Goto	XTestb						;
	MOVF	X,W							;
	MOVWF	Number4						;
	Goto 	Exit						;
XTestb
	MOVF	Number3,W					;
	XORLW	0x0							;
	BTFSS	STATUS,Z					;
	Goto	XTestc						;
	MOVF	X,W							;
	MOVWF	Number3						;
	Goto	Exit						;
XTestc
	MOVF	Number2,W					;
	XORLW	0x0							;
	BTFSS	STATUS,Z					;
	Goto	XTestd						;
	MOVF	X,W							;
	MOVWF	Number2						;
	Goto	Exit						;
XTestd
	MOVF	Number1,W					;
	XORLW	0x0							;
	BTFSS	STATUS,Z					;
	Goto	Exit						;
	MOVF	X,W							;
	MOVWF	Number1						;
	Goto	Exit						;

XTestReset
	CLRF	Number1						;
	CLRF	Number2						;
	CLRF	Number3						;
	CLRF	Number4						;

;*** End of Insert ***

Exit:
	CLRF	Y							;
	BSF		INTCON,GIE

	SWAPF 	STATUS_TEMP,W				; Restore Status and W	
	MOVWF 	STATUS						;
	SWAPF 	W_TEMP,F					;
	SWAPF 	W_TEMP,W					;

	RETFIE								


;*** Configuration ***

Start
	MOVLW	0x07						; Turn comparators off and enable pins for I/O
	MOVWF	CMCON						; ^
	CLRF	PORTA						; PortA all low
	CLRF	PORTB						; PortB all low
	
	BSF		STATUS,RP0					; Bank 1
	MOVLW	b'00100000'					;
	MOVWF	TRISA						; PortA all output except MCLR
	MOVLW 	0xF0						; Half input half output (for interrupt on change)
	MOVWF	TRISB						; Move to PortB
	BCF		STATUS,RP0					; Bank 0

;*** RB Pin Change Interrupt Set Up ***

	BSF 	INTCON,RBIE					; RB Port Change Interrupt Enable bit	
	BSF 	INTCON,PEIE					; Peripheral Interrupt Enable bit
	BSF 	INTCON,GIE					; Global Interrupt Enable bit


	MOVLW	d'11'						;
	MOVWF	Number1
	MOVLW	d'11'
	MOVWF	Number2
	MOVLW	d'11'
	MOVWF	Number3
	MOVLW	d'11'
	MOVWF	Number4

	MOVLW	0x0F
	MOVWF	PORTB
	CLRF	Y

Main:
	
	INCF	Y,F

	MOVF	Y,W
	XORLW	0x03
	BTFSC	STATUS,Z
	BSF		INTCON,RBIE			; Enable Interrupts

	Call 	TurnOffNumbers
	MOVF	Number1,W
	Call 	Table
	MOVWF	Numb1
	HC595 	Numb1,X
	BSF		MinLow	
	Call 	Delay

	BSF		PORTB,2
	BCF		PORTB,0

	Call 	TurnOffNumbers
	MOVF	Number2,W
	Call 	Table
	MOVWF	Numb2 
	HC595	Numb2,X
	BSF		MinHigh
	Call	Delay

	BSF		PORTB,0
	BCF		PORTB,1		

	Call 	TurnOffNumbers
 	MOVF	Number3,W
	Call 	Table
	MOVWF	Numb3
	HC595 	Numb3,X
	BSF		HourLow
	Call 	Delay

	BSF		PORTB,1
	BCF		PORTB,2

	Call 	TurnOffNumbers
 	MOVF	Number4,W
	Call 	Table
	MOVWF	Numb4
	HC595 	Numb4,X
	BSF		HourHigh
	Call 	Delay

	GOTO 	Main

TurnOffNumbers:

	BCF 	MinLow
	BCF 	MinHigh
	BCF 	HourLow
	BCF 	HourHigh
	RETURN	

Table:

	ADDWF 	PCL
	RETLW 	b'00000000' 				; Clear
	RETLW 	b'00111111' 				; 0
	RETLW 	b'00000110' 				; 1 
	RETLW 	b'01011011' 				; 2
	RETLW 	b'01001111' 				; 3 
	RETLW 	b'01100110' 				; 4
	RETLW 	b'01101101' 				; 5
	RETLW 	b'01111101' 				; 6		
	RETLW 	b'00000111' 				; 7
	RETLW 	b'01111111' 				; 8
	RETLW 	b'01101111' 				; 9 
	RETLW 	b'01000000' 				; Dash
	RETLW	b'01110111'					; A	

; *** Delay ***
Delay:	
	MOVLW	d'8'
	MOVWF	d2
D2:	
	DECFSZ	d1,F
	GOTO	D2
	DECFSZ	d2,F
	GOTO	D2
	RETURN

;***

	END

;********************************
; Table
;		    					    (f) Left Top = bit5
;		    __   (a) Top    = bit0 	(b) Righ Top = bit1   
;		   |__|  (g) Middle = bit6  (e) Left Bot = bit4
;		   |__|  (d) Bottom = bit3	(c) Righ Bot = bit2
;
;  = b'00000000'
;0 = b'00111111'
;1 = b'00000110'
;2 = b'01011011'
;3 = b'01001111'
;4 = b'01100110'  
;5 = b'01101101'  
;6 = b'01111101'  			
;7 = b'00001111'  
;8 = b'01111111'  
;9 = b'01101111'  
;
; That's all folks!
;*********************************
 

be80be

Well-Known Member
Bird is your programmer still hooked up to RB6 and RB7 if I leave my pickit2 hooked up it makes the key that uses RB6 and 7 not work right
 
Last edited:

be80be

Well-Known Member
Ok what is RB6 and RB7 for if you use a keypad on port B it will mess up one key making it look like it is repeating I work for weeks with a keypad on portb It didn't work till I built my code for release and then I had to unhook the programmer to.
 
Last edited:
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top