Showing posts with label keyboard interfacing with 8051. Show all posts
8051 assembly program for keyboard interfacing
/************************************************************************************/
// PROGRAM TO DEMONSTRATE 4x4 keyboard interfacing
/************************************************************************************/
ORG 0000H
/************************************************************************************/
/* I/O PIN INITIALISATIONS AND DECLARATIONS */
/************************************************************************************/
C1 EQU P2.0
C2 EQU P2.1
C3 EQU P2.2
C4 EQU P2.3
ROW1 EQU P2.4
ROW2 EQU P2.5
ROW3 EQU P2.6
ROW4 EQU P2.7
MOV P2,#00H
MOV P0,#00H
MOV DPTR,#MSG
CLR A
MOV B,#00H
MOV R3,#00H
MOV SCON,#50H
MOV TMOD,#20H
MOV TH1,#0FDH
SETB TR1
/************************************************************************************/
/* READING COLUMN VALUE */
/************************************************************************************/
AGAIN: ACALL DELAY
MOV P2, #0FH
ACALL DELAY
K1: MOV A,P2
CJNE A,#0FH,KK1
SJMP K1
KK1: JB C1,N1
MOV B,#00h
ACALL DELAY
N1: JB C2,N2
MOV B,#01h
ACALL DELAY
N2: JB C3,N3
MOV B,#02h
ACALL DELAY
N3: JB C4,N4
MOV B,#03h
ACALL DELAY
/************************************************************************************/
/* READING ROW VALUE */
/************************************************************************************/
N4: MOV P2, #0F0H
K11: MOV A,P2
CJNE A,#0F0H,KK11
SJMP K11
KK11: ACALL DELAY
JB ROW1,NR1
MOV R3,#00h
ACALL DELAY
NR1: JB ROW2,NR2
MOV R3,#04h
ACALL DELAY
NR2: JB ROW3,NR3
MOV R3,#08h
ACALL DELAY
NR3: JB ROW4,NR4
MOV R3,#0Ch
ACALL DELAY
NR4: MOV A,R3
/************************************************************************************/
/* SENDING KEYVALUE TO PORT 0 AND SERAIL PORT */
/************************************************************************************/
ADD A,B
MOV P0,A
MOVC A,@A+DPTR
MOV SBUF,A
AGAIN_SR:JNB TI,AGAIN_SR
CLR A
SJMP AGAIN
/************************************************************************************/
/* DELAY SUBROUTINE */
/************************************************************************************/
DELAY: MOV R6,#5FH
a1: MOV R5,#0FEH
a2: DJNZ R5,a2
DJNZ R6,a1
RET
/************************************************************************************/
/* LOOKUP TABLE W.R.T 0-15 SWITCHES IN HEX KEYPAD */
/************************************************************************************/
MSG: DB '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F',0
keyboard interfacing with 8051
Keyboard / Keypad interfacing with 8051.
First we need to connect switch as given in figure. So we have now 8 pins that is to be interfaced with microcontroller to detect any of the keystroke. I have simulated this on Proteus. Program has been written in assembly language. You can use Keil to write program and then generate hex file.This is the snapshot of proteus design. Here i have connected keypad to port 2. You need not to connect resister pack to port 0 if you are not using it. You can see in the figure that a black box has been connected to the Rx and Tx pin. It is virtual terminal used to communicate with computer directly. Here we need to connect it to computer. We will just view the result on this when any key is pressed. You can also use LCD to see the output. I will explain about it in next post.
Click Here to see the assembly language program