Sie sind auf Seite 1von 9

MICROPROCESSOR INTERFACING &

PROGRAMMING
(EL-303)

LABORATORY MANUAL

Lab # 08: To Setup Keypad with a Controller in Polling


Mode
Student Name: Ethisham Ul Hassan, Amlish Rafique

Roll No: 17F-8408,17F-8406 Group No: 01 Section: B

Date performed: 23-102019

CLO MARKS OBTAINED


1
3

Lab Engineer Signature:_________________

_________________________________________________________________________________________________________________________________________________________
___
NATIONAL UNIVERSITY OF COMPUTER AND EMERGING SCIENCES, CHINIOT- FAISALABAD

Prepared by: Engr. Umer Farooq


MIP Lab National University Roll No: __________

Lab #
(EL303)
of Computer and Emerging Sciences
Chiniot-Faisalabad Fall 2019
08
_________________________________________________________________________________

EVALUATION RUBRIC:
EL303 – MICROPROCESSOR INTERFACING AND PROGRAMMING LAB
To enable the students to write effective assembly language programs using various addressing modes,
jumps, timers, counters, and interrupts. Also enabling them to interface any external hardware using
serial programming and verifying the results either through simulators or through actual hardware.

CLO Statement ↓ Exemplary (5) Proficient (4) Developing (3) Beginning (2) Novice
Score → (1)

Behaves
responsibly within Takes ownership Actively works Partially work Needs help from Does not
and Works and participates and participate in others group to work
team, and perform
actively in group group complete
1 the experiment throughout the discussions. discussions assigned task
safely. lab

Design and
development of a
microcontroller- Correctly With minor With major Partially Does not
based system to develops the mistakes mistakes develops the work
3 solve an microcontroller- develops the develops the microcontroller-
based system microcontroller- microcontroller- based system
engineering
based system based system
problem.

____________________________________________________________________________________________
Page 2 of 9
MIP Lab National University Roll No: __________

Lab #
(EL303)
of Computer and Emerging Sciences
Chiniot-Faisalabad Fall 2019
08
_________________________________________________________________________________

Lab #08: To Setup Keypad with a Controller in Polling Mode


PURPOSE:

1. To learn scanning of a simple keypad for input


2. To learn a method of taking input from keypad and process it using the 89C52 micro-
controller
EQUIPMENT REQUIRED:

1. KeilμVision IDE
2. ATMEL ®89C52 Microcontroller Kit
3. XELTEX Universal Burner
4. Keypad

8.1 BACKGROUND:

1. The keypad is a matrix of 16 switches as shown in the figure above. It can be used in
various ways to take an input. We will discuss only one method here.
2. The figure below shows a typical circuit for scanning a keypad for input. The method is
as follows:
3. Put Port pins P0.0, P0.1, P0.2, P0.3 in high impedance input mode by writing 1s to them.
These are now our scanning inputs.
4. Write 1s to the port pins 1.0 to 1.3 as well. These are our scanning outputs.
5. Start the scanning by writing a 0 to P1.0.
6. Read the values of P0.0 to P0.3.
7. If P0.0 is 0, 1 is pressed. If P0.1 is 0, 4 is pressed. If P0.2 is 0, 7 is pressed. If P0.3 is 0, *
is pressed. Otherwise, no key press is detected.
8. Now continue scanning by writing zeros to the columns, one by one.

____________________________________________________________________________________________
Page 3 of 9
MIP Lab National University Roll No: __________

Lab #
(EL303)
of Computer and Emerging Sciences
Chiniot-Faisalabad Fall 2019
08
_________________________________________________________________________________

Telephonic Keypad:
1. The figure below shows a typical circuit for scanning of a telephonic keypad, which has
12 switches, for input. The method mentioned above can also be used.
2. We can write ‘0’ at rows, one by one, and then can scan the columns to check if any key
is pressed.

____________________________________________________________________________________________
Page 4 of 9
MIP Lab National University Roll No: __________

Lab #
(EL303)
of Computer and Emerging Sciences
Chiniot-Faisalabad Fall 2019
08
_________________________________________________________________________________

8.2 EXERCISES:

Task1: Write a program that takes input of one digit from 4x3 keypad. Assign ten decimal value
to ‘*’ button and eleven decimal value to ‘#’ button. After getting the input, display the square
of the input number on LEDs.

Task2: Write a program that takes input of 2-digit number from 4x3 keypad and set P1.3 pin if
the input number is even otherwise clear P1.3 pin. Assign ten decimal value to ‘*’ button and
eleven decimal value to ‘#’ button. If ‘*’ or ‘#’ button is pressed then use their corresponding
decimal value as 2-digit number.

ORG 00H

MOV A,#0FFH
MOV P0,#00H

MOV DPTR,#LIST

BACK:MOV P1,#11111111B
CLR P1.0
JB P1.4,NEXT1
MOV A,#0D
ACALL DISPLAY
NEXT1:JB P1.5,NEXT2
MOV A,#1D
ACALL DISPLAY
NEXT2:JB P1.6,NEXT3
MOV A,#2D
ACALL DISPLAY
NEXT3:JB P1.7,NEXT4
MOV A,#3D
ACALL DISPLAY
NEXT4:SETB P1.0
CLR P1.1
JB P1.4,NEXT5
MOV A,#4D
ACALL DISPLAY
NEXT5:JB P1.5,NEXT6
MOV A,#5D
ACALL DISPLAY
NEXT6:JB P1.6,NEXT7
MOV A,#6D
ACALL DISPLAY

____________________________________________________________________________________________
Page 5 of 9
MIP Lab National University Roll No: __________

Lab #
(EL303)
of Computer and Emerging Sciences
Chiniot-Faisalabad Fall 2019
08
_________________________________________________________________________________

NEXT7:JB P1.7,NEXT8
MOV A,#7D
ACALL DISPLAY
NEXT8:SETB P1.1
CLR P1.2
JB P1.4,NEXT9
MOV A,#8D
ACALL DISPLAY
NEXT9:JB P1.5,NEXT10
MOV A,#9D
ACALL DISPLAY
NEXT10:JB P1.6,NEXT11
MOV A,#10D
ACALL DISPLAY
NEXT11:JB P1.7,NEXT12
MOV A,#11D
ACALL DISPLAY
NEXT12:SETB P1.2
CLR P1.3
JB P1.4,BACK
MOV A,#12D
ACALL DISPLAY
LJMP BACK

DISPLAY:
MOVC A,@A+DPTR
MOV P0,A
RET

LIST:
DB 01100000B
DB 11011010B
DB 11110010B
DB 11101110B
DB 01100110B
DB 10110110B
DB 10111110B
DB 00111110B
DB 11100000B
DB 11111110B
DB 11110110B
DB 10011100B
DB 10011110B
DB 11111100B

____________________________________________________________________________________________
Page 6 of 9
MIP Lab National University Roll No: __________

Lab #
(EL303)
of Computer and Emerging Sciences
Chiniot-Faisalabad Fall 2019
08
_________________________________________________________________________________

DB 10001110B
DB 01111010B
END

8.3 POST LAB:

Write a program that generates one cycle of a square wave with frequency of 100mHz on port
pin P1.0 with duty cycle depending on the one digit input value pressed by the user on 4x3
keypad. The user is allowed to mention the value from 1 – 9. For example, if input value is 1 then
duty cycle is 10%, if the value is 2 duty cycle is 20% and so on. Use crystal frequency
f=11.0592MHz.

Code:
ORG 00H
MOV A,#0FFH
CLR P1.0
BACK: MOV P3,#0FFH
JB P3.4,NEXT1
MOV A,#0
ACALL CHECK
SJMP BACK

NEXT1: JB P3.5,NEXT2
MOV A,#1
ACALL CHECK

NEXT2:JB P3.6,NEXT3
MOV A,#2
ACALL CHECK

NEXT3: JB P3.7,NEXT4
MOV A,#3
ACALL CHECK

NEXT4: SETB P3.0


CLR P3.1

____________________________________________________________________________________________
Page 7 of 9
MIP Lab National University Roll No: __________

Lab #
(EL303)
of Computer and Emerging Sciences
Chiniot-Faisalabad Fall 2019
08
_________________________________________________________________________________

JB P3.4,NEXT5
MOV A,#4
ACALL CHECK

NEXT5:JB P3.5,NEXT6
MOV A,#5
ACALL CHECK

NEXT6: JB P3.6,NEXT7
MOV A,#6
ACALL CHECK

NEXT7: JB P3.7,NEXT8
MOV A,#7
ACALL CHECK

NEXT8:SETB P3.1
CLR P3.2
JB P3.4,NEXT9
MOV A,#8
ACALL CHECK

NEXT9:JB P3.5,BACK
MOV A,#9
ACALL CHECK
LJMP BACK

CHECK:
CLR P1.0
MOV R6,A
AGAIN: SETB P1.0
ACALL DELAY
DJNZ R6,AGAIN
CLR P1.0
RET

DELAY:
MOV R0,#150
LOOP3:MOV R1,#80
LOOP2: MOV R2,#50
LOOP1:DJNZ R2,LOOP1
DJNZ R1,LOOP2
DJNZ R0,LOOP3

____________________________________________________________________________________________
Page 8 of 9
MIP Lab National University Roll No: __________

Lab #
(EL303)
of Computer and Emerging Sciences
Chiniot-Faisalabad Fall 2019
08
_________________________________________________________________________________

RET

END

U1
19 39
XTAL1 P0.0/AD0
38
P0.1/AD1
37
P0.2/AD2
18 36
XTAL2 P0.3/AD3
35
P0.4/AD4
34
P0.5/AD5
33
P0.6/AD6
9 32
RST P0.7/AD7
21
P2.0/A8
22
P2.1/A9
23
P2.2/A10
29 24
PSEN P2.3/A11
30 25
ALE P2.4/A12
31 26
EA P2.5/A13
27
P2.6/A14
28
P2.7/A15
1 10
P1.0/T2 P3.0/RXD
2 11
P1.1/T2EX P3.1/TXD
3 12
P1.2 P3.2/INT0
4 13
P1.3 P3.3/INT1
5 14
P1.4 P3.4/T0
6 15
P1.5 P3.5/T1
7 16
P1.6 P3.6/WR
8 17
P1.7 P3.7/RD
AT89C52
1

A 1 2 3
B 4 5 6
C 7 8 9
D 0 #

Attach the code in the manual

____________________________________________________________________________________________
Page 9 of 9

Das könnte Ihnen auch gefallen