Microprocessor Interfacing & Programming: Laboratory Manual
Microprocessor Interfacing & Programming: Laboratory Manual
PROGRAMMING
(EL-303)
LABORATORY MANUAL
_________________________________________________________________________________________________________________________________________________________
___
NATIONAL UNIVERSITY OF COMPUTER AND EMERGING SCIENCES, CHINIOT- FAISALABAD
MIP Lab National University Roll No: __________
Lab #
(EL303)
of Computer and Emerging Sciences
Chiniot-Faisalabad Fall 2019
06
_________________________________________________________________________________
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 Developing (3) Beginning (2) Novice
Score → (4) (1)
Behaves
responsibly within Takes ownership Actively works Partially work Needs help from Does not
and Works and and participate in others group to work
team, and perform
actively participates in group complete
1 the experiment throughout the group discussions assigned task
safely. lab discussions.
Demonstrate
elementary skills to Correctly With minor With major Partially Does not
conduct performs the mistakes mistakes performs the work
experiments using tasks performs the performs the tasks
2 tasks tasks
various
programming
techniques.
____________________________________________________________________________________________
Page 2 of 7
MIP Lab National University Roll No: __________
Lab #
(EL303)
of Computer and Emerging Sciences
Chiniot-Faisalabad Fall 2019
06
_________________________________________________________________________________
EQUIPMENT REQUIRED:
1. KeilμVision IDE
2. ATMEL ®89C52 Microcontroller Kit
3. XELTEX Universal Burner
4. Mechanical Switches
6.1 BACKGROUND:
Push-button switches, toggle switches, and electro-mechanical relays all have one thing in
common: contacts. It's the metal contacts that make and break the circuit and carry the current in
switches and relays. Because they are metal, contacts have mass. And since at least one of the
contacts is on a movable strip of metal, it has springiness. Since contacts are designed to open
and close quickly, there is little resistance (damping) to their movement.
Because the moving contacts have mass and springiness with low damping they will be "bouncy"
as they make and break. That is, when a normally open (N.O.) pair of contacts is closed, the
contacts will come together and bounce off each other several times before finally coming to rest
in a closed position. The effect is called "contact bounce" in a switch, or "switch bounce" See
Figure 1. Note that contacts can bounce on opening as well as on closing.
If all you want your switch or relay to do is turn on a lamp or start a fan motor, then contact
bounce is not a problem. But if you are using a switch or relay as input to a digital counter, a
____________________________________________________________________________________________
Page 3 of 7
MIP Lab National University Roll No: __________
Lab #
(EL303)
of Computer and Emerging Sciences
Chiniot-Faisalabad Fall 2019
06
_________________________________________________________________________________
personal computer, or a micro-processor based piece of equipment, then you must consider
contact bounce. The reason for concern is that the time it takes for contacts to stop bouncing is
measured in milliseconds. Digital circuits can respond in microseconds.
As an example, suppose you want to count widgets as they go by on a conveyor belt. You could
set up a sensitive switch and a digital counter so that as the widgets go by they activate the switch
and increment the counter. But what you might see is that the first widget produces a count of
47, the second widget causes a count of 113, and so forth. What's going on? The answer is you're
not counting widgets; you're counting how many times the contacts bounced each time the switch
is activated!
There are several ways to solve the problem of contact bounce (that is, to "de-bounce" the input
signal). Often the easiest way is to simply get a piece of equipment that is designed to accept
"bouncy" input. In the widget example above, you can buy special digital counters that are
designed to accept switch input signals. They do the de-bouncing internally. If that is not an
option, then you will have to do the debouncing yourself using either hardware or software.
A simple hardware debounce circuit for a momentary N.O. push-button switch is show in Figure
2. As you can see, it uses an RC time constant to swamp out the bounce. If you multiply the
resistance value by the capacitance value you get the RC time constant. You pick R and C so that
RC is longer than the expected bounce time. An RC value of about 0.1 seconds is typical. Note
the use of a buffer after the switch to produce a sharp high-to-low transition. And remember that
the time delay also means that you have to wait before you push the switch again. If you press it
again too soon it will not generate another signal.
____________________________________________________________________________________________
Page 4 of 7
MIP Lab National University Roll No: __________
Lab #
(EL303)
of Computer and Emerging Sciences
Chiniot-Faisalabad Fall 2019
06
_________________________________________________________________________________
The idea is that as soon as the switch is activated the Debounce Routine (DR) is called. The DR
calls another subroutine called DELAY which just kills time long enough to allow the contacts
to stop bouncing. At that point the DR checks to see if the contacts are still activated (maybe the
user kept a finger on the switch). If so, the DR waits for the contacts to clear. If the contacts are
clear, DR calls DELAY one more time to allow for bounce on contact-release before finishing.
A debounce routine must be tuned to your application; the one above may not work for
everything. Also, the programmer should be aware that switches and relays can lose some of
their springiness as they age. That can cause the time it takes for contacts to stop bouncing to
increase with time. So the debounce code that worked fine when the keyboard was new might
not work a year or two later. Consult the switch manufacturer for data on worst-case bounce
times
4. MUL Instruction:
3. DIV Instruction: Syntax: MUL AB
Syntax: DIV AB Effect: AxB, 16-bit result in B= high byte,
Effect: Divide A by B, A=Quotient, A= low byte
B=Remainder The 8051 supports byte by byte multiplication only.
The 8051 supports bytes over byte division only, the The bytes are assumed to be unsigned data.
byte are assumed to be unsigned data.
____________________________________________________________________________________________
Page 5 of 7
MIP Lab National University Roll No: __________
Lab #
(EL303)
of Computer and Emerging Sciences
Chiniot-Faisalabad Fall 2019
06
_________________________________________________________________________________
6.3 EXERCISES:
Design and implement a simple 4 bit calculator that can perform arithmetic operations of two, 4
bit numbers. First number will be provided through first 4 bits of P1, and second number through
the remainnig 4 bits of P1 (input will be provided through SPDT mechanical switches). There
will be 4 push buttons attached to the P0 through which user can enter the required mathematical
operation.
ORG 00H
MOV A,#0FFH;
MOV P1,A;
MOV P0,A;
MOV A,P1;
MOV A,P1;
ANL A,#00001111B;
MOV R0,A;
MOV A,B;
ANL A,#11110000B;
SWAP A;
MOV R1,A;
MOV P2,#0H;
JB P0.7,LABLE1
JB P0.6,LABLE2
JB P0.5,LABLE3
JB P0.4,LABLE4
LABLE1:MOV A,R0
ADD A,R1;
SJMP END1;
LABLE2:MOV A,R0
SUBB A,R1;
SJMP END1;
LABLE3:MOV A,R0
MOV B,R1;
DIV AB;
SJMP END1;
LABLE4:MOV A,R0;
MOV B,R1;
MUL AB;
SJMP END1;
END1:MOV P2,A;
END;
____________________________________________________________________________________________
Page 6 of 7
MIP Lab National University Roll No: __________
Lab #
(EL303)
of Computer and Emerging Sciences
Chiniot-Faisalabad Fall 2019
06
_________________________________________________________________________________
After entering numbers to P1 and selecting operation from P0, user will be able to see the required
result on P2.
Note: While taking the input make sure to debounce the operator switches.
6.4 IN LAB:
Write a program that generates one cycle of a square wave with frequency of 100mHz on port pin
P3.3 with duty cycle depending on the 4-bit input value mentioned on port P2 by the user. User
prepares a 4-bit data over the binary switches, and then sets the control switch to logic 0 and then
back to logic 1 (1-0-1). The user is allowed to mention the value from 0 – 10. For example, if input
value is 1 then duty cycle is 10%, if the value is 2 duty cycle is 20% and so on. If value is 0 then P3.3
is low and if value is greater than or equal to 10 then P3.3 is high.
____________________________________________________________________________________________
Page 7 of 7