Você está na página 1de 18

Semester Project Report

KEYPAD & LCD INTERFACE

Prepared by
Zeeshan Maqbool Imran Akhter Muhammad Sajid Ali 2008-EE-031 2008-EE-040 2008-EE-021

Teacher
Sir Numan Siddiqui

Department of Electronics Engg

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 (SaiAllah-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.

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.

PORT 3.0 PORT3.1 PORT3.2 PORT3.3

Key 1 Key 5 Key 9 Key 13 PORT3.4

Key 2 Key 6 Key 10 Key 14 PORT3.5

Key 3 Key 7 Key 11 Key 15 PORT3.6

Key 4 Key 8 Key 12 Key 16 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 for people who want their systems to be near to perfect they may utilize other method.

Block diagram

Circuit Diagram

Flow Chart

Coding
ORG 00H MOV A,#38H CALL CWRT CALL DELAY MOV A,#0EH CALL CWRT CALL DELAY MOV A,#01H CALL CWRT CALL DELAY MOV A,#06H CALL CWRT CALL DELAY ;SHIFT CURSOR RIGHT ;CLEAR LCD ;DISPLAY ON,CURSOR ON ;INITIATE LCD ;COMMAND SUBROUTINE

MOV P3,#0FFH K1: MOV P1,#0 MOV A,P3 ANL A,#00001111B CJNE A,#00001111B,K1 K2: ACALL DELAY MOV A,P3 ANL A,#00001111B CJNE A,#00001111B,OVER

;MAKE P3 AN INPUT PORT

;GROUND ALL ROWS AT ONCE ;READ ALL COL. ;MASKED UNUSED BIT ;CHECK TILL ALL KEYS RELEASED

;CALL 20 MS DELAY ;SEE IF ANY KEY IS PRESSED ;MASKED UNUSED BIT ;KEY PRESSED, WAIT CLOSURE

SJMP K2 OVER: ACALL DELAY MOV A,P3 ANL A,#00001111B CJNE A,#00001111B,OVER1 SJMP K2 OVER1: MOV P1,#1111110B MOV A,P3 ANL A,#00001111B CJNE A,#00001111B,ROW_0 MOV P1,#11111101B MOV A,P3 ANL A,#00001111B CJNE A,#00001111B,ROW_1 MOV P1,#11111011B MOV A,P3 ANL A,#00001111B CJNE A,#00001111B,ROW_2 MOV P1,#11110111B MOV A,P3 ANL A,#00001111B CJNE A,#00001111B,ROW_3 LJMP K2

;CHECK TILL KEY PRESSED

;WAIT 20 MS DEBOUNCE TIME ;CHECK KEY CLOSURE ;MASKED UNUSED BIT ;KEY PRESSED, FIND ROW ;IF NONE, KEEP POLLING

;GROUND ROW 0 ;READ ALL COLUMNS ;MASKED UNUSED BIT ;KEY ROW 0, FIND THE COL ;GROUND ROW 1 ;READ ALL COL. ;MASKED UNUSED BIT ;KEY ROW 1, FIND THE COL ;GROUND ROW 2 ;READ ALL COL. ;MASKED UNUSED BIT ;KEY ROW 2, FIND THE COL ;GROUND ROW 3 ;READ ALL COL. ;MASKED UNUSED BIT ;KEY ROW 3, FIND THE COL ;IF NONE, FALSE INPUT, REPEAT

ROW_0: MOV DPTR, #KCODE0 SJMP FIND ;SET DPTR=START OR ROW 0 ;FIND COLUMN BELONGS TO

ROW_1: MOV DPTR, #KCODE1 SJMP FIND ;SET DPTR=START OR ROW 1 ;FIND COLUMN BELONGS TO

ROW_2: MOV DPTR, #KCODE2 SJMP FIND ;SET DPTR=START OR ROW 2 ;FIND COLUMN BELONGS TO

ROW_3: MOV DPTR, #KCODE3 ;SET DPTR=START OR ROW 3

FIND: RRC A JNC MATCH INC DPTR SJMP FIND ;SEE IF ANY CY BIT LOW ;IF ZERO GET ASCII CODE ;POINT TO NEXT COLUMN ;KEEP SEARCHING

MATCH: CLR A MOVC A,@A+DPTR //CALL DWRT MOV P2,A ;GET ASCII CODE FROM LOOK-UP ;CALL LCD DATA WRITE ROUTINE

LJMP K1

;LOOP

DELAY: dl1:MOV R4,#62 MOV R5,#149 DJNZ R5,$ DJNZ R4,dl1 ret

CWRT: MOV P2,A CLR P0.0 CLR P0.1 SETB P0.2 CALL DELAY CLR P0.2 ret ;E=0 ;COPY REGISTER TO PORT 2 ;RS=0 FOR COMMAND ;W/R=0 FOR WRITE ;E=1

DWRT: MOV P2,A SETB P0.0 CLR P0.1 SETB P0.2 CALL DELAY ;RS=1 FOR DATA ;R/W=0 FOR WRITE ;E=1

CLR P0.2 ret

;E=0

;LOOK-UP TABLE ORG 300H

KCODE0:

DB '0' , '1' , '2' , '3' KCODE1:

;ROW 0

DB '4' , '5' , '6' , '7' KCODE2:

;ROW 1

DB '8' , '9' , 'A' , 'B' KCODE3:

;ROW 2

DB 'C' , 'D' , 'E' , 'F' END

;ROW 3

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: Teachers Comments: Name: miss umaira shahid

Signature:

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 the resistor 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.

unit
The 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 = 103 ), kilohm (1 k = 103 ), and megohm (1 M = 106 ) are also in common usage

A capacitor (formerly known as condenser) is a device for storing


electric 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 oscillator is 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

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 at


both 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.

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 machine cycle 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

Marks/Grade Obtained: Teachers Comments: Name: miss umaira shahid

Signature:

Você também pode gostar