Assignment

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Brac University

Department of Electrical and Electronic Engineering


EEE/ECE365: Microprocessors
Assignment, Fall 2020

Deadline: 11:59pm, December 22, 2020

[You need to solve all of the problems stated below on paper. Each of the problems requires you to
write down a program. Additionally, mention the reason why you are putting all the specific values
in the registers involved. Make sure you submit your assignment in time as the deadline won’t be
extended.]

1. Suppose PORTD.2 is connected to a switch that is normally high. 8LEDs are connected to
PORTC which glow in pairs, i.e., the first two glows with the next two OFF, followed by two
glowing ones with the final two turned OFF. Write a program that toggles PORTC whenever
PORTD.2 goes to high from low.

2. A DC motor has two wires, wire1 is power, connected to PORTC.5 and wire2 is ground,
connected to PORTC.6. If you send 1 to wire1 and 0 to wire2 it rotates in clockwise direction.
But if you send 0 to wire1 and 1 to wire2 instead, it rotates in counter-clockwise direction.
Sending 0 to both means the motor doesn’t rotate. Also, two push buttons are connected to
PORTD.2 and PORTD.3, a 7-segment display is connected to PORTB. You want the 7-
segment display to show 0 to 9 at 2 seconds interval and whenever PD.2 button is pushed, the
display pauses and motor starts rotating clockwise for the next 5 seconds. If you push PD.3
button during this rotation, the motor starts rotating anti-clockwise for 5 seconds. However,
if the PD.3 button is pushed first, the motor rotates anti-clockwise for 10 seconds and in this
case, pushing PD.2 button doesn’t have any effect. Write a code to carry out the operations.

3. The signal pin of an IR sensor is connected to PB.2 of a microcontroller and a 7-segment


display is connected to PORTA. Whenever someone walks past the IR sensor, it sends a
0 to PB.2 and the count being displayed on the 7-segment display increases by one. When
the reading reaches 9, it resets back to zero again. Write a code to make this work. Define
your interrupt to be sensed at falling edge.

4. The signal pin of an IR sensor is connected to PD.2 of a microcontroller and a 7-segment


display is connected to PORTA. Whenever someone walks past the IR sensor, it sends a
1 to PD.2 and the count being displayed on the 7-segment display increases by one. When
the reading reaches 9, it resets back to zero again. Write a code to make this work. Define
your interrupt to be sensed at rising edge.

5. A DC motor has two wires, wire1 is power, connected to PORTC.5 and wire2 is ground,
connected to PORTC.6. If you send 1 to wire1 and 0 to wire2 it rotates in clockwise
direction. But if you send 0 to wire1 and 1 to wire2 instead, it rotates in counter-clockwise
direction. Sending 0 to both means the motor doesn’t rotate. Also a push button is
connected to PORTD.3, 8LEDs are connected to PORTA. You want to make the LEDs
keep glowing together and then turning OFF together at 1s interval until the button is
pushed when the motor starts rotating clockwise for 5seconds. Then it stops and the LEDs
start glowing and turning OFF again. Write a code for it.
6. Write a program to generate a square wave having 10 ms time period and 50% duty cycle
using Timer0. Crystal Frequency is 8MHz and prescaler is 256.

7. Write a program to toggle the PORTB.4 bit continuously every half a second using
Timer1, normal mode and prescaler 1:1024. Crystal Frequency = 8MHz. Use Overflow
method.

8. Write a program to toggle the PORTB.7 bit continuously every 750ms using Timer1, normal
mode and prescaler 1:64. Crystal Frequency = 2MHz. Use Output compare method.

9. Write a program to generate a square wave having 20 ms time period and 50% duty cycle
using Timer0. Crystal Frequency is 8MHz and prescaler is 1024.

You might also like