Upload
zeeshanmaqboo2413
View
236
Download
0
Embed Size (px)
Citation preview
8/3/2019 Keypad Interface
http://slidepdf.com/reader/full/keypad-interface 1/18
Semester Project Report
KEYPAD & LCD INTERFACEPrepared by
Zeeshan Maqbool 2008-EE-031
Imran Akhter 2008-EE-040
Muhammad Sajid Ali 2008-EE-021
Teacher
Sir Numan Siddiqui
Department of Electronics Engg
8/3/2019 Keypad Interface
http://slidepdf.com/reader/full/keypad-interface 2/18
ACKNOWLEDGEMENT
In the name of ALLAH the ALMIGHTY who
enabled us to complete this report successfully and helped us in the difficult moments
during the development of this report.
PREFACE
Gratitude to ALLAH ALMIGHTY (Azza-wa-Jal) and cordial tribute to Nabi-e-Karim (Sai-
Allah-Aliika-Wasalam) by the grace of which we achieve success in every field of life.
The project is compiled on a student level on the behalf of possible technical data
arranged from internet and from course book.
8/3/2019 Keypad Interface
http://slidepdf.com/reader/full/keypad-interface 3/18
KEYPAD & LCD INTERFACE
Project Objective
To design and implement a keypad interface with 8051 which print the
character on LCD pressed from the keypad.
Working
.
Microcontrollers are just silicon wafers until we tell them what to do, programthem
according to our requirement. Similarly any user interface is incomplete without an
Input. One, two pushbuttons can be easily interfaced however if more user inputs are
required it can take up a lot of I/O lines. So here is a small tutorial to interface a 4x4
Matrix Keypad and displaying the key pressed on a LCD. Themicrocontroller used is
AT89C51 and the coding has been done in assembly language.
The 4x4 Keypad has 16 keys and requires a single PORT or 8 I/O lines. Port 3 has
been designed to handle keypad, LCD Data Bus D7-D0 is connected to PORT 1, while
(Enable) EN is connected to P2.0
(Register Select – Command or Data Register) RS is connected to P2.1
(Read/Write) RW is connected to P2.2
The LCD is based on Hitachi HD44780 Controller and
To check for the keystroke, a polling method has been used.
8/3/2019 Keypad Interface
http://slidepdf.com/reader/full/keypad-interface 4/18
PORT 3.0 Key 1 Key 2 Key 3 Key 4
PORT3.1 Key 5 Key 6 Key 7 Key 8
PORT3.2 Key 9 Key 10 Key 11 Key 12
PORT3.3 Key 13 Key 14 Key 15 Key 16
PORT3.4 PORT3.5 PORT3.6 PORT3.7
The connections are similar as shown over here. Now consider this, if I select the first
column only, it has 4 keys, 1, 5,9,13. If a change of value (i.e. Binary 1 or 0) is made
any one of these keys, it can be decoded and suitable message is displayed on the
LCD. This is exactly what happens. Initially all the I/O lines are pulled high, then during
Key Scan, every column linked is held low for a little time. If during that time a Key is
pressed in that column a row I/O lines is also held low, thus the keystroke can
be captured.
The obvious question would be what if we press the key on a particular column and at
that particular moment that column has not been pulled low, thus making no signal
changes?
The answer is simple, the microcontroller runs quite fast, even a convention 89c51 in
which the internal frequency= external frequency clock/12 can achieve 2 MIPS at
24MHz. That is 2 Million instructions Per Second. This method is not foolproof, it has a
drawback, while the Key Scan, It cannot perform other cumbersome operations which
may take time and a Key Stroke could be missed. The program will work very well for
small operations like activating a small relay or LED when a Key is pressed, but forpeople who want their systems to be near to perfect they may utilize other method.
.
8/3/2019 Keypad Interface
http://slidepdf.com/reader/full/keypad-interface 5/18
Block diagram
8/3/2019 Keypad Interface
http://slidepdf.com/reader/full/keypad-interface 6/18
Circuit Diagram
8/3/2019 Keypad Interface
http://slidepdf.com/reader/full/keypad-interface 7/18
Flow Chart
8/3/2019 Keypad Interface
http://slidepdf.com/reader/full/keypad-interface 8/18
Coding
ORG 00H
MOV A,#38H ;INITIATE LCD
CALL CWRT ;COMMAND SUBROUTINE
CALL DELAY
MOV A,#0EH ;DISPLAY ON,CURSOR ON
CALL CWRT
CALL DELAY
MOV A,#01H ;CLEAR LCD
CALL CWRT
CALL DELAY
MOV A,#06H ;SHIFT CURSOR RIGHT
CALL CWRT
CALL DELAY
MOV P3,#0FFH ;MAKE P3 AN INPUT PORT
K1:
MOV P1,#0 ;GROUND ALL ROWS AT ONCE
MOV A,P3 ;READ ALL COL.
ANL A,#00001111B ;MASKED UNUSED BIT
CJNE A,#00001111B,K1 ;CHECK TILL ALL KEYS RELEASED
K2:
ACALL DELAY ;CALL 20 MS DELAY
MOV A,P3 ;SEE IF ANY KEY IS PRESSED
ANL A,#00001111B ;MASKED UNUSED BIT
CJNE A,#00001111B,OVER ;KEY PRESSED, WAIT CLOSURE
8/3/2019 Keypad Interface
http://slidepdf.com/reader/full/keypad-interface 9/18
SJMP K2 ;CHECK TILL KEY PRESSED
OVER:
ACALL DELAY ;WAIT 20 MS DEBOUNCE TIME
MOV A,P3 ;CHECK KEY CLOSURE
ANL A,#00001111B ;MASKED UNUSED BIT
CJNE A,#00001111B,OVER1 ;KEY PRESSED, FIND ROW
SJMP K2 ;IF NONE, KEEP POLLING
OVER1:
MOV P1,#1111110B ;GROUND ROW 0
MOV A,P3 ;READ ALL COLUMNS
ANL A,#00001111B ;MASKED UNUSED BIT
CJNE A,#00001111B,ROW_0 ;KEY ROW 0, FIND THE COL
MOV P1,#11111101B ;GROUND ROW 1
MOV A,P3 ;READ ALL COL.
ANL A,#00001111B ;MASKED UNUSED BIT
CJNE A,#00001111B,ROW_1 ;KEY ROW 1, FIND THE COL
MOV P1,#11111011B ;GROUND ROW 2
MOV A,P3 ;READ ALL COL.
ANL A,#00001111B ;MASKED UNUSED BIT
CJNE A,#00001111B,ROW_2 ;KEY ROW 2, FIND THE COL
MOV P1,#11110111B ;GROUND ROW 3
MOV A,P3 ;READ ALL COL.
ANL A,#00001111B ;MASKED UNUSED BIT
CJNE A,#00001111B,ROW_3 ;KEY ROW 3, FIND THE COL
LJMP K2 ;IF NONE, FALSE INPUT, REPEAT
8/3/2019 Keypad Interface
http://slidepdf.com/reader/full/keypad-interface 10/18
ROW_0:
MOV DPTR, #KCODE0 ;SET DPTR=START OR ROW 0
SJMP FIND ;FIND COLUMN BELONGS TO
ROW_1:
MOV DPTR, #KCODE1 ;SET DPTR=START OR ROW 1
SJMP FIND ;FIND COLUMN BELONGS TO
ROW_2:
MOV DPTR, #KCODE2 ;SET DPTR=START OR ROW 2
SJMP FIND ;FIND COLUMN BELONGS TO
ROW_3:
MOV DPTR, #KCODE3 ;SET DPTR=START OR ROW 3
FIND:
RRC A ;SEE IF ANY CY BIT LOW
JNC MATCH ;IF ZERO GET ASCII CODE
INC DPTR ;POINT TO NEXT COLUMN
SJMP FIND ;KEEP SEARCHING
MATCH:
CLR A
MOVC A,@A+DPTR ;GET ASCII CODE FROM LOOK-UP
//CALL DWRT ;CALL LCD DATA WRITE ROUTINE
MOV P2,A
8/3/2019 Keypad Interface
http://slidepdf.com/reader/full/keypad-interface 11/18
LJMP K1 ;LOOP
DELAY:
dl1:MOV R4,#62
MOV R5,#149
DJNZ R5,$
DJNZ R4,dl1
ret
CWRT:
MOV P2,A ;COPY REGISTER TO PORT 2
CLR P0.0 ;RS=0 FOR COMMAND
CLR P0.1 ;W/R=0 FOR WRITE
SETB P0.2 ;E=1
CALL DELAY
CLR P0.2 ;E=0
ret
DWRT:
MOV P2,A
SETB P0.0 ;RS=1 FOR DATA
CLR P0.1 ;R/W=0 FOR WRITE
SETB P0.2 ;E=1
CALL DELAY
8/3/2019 Keypad Interface
http://slidepdf.com/reader/full/keypad-interface 12/18
CLR P0.2 ;E=0
ret
;LOOK-UP TABLE
ORG 300H
KCODE0:
DB '0' , '1' , '2' , '3' ;ROW 0
KCODE1:
DB '4' , '5' , '6' , '7' ;ROW 1
KCODE2:
DB '8' , '9' , 'A' , 'B' ;ROW 2
KCODE3:
DB 'C' , 'D' , 'E' , 'F' ;ROW 3
END
8/3/2019 Keypad Interface
http://slidepdf.com/reader/full/keypad-interface 13/18
Data Sheet
CONCLUSION
TIME [MAN HOURS] CONSUMED
Total time consumed on the project is 8-10 hours.
SOURCE OF COMPONENTS
First we searched on internet about project aeecssories and then brought
from electronics market .
For Use by the Teacher Only
Marks/Grade Obtained:
Teacher’s Comments:
Name: miss umaira shahid
Signature:
8/3/2019 Keypad Interface
http://slidepdf.com/reader/full/keypad-interface 14/18
A resistor is a two-terminal passive electronic componentwhich
implements electrical resistance as a circuit element. When a voltage V is
applied across the terminals of a resistor, a current I will flow through theresistor in direct proportion to that voltage.
by Ohm's law:
Resistors are common elements of electrical networks and electronic
circuits and are ubiquitous in most electronic equipment.
unitThe ohm (symbol: Ω) is the SI unit of electrical resistance, named after Georg
Simon Ohm. An ohm is equivalent to a volt per ampere. Since resistors are
specified and manufactured over a very large range of values, the derived
units of milliohm (1 mΩ = 10−3 Ω), kilohm (1 kΩ = 103 Ω), and megohm (1 MΩ
= 106 Ω) are also in common usage
A capacitor (formerly known as condenser) is a device for storingelectric charge. Capacitors used as parts of electrical systems, for example,
consist of metal foils separated by a layer of insulating film.
Capacitors are widely used in electronic circuits for blocking direct
current while allowing alternating currentto pass, in filter networks, for
smoothing the output ofpower supplies, in the resonant circuits that tune
radios to particular frequencies and for many other purposes.
A crystal oscillatoris an electronic oscillator circuit that uses the
mechanical resonance of a vibrating crystal ofpiezoelectric material to create
an electrical signal with a very precise frequency. This frequency is commonly
used to keep track of time (as in quartz wristwatches), to provide a
stable clock signal for digital integrated circuits, and to stabilize frequencies
for radio transmitters and receivers. Quartz crystals are manufactured for
8/3/2019 Keypad Interface
http://slidepdf.com/reader/full/keypad-interface 15/18
frequencies from a few tens of kilohertz to tens of megahertz. Most are used
for consumer devices such as wristwatches, clocks, radios,computers,
and cellphones.
Variable resistors consist of a resistance track with connections atboth ends and a wiper which moves along the track as you turn the spindle.
The track may be made from carbon, cermet (ceramic and metal mixture) or a
coil of wire (for low resistances). The track is usually rotary but straight track
versions, usually called sliders, are also available.
Variable resistors are often called potentiometers in books and catalogues.
They are specified by their maximum resistance, linear or logarithmic track,
and their physical size. The standard spindle diameter is 6mm. Some variable
resistors are designed to be mounted directly on the circuit board,
The Intel 8051 microcontroller is one of the most popular general
purpose microcontrollers in use today. The Intel 8051 is an 8-bit
microcontroller which means that most available operations are limited to 8
bits.
Some of the features that have made the 8051 popular are:
64 KB on chip program memory. 128 bytes on chip data memory(RAM).
4 reg banks.
128 user defined software flags.
8-bit data bus
16-bit address bus
32 general purpose registers each of 8 bits
16 bit timers (usually 2, but may have more, or less).
3 internal and 2 external interrupts. Bit as well as byte addressable RAM area of 16 bytes.
Four 8-bit ports, (short models have two 8-bit ports).
16-bit program counter and data pointer.
1 Microsecond instruction cycle with 12 MHz Crystal.
8/3/2019 Keypad Interface
http://slidepdf.com/reader/full/keypad-interface 16/18
8051 models may also have a number of special, model-specific features,
such as UARTs, ADC, OpAmps, etc...
The 8051 requires the existence of an external oscillator circuit. The oscillator
circuit usually runs around 12MHz, although the 8051 (depending on which
specific model) is capable of running at a maximum of 40MHz. Each machinecycle in the 8051 is 12 clock cycles, giving an effective cycle rate at 1MHz (for
a 12MHz clock) to 3.33MHz (for the maximum 40MHz clock).
A liquid crystal display (LCD) is a thin, flat electronic visual
display that uses the light modulating properties of liquid crystals (LCs). LCs
do not emit light directly.
They are used in a wide range of applications, includingcomputer
monitors, television, instrument panels, aircraft cockpit displays, signage, etc.They are common in consumer devices such as video players, gaming
devices, clocks, watches, calculators, and telephones. LCDs have
displaced cathode ray tube (CRT) displays in most applications.
A keypad is a set of buttons arranged in a block or "pad" which usually
bear digits, symbols and usually a complete set of alphabetical letters. If it
mostly contains numbers then it can also be called a numeric keypad.
Keypads are found on many alphanumeric keyboards and on other devices
such as calculators, push-button telephones, combination locks, and digital
door locks, which require mainly numeric input
8/3/2019 Keypad Interface
http://slidepdf.com/reader/full/keypad-interface 17/18
8/3/2019 Keypad Interface
http://slidepdf.com/reader/full/keypad-interface 18/18
Marks/Grade Obtained:
Teacher’s Comments:
Name: miss umaira shahid
Signature: