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.

PIC keypad (i'm newbie)

Status
Not open for further replies.
11max11 said:
hihi....
i want to do is the second one...but i need to add one more function for it. that is encryption and decryption it because the thing i want to do is key lock like i want to protect it...dun let it hack by someone...:p

thx for reply
hi,
I understand, I used 'encode' to include the 'encryption' OK.

What part of the keyboard/encryption do you need help with??
 
11max11 said:
hihi....
i want to do is the second one...but i need to add one more function for it. that is encryption and decryption it because the thing i want to do is key lock like i want to protect it...dun let it hack by someone...:p

I don't really see your problem? - it's an IR remote, so it's short range and directional, it's not as if anyone can pick it up nearby like a radio remote.

Assuming they are standing in front of you, they could simply record and replicate the encrypted burst anyway - unless it's on a rolling code, which changes everytime you use it.
 
Much better to use an iButton for a lock. Lots and lots of iButton code for PICs on the net. And only 1 wire plus GND.
**broken link removed**
 
hi 11max11,

Have you decided to use an alternate method or are you still asking for help with the 74C922 and encryption?
 
ericgibbs said:
hi 11max11,

Have you decided to use an alternate method or are you still asking for help with the 74C922 and encryption?


hihi...sorry for reply late...
yaya i still want to use the 74C922 for my keypad
 
11max11 said:
hihi...sorry for reply late...
yaya i still want to use the 74C922 for my keypad

hi,
As requested in your PM, zipped files *.bas and *.asm.

I have included the *.bas file for reference, it will help you follow the *.asm..

The asm file is also commented, it does work on my PIC sim OK, with a 74C922keypad sim.

Change the 16 values in the LOOKUP table brackets to suit your encryption.

Any questions, Ask!

EDITED: Replaced the zip, uploaded incorrect files!!:o
Enjoy:)
 
Last edited:
ericgibbs said:
hi,
As requested in your PM, zipped files *.bas and *.asm.

I have included the *.bas file for reference, it will help you follow the *.asm..

The asm file is also commented, it does work on my PIC sim OK, with a 74C922keypad sim.

Change the 16 values in the LOOKUP table brackets to suit your encryption.

Any questions, Ask!
Enjoy:)


hihi...
really really thank a lot for helping me..:eek:
i will try to understand it because my basic no strong yet
 
11max11 said:
hihi...
really really thank a lot for helping me..:eek:
i will try to understand it because my basic no strong yet

hi,
Re download the new zip, I put the wrong one on the forum.:eek:

Sorry, hope it didnt cause to much confusion.
 
hi,
To make it easier to understand, this listing has the ' Save States ' instruction removed from the Intr subr, you should include it in your final program


Code:
	list p=16f877
	#include <p16f877.inc>
	radix dec
; Begin
	R0L EQU 0x20
	R0H EQU 0x21
	R1L EQU 0x22
	R1H EQU 0x23
	R2L EQU 0x24
	R2H EQU 0x25
	R3L EQU 0x26
	R3H EQU 0x27
	R4L EQU 0x28
	R4H EQU 0x29
	R5L EQU 0x2A
	R5H EQU 0x2B
	W_TEMP EQU 0x7F
	STATUS_TEMP EQU 0x7E
	ORG 0x0000
	BCF PCLATH,3
	BCF PCLATH,4
	GOTO L0002
	ORG 0x0004
	MOVWF W_TEMP
	SWAPF STATUS,W
	CLRF STATUS
	MOVWF STATUS_TEMP
	CALL L0003
	SWAPF STATUS_TEMP,W
	MOVWF STATUS
	SWAPF W_TEMP,F
	SWAPF W_TEMP,W
	RETFIE
L0002:
; 1:  'Prog for 16F877 with 74C922 connected to PORTA lower nibble,
; 2:  'RA4 is used as Intr from 'data available' triggering T0 Timer cntr
; 3:  'test output is PORTB
; 4: 
; 5: AllDigital
	BSF STATUS,RP0
	MOVLW 0x06
	MOVWF 0x1F
; 6: 
	BCF STATUS,RP0
; 7: Dim key As Byte
;       The address of 'key' is 0x2C
	key EQU 0x2C
; 8: Dim keycode As Byte
;       The address of 'keycode' is 0x2D
	keycode EQU 0x2D
; 9: 
; 10: TRISA = 0xff
	BSF STATUS,RP0
	MOVLW 0xFF
	MOVWF 0x05
; 11: TRISB = 0x00
	CLRF 0x06
; 12: 
; 13: OPTION_REG.T0CS = 1 'selects RA4 as the T0 CLK input
	BSF 0x01,5
; 14: OPTION_REG.T0SE = 0 'intr on press,,, =1 intr on release
	BCF 0x01,4
; 15: INTCON.T0IE = 1 'enables the T0 timer to Interrupt
	BCF STATUS,RP0
	BSF 0x0B,5
; 16: TMR0 = 255
	MOVLW 0xFF
	MOVWF 0x01
; 17: 
; 18: Enable 'this enables the Interrrupts
	BSF INTCON,GIE
; 19: 
; 20: loop: 
L0001:
; 21: 
; 22: Goto loop
	GOTO L0001
; 23: 
; 24: 
; 25: End
L0004:	GOTO L0004
; 26: 
; 27: On Interrupt
L0003:
; 28: 
; 29: 
; 30: INTCON.T0IF = 0 'clears the Interrupt flag, set by T0 timer
	BCF 0x0B,2
; 31: 
; 32: key = PORTA And 0x0f
	MOVF 0x05,W
	MOVWF R0L
	MOVLW 0x0F
	ANDWF R0L,W
	MOVWF 0x2C
; 33: 
; 34:  'replace the 0 to 15, with a byte that represents the encryption
; 35:  'example: keycode = LookUp(7, 4, 3, 0, 2, 1, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15), key
; 36: keycode = LookUp(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15), key
	MOVF 0x2C,W
	SUBLW 0x0F
	BTFSS STATUS,C
	GOTO L0005
	CALL L0006
	MOVWF 0x2D
	GOTO L0005
L0006:
	MOVLW 0x00
	MOVWF PCLATH
	MOVF 0x2C,W
	ADDWF PCL,F
	RETLW 0x00
	RETLW 0x01
	RETLW 0x02
	RETLW 0x03
	RETLW 0x04
	RETLW 0x05
	RETLW 0x06
	RETLW 0x07
	RETLW 0x08
	RETLW 0x09
	RETLW 0x0A
	RETLW 0x0B
	RETLW 0x0C
	RETLW 0x0D
	RETLW 0x0E
	RETLW 0x0F
L0005:
; 37: 
; 38: PORTB = keycode
	MOVF 0x2D,W
	MOVWF 0x06
; 39: 
; 40: TMR0 = 255
	MOVLW 0xFF
	MOVWF 0x01
; 41: 
; 42: Resume
	RETURN
; End of program
L0007:	GOTO L0007
; End of listing
	END
 
hihi....
thx for helping me...really thx....
but my lecture tell me that don't use IC74C922 better that use the PIC16F877 to finish all the thing.....sigh...
eric..is that the first page u give me that keypad useful?
thx
 
11max11 said:
hihi....
thx for helping me...really thx....
but my lecture tell me that don't use IC74C922 better that use the PIC16F877 to finish all the thing.....sigh...
eric..is that the first page u give me that keypad useful?
thx
hi,
If you are going to use the PIC to scan the keyboard then the programs I have posted are not suitable.

Look here:

Look also at the other examples on WinPic
 
Last edited:
11max11 said:
after i see the tutorial on there make me very blur....=.="

hi,
Which part or section 'blurs' you the most and which parts don't 'blur' you..:confused:

Tell us how/where the keypads 16 keys [4 * 4] are connected to the PIC port pins.
 
hihi....
i'm blur in the scanning and key pressing part...
why got 4 col and not need row one...

i want to do is 12 keys[4 * 3] and connect the input to the portB
7 input and 1 output
 
Last edited:
A 4x3 keypad normally uses 7 I/O pins. 4 outputs and 3 inputs. PORTB is handy because you can enable weak pullups, it even has a very handy interrupt / wakeup on change mode for bits 4 thru 7.
 
11max11 said:
Can anyone help me see is that i done correct?
i using the MPlab to done one..

View attachment 15611

As I have requested, POST a drawing on how you have connected the 12 key switches to the PORT pins.

We would like to help you, but you are not giving us the information we need.
 
From your code it looks like you've configured the keypad like this;

keypad-3x4-png.15623


Your code looks good except for being in the wrong bank when writing the OPTION register. Your code could also be optimized a bit;

Code:
COLUMN1 BCF     PORTB,0         ;Clear B0
        BSF     PORTB,1         ;Set B1
        BSF     PORTB,2         ;Set B2

CHECK1  MOVLW   .1              ;assume key 1
        BTFSS   PORTB,3         ;pressed? no, skip, else
        MOVWF   PORTA           ;output 1 on PORTA

CHECK4  MOVLW   .4              ;assume key 4
        BTFSS   PORTB,4         ;pressed? no, skip, else
        MOVWF   PORTA           ;output 4 on PORTA

CHECK7  MOVLW   .7              ;assume key 7
        BTFSS   PORTB,5         ;pressed? no, skip, else
        MOVWF   PORTA           ;output 7 on PORTA

CHECK11 MOVLW   .11             ;assume key 11
        BTFSS   PORTB,6         ;pressed? no, skip, else
        MOVWF   PORTA           ;output 11 on PORTA
Or perhaps something like this;
Code:
COLUMN1 BCF     PORTB,0         ;RB0 = 0
        BSF     PORTB,1         ;RB1 = 1
        BSF     PORTB,2         ;RB2 = 1
        MOVLW   0               ;clear WREG (set Z = 1)
        BTFSS   PORTB,3         ;pressed? no, skip, else
        MOVLW   .1              ;WREG = '1'
        BTFSS   PORTB,4         ;pressed? no, skip, else
        MOVLW   .4              ;WREG = '4'
        BTFSS   PORTB,5         ;pressed? no, skip, else
        MOVLW   .7              ;WREG = '7'
        BTFSS   PORTB,6         ;pressed? no, skip, else
        MOVLW   .11             ;WREG = '11'
COLUMN2 BSF     PORTB,0         ;RB0 = 1
        BCF     PORTB,1         ;RB1 = 0
        BSF     PORTB,2         ;RB2 = 1
        BTFSS   PORTB,3         ;
        MOVLW   .2              ;
        BTFSS   PORTB,4         ;
        MOVLW   .5              ;
        BTFSS   PORTB,5         ;
        MOVLW   .8              ;
        BTFSS   PORTB,6         ;
        MOVLW   .10             ;
COLUMN3 BSF     PORTB,0         ;RB0 = 1
        BSF     PORTB,1         ;RB1 = 1
        BCF     PORTB,2         ;RB2 = 0
        BTFSS   PORTB,3         ;
        MOVLW   .3              ;
        BTFSS   PORTB,4         ;
        MOVLW   .6              ;
        BTFSS   PORTB,5         ;
        MOVLW   .9              ;
        BTFSC   PORTB,6         ;
        MOVLW   .12             ;
WRAPUP  BTFSS   STATUS,Z        ;key press? no, skip, else
        MOVWF   PORTA           ;output key on PORTA
        GOTO    COLUMN1         ;Start scanning again.
 

Attachments

  • Keypad 3x4.PNG
    Keypad 3x4.PNG
    8.2 KB · Views: 687
Last edited:
hi guys i am using a PIC16F84A and i want to use a keypad with
my question is how can i connect the keypad in the circuit? is there any VDD going through it? if there isn't how can i detect a key pushed?
thanks in advance
 
Status
Not open for further replies.

Latest threads

Back
Top