Docsity

EEE20003 Tutorial: GPIO Manipulation and Reaction Timing, Exercises of Microcontrollers

Toggle sidebar
bg1
EEE20003 Tutorial - 2
Q1. The figure below shows some simple devices connected to Port C of a MK20DX128M5.
Write code snippets to do the following without disturbing any other outputs (after the initialisation).
a) Use direct manipulation of the GPIO and PORT registers e.g. PCR, PDDR etc.
Declarations
Initialisation of GPIOs
Enable the clock to the port
Initialise the used device pins.
Initialise the GPIO
Turn on the LED.
Turn off the LED.
Toggle the LED (i.e. if on turn off, if off
turn on).
Change the 7-segment display to 0.
Change the 7-segment display to 5.
Change the 7-segment display to the
value in the integer variable
sevenSegment.
b) Is the LED active-high or active-low?
MK20
PTC0
PTC1
PTC2
PTC4
PTC5
PTC6
PTC7
Encoder
Driver
0
1
2
PTC3
pf2

Partial preview of the text

Download EEE20003 Tutorial: GPIO Manipulation and Reaction Timing and more Exercises Microcontrollers in PDF only on Docsity!

EEE20003 Tutorial - 2

Q1. The figure below shows some simple devices connected to Port C of a MK20DX128M5.

Write code snippets to do the following without disturbing any other outputs (after the initialisation).

a) Use direct manipulation of the GPIO and PORT registers e.g. PCR, PDDR etc.

Declarations

Initialisation of GPIOs

Enable the clock to the port Initialise the used device pins. Initialise the GPIO

Turn on the LED.

Turn off the LED.

Toggle the LED (i.e. if on turn off, if off turn on).

Change the 7-segment display to 0.

Change the 7-segment display to 5.

Change the 7-segment display to the value in the integer variable sevenSegment.

b) Is the LED active-high or active-low?

MK

PTC

PTC

PTC

PTC

PTC

PTC

PTC

Encoder

Driver

PTC

EEE20003 Tutorial - 2

Q2. Write a reaction-timing program in C. The program uses a press button and LED as shown below.

Basic Operation

  • Initialisation
  • Infinite loop …
    • Turn off the LED.
    • Short delay.
    • Turn on the LED.
    • Wait in a loop for the button to be pressed. While waiting increment a counter. The counter value will be proportional to the time taken to press the button. Incorporate a suitable delay in the counting loop.
    • Print the reaction time to the console.
    • Wait for button release

For this exercise assume the existence of a delay1ms() and delayRandomTime() functions.

Port D.

Port C.

Vdd