Escolar Documentos
Profissional Documentos
Cultura Documentos
Prepared by
Zeeshan Maqbool Imran Akhter Muhammad Sajid Ali 2008-EE-031 2008-EE-040 2008-EE-021
Teacher
Sir Numan Siddiqui
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.
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
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
;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
;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
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
;E=0
KCODE0:
;ROW 0
;ROW 1
;ROW 2
;ROW 3
SOURCE OF COMPONENTS
First we searched on internet about project aeecssories and then brought from electronics market .
Signature:
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
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.
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).
Signature: