COMP22712 - Microcontrollers

Welcome to Microcontrollers.
This website will provide you quick access to all COMP22712 resources and will be updated throughout this course unit.


The lab will run in a virtual environment running under Linux. We provide an all-in-one installation script that will compile and install the ARM simulator, Komodo, the virtual I/O GUIs and the compiler under:

Download Virtual Lab Environment

(This is an update supporting interrupts and which shows LEDs - thanks to Veselin for sharing that with us)

We tested the environment on the (Ubuntu) images for VirtualBox provided by the Department of Computer Science.
Follow this link, for the suggested school VMs. Note that you have to log into the Computer Science Wiki.
Of course, you can use your native Linux system for running our lab environment, if you want. And in theory, the lab environment should be executable under Windows using Cygwin, but that is difficult to install and was not tested by us.

The link above includes installation guidelines for setting up a provided image in VirtualBox. It looks like that 2GB RAM is sufficient to run the virtual machine and the lab. We saw a problem importing an image into VirtuaBox, but the process unpacked the virtual disk file, which could then be imported in a new virtual machine (select Linux - Ubuntu64 as the OS). If you have performance issues using the VirtualBox image, look into troubleshooting.

Note that the password to the Computer Science Ubuntu images is Kilburn
You will this also for sudo commands (which we use in our installation script).

Virtual Lab Installation

Its easiest if you load the virtual lab environment
directly into your Linux in a local directory.
Use wget or your browser (inside your Linux VirtualBox) for this.
Note: you can setup a shared folder, but installation may fail when using that for the installation. However, you can use a shared folder to copy data from your host machine into the VM all the way to a local directory.

Then open a shell go into your local directory containing kmd_setup_v2.tar.gz and run:

tar -xzf kmd_setup_v2.tar.gz

cd kmd_setup_v2.1


After the installation, the virtual lab environment is started.
Otherwise, you can start the environment with


You can install the virtual lab environment under native Ubuntu 18.04. For this, change in


<requires lib="gtk+" version="3.24">


<requires lib="gtk+" version="3.22">

The Microcontollers Lab Manual 2021 (Update from March 17)

Introduction and Exercise 1 (Simple I/O)

Simple traffic light example to lear how to talk to peripherals
As an optional extension, you can program this as a reactive state meachine where pedestrians can request their green phase. In this first exercise, we are using a delay loop. In a later exercise, this will be replaced with a hardware timer.

Slides from week1

Exercise 2 (The Terminal Window)

The overall goal of this exercise is to create a simple text output window that looks like a shell or DOS window. That requires a font and we are using 8x8 pixel for each (ASCII) symbol.
The following file provides 7x8 pixel fonts and you can add a zero column in fromt of each symbol as a spacer between characters:


In our execise, we are using zero-terminated (NUL-terminated) strings. A good discussion on how to encode strings is provides in the article The Most Expensive One-byte Mistake – Did Ken, Dennis, and Brian choose wrong with NUL-terminated text strings? by Poul-Henning Kamp.

Slides from week2

Even we are not working with the Hitachi HD44780 LCD controller this year, you may have a look at its datasheet to get an idea how such a device is used.

Slides from week2 (second session)

Slides from week3 (using SVCs)

Slides from week4 (Multiway Branches, Breakpoints, Shift and Rotates, Timers, PWM)

Slides from week5 (Feedback session and Updates)

Slides from week5 (Spectre and Meltdown Security attacks)

Exercise 5 (The Stopwatch)

You will implement a simple two-button stopwatch by reading the millisecond timer register. You can either count in BCD arithmetic or use the following function:


Slides from week6 (Exercise 5 Stopwatch and Interrupts)

A nice description of the ARM status register (from the Internet)

Slides from week6 (Memory latency and real-time)

Slides from week7 (FPGA Research and 3rd year projects)

Slides from week8 (Ex5 Stopwatch feedback session)

Exercise 7 (Keyyboard Scanning)

You will scan the keypad in this exercise and consider that buttons bounce in real world systems.

Slides from week8 (Keyboard scan (hardware only))

Slides from week8 (Keyboard debouncing)

Other Topics

Other topics covered in the introductions that are related to microcontrollers.

How to compute trigonometric functions?

Questions on using PIOs and data-driven state machines

Exercise 8 the Piezzo-buzzer

Multiply and shifting in microcontrollers

Trigonometric functions: the CORDIC algorithm

Scheduling and context-switching

Priorities and interrocess communication

The Project

Introduction Videos










10_Spectre Meltdown.mp4




14_Watchdogs and Instruction Set.mp4