Uploaded by salmanjalil577

MPI LAB NO 7

advertisement
LAB MANUAL
Microprocessors and Microcontrollers
LAB NO. 7
09/09/2021
Using Input/Output ports. (open ended lab)
Lab outcomes:
After completing this lab, students will be able to;
 Use ports and individual pins to get input from switch
 Use ports and individual pins to send output to LEDs
 Make assembly language programs that perform tasks according to specific conditions
Corresponding CLO and PLO:
CLO-1, PLO-5
Theory:
Number of I/O ports and pins depends on the model of chip you are using. For example,
ATmega32 has 4 ports: PORTA, PORTB, PORTC and PORTD. Each port has 8 bits.
ATmega328p, which is the chip fitted in Arduino Uno, only has 13 I/O pins and 6 analog input
puns. ATmega2560, which is the chip fitted in Arduino Mega, has 54 I/O pins and 16 analog
input pins. In order to use Arduino boards as circuit board for the ATmega chip, we need to
know which pins of Arduino correspond to which ports of ATmega. We can use the pin circuit
diagrams to find this.
LAB MANUAL
Microprocessors and Microcontrollers
Fig. 1: Pin mapping of Arduino Uno
LAB MANUAL
Microprocessors and Microcontrollers
Fig. 2: Arduino Mega pin mapping
There are three registers associated with each Port. DDRx, PORTx and PINx registers (where x
represents alphabet). DDRx register decides if port is input or output. All 1s in DDRx will make
port x as output port and all 0s will make it input port. When port is selected as output port,
PORTx register is used to send data out of MC. When port is selected as input port, PINx register
is used to get input into MC. I/O ports are bit addressable. Meaning we can use individual pins as
input or output.
LAB MANUAL
Microprocessors and Microcontrollers
Fig. 3: Relations Between the Registers and the Pins of AVR
If we want to attach an active low (0 when switch is pressed) switch to a I/O pin (or port), we can
activate pull-up resistor on that pin (or port). To do that we have to first select that pin (or port)
as input by sending 0 on DDRx register and then sending 1 to PORTx of the same pin (or port)
Fig. 4: The Pull-up Resistor
Alternatively, we can put our own pull-up resistor outside MC. We can also use make active high
input switch.
LAB MANUAL
Microprocessors and Microcontrollers
Fig. 5: Two types of input
For more information, refer to textbook.
Procedure: (Write code, attach Screenshots of simulation and pictures of circuit)
Task 1: Interface an LED on a pin and a switch on another pin. Write a code in assembly such
that when switch is pressed LED turns on and when switch is open, LED turns off.
Task 2: Modify code such that when switch is open LED is blinking with some delay, when
switch is closed, LED is off.
Observations:
Please write your observation after conducting this lab, you have to write in few lines, what
did you learn in this lab
LAB MANUAL
Microprocessors and Microcontrollers
Rubrics
Absent
Student is
unable to
follow the
provided
instructions
properly.
The student
can name the
hardware or
simulation
platform, but
unable to
implement
anything
practically or
on the
software
Ungraded
[0]
0.0
Very Poor
[1-20]
1-5
Demonstration
Category
Percentage
Marks
Date
Date
Student has
followed
instructions
to construct
the
fundamental
schematic/
block
diagram/
code/ model
on the
protoboard/
trainer/
simulation
software.
Student has
constructed
the
functional/
working
schematic/
model/ block
diagram/
code, and
have
successfully
executed the
program/ run
circuit on
software
platform
Fair
[41-60]
11- 15
Good
[61-80]
16- 20
Report not
submitted
Plagiarized
content
presented or
incomplete
submission
Requirements
are listed and
experimental
procedure is
presented
Observations
are recorded
along with
detailed
procedure
Appropriate
computations
or numerical
analysis is
performed
Ungraded
[0]
0.0
Very Poor
[1-20]
0.1 - 2
Poor
[21-40]
3-4
Fair
[41-60]
5-6
Good
[61-80]
7-8
Total Marks
Student
perfectly
implemented a
working
model/ logic/
circuit/ block
diagram/ code
and
successfully
executed the
lab objective
in Realtime or
in a
simulation
environment
and produced
the desired
results
Excellent
[81-100]
21 - 25.0
Instructor’s Signature
Total Marks
Laboratory
Reports
Category
Percentage
Marks
Student can
understand
the provided
laboratory
instructions
and familiar
with the lab
environment
(Trainer/
software/
IDE), but
cannot
implement
on the
platform
practically or
on the
software
Poor
[21-40]
6 - 10
Instructor’s Signature
Correctly
drawn
conclusion
with
exact results
and complete
report in all
respects
Excellent
[81-100]
9 - 10
Download