You are on page 1of 26

Introduction to Microcontrollers

MOKHTAR NIBOUCHE
MOKHTAR.NIBOUCHE@UWE.AC.UK
ROOM 2N36
DEPARTMENT OF ENGINEERING DESIGN AND
MATHEMATICS
FACULTY OF ENVIRONMENT AND TECHNOLOGY
UNIVERSITY OF THE WEST OF ENGLAND
Content
2

Microcontroller Vs Microprocessor.
Architecture of a microcontroller
CPU, Peripherals. I/Os. Memory

Oscillator/Clocking Signals

Watchdog timer

Analogue to Digital Converter

Etc ..

Architecture Type (Von Neumann vs.


Harvard)
Brief overview of the PIC16F877
microcontroller
Microcontroller Vs Microprocessor
3
Microcontroller Vs Microprocessor
4

In order for a microprocessor to be used, other


components such as memory, or components
for receiving and sending data must be added
to it.

Microcontrollers are designed to be all of that in


one. No other external components are needed
for its application
Central Processing Unit (CPU)
5

Monitors and controls all processes inside the


microcontroller.
Consists of several smaller subunits, of which the
most important are:
The Instruction Decoder is a part of the electronics which
recognises program instructions and runs other circuits on
the basis of that.
The instruction set which is different for each
microcontroller family expresses the abilities of this circuit.
Arithmetic and Logic Unit (ALU) performs all mathematical
and logical operations upon data.
Accumulator is a special function register (SFR) closely
related to the operation of the ALU.
Central Processing Unit (CPU)
6

Considered as the brain of the microcontroller


The PSW register or status register provides
information on the status of the number stored in
the accumulator.
Registers and Special Function Registers
7

A register is a memory cell used to store information


(e.g. in an 8-bit microcontroller, a register stores 8
bits). Note that 8 bits make a byte.
The memory cell, which could part of a memory is
accessed using its unique address.
Registers and Special Function Registers
8

Registers dont have any special or predetermined


function.
In addition to these generic registers, every
microcontroller has a number of of special
registers.
The function of these special registers is
predetermined by the manufacturer.
Registers and Special Function Registers
9

Their bits are connected to internal circuits such as


timers, A/D converter, oscillators, ports and others.
SFR registers are directly in command of the
operation of the microcontroller.
The behaviour of the microcontroller follows
changes taking place in one or more SFR registers.
Memory Unit
10

A memory unit is used for data


storage.
A memory slot is called a
memory location.
The content of a memory
location can be accessed using
and an address.
A memory location can either read from or
written to.
A microcontroller can feature several types of
memory units (RAM, ROM, Flash etc ..)
Memory Unit
11

Non Volatile Memory Volatile Memory


Read only memory (ROM) Random access memory

Masked ROM (RAM)


One time Static RAM

programmable memory Dynamic RAM


(OTP) Double Data Rate RAM
UV Erasable
Programmable ROM (UV
EPROM)
Flash memory

Electrically Erasable
Programmable ROM
(EEPROM)
Inputs and outputs (I/Os)
12

A microcontroller will have input and output pins


associated with its internal electronic.
Inputs/outputs or simply I/Os pins are connected
to SFR registers called PORTS.
I/Os represent the interface with the external
world.
Interrupts
13

The purpose of the microcontroller is mainly to


react to changes in its surrounding (events).
The signal (or event) that inform the microcontroller
about any change taking place is called an
interrupt.
Interrupts have a priority.
Interrupts are either internal or external signal
The microcontroller has to deal immediately with
an interrupt (except in some occasions).
Branches to an interrupt service routine (ISR) to
deal with the interrupt.
Interrupts
14

The microcontroller follows a clear process for


dealing with an interrupt:
Acknowledge
Context Save
Activate
Process (branch to the ISR)
Context Restore
Clear
Busses and Communication
15

Internal communication between different the


microcontrollers unit uses busses (a set of wire of
different widths).
There are two types of buses: the address bus and
the data bus.
The address bus consists of as many lines as
necessary for memory addressing.
It is used to transmit the address from the CPU to
the memory.
The data bus is as wide as the data. It is used to
connect all circuits inside the microcontroller.
Busses and Communication
16

To communicate with other peripherals using the input


output ports, two types of communications are possible
Parallel communication (ideal for short distances)
Serial Communication (ideal for long distances)
Serial communications systems are used predominantly
in microcontrollers. The type depends on:
The number of devices the microcontroller has to
exchange data with;
The speed of data exchange;
The distance between devices;
How data is sent and received.
Oscillator/Clocking Signals
17

The oscillator provides the clocking signals to different


circuits of the microcontroller (synchronous operation).
In general is set in a way to use a quartz crystal or a
resonator. It can also operate as a stand alone circuit.
The different circuits within a
microcontroller will generally
run at different rates. The
instructions as well are
executed at different rates.
To deal with this situation, the
clock signal generated by the
oscillator is prescaled or scaled
down.
Watchdog Timer
18

The watchdog timer is an


important peripheral in any
microcontroller.
In the event of a crash, it
resets the CPU.
A watchdog timer is a
timer connected to a
stand-alone RC oscillator
within the microcontroller.
The main unit of a watchdog timer is a counter.
If the watchdog is enabled and if the timer is not
serviced at regular intervals, the watchdog will trigger an
infinite number of resets (counter reaching overflow or
maximum value).
Analogue to Digital Converter
19

Signals external to the microcontroller are analogue.


In order to be processed by the microcontroller, they
need to be converted to digital.
The analogue to digital converter (ADC) converts
analogue signals to digital or binary signals.
The core of an ADC circuit are the sample/hold and
quantisation units.
Timers
20

The main part of a timer is an 8


bits (or 16 bits) special function
register.
Uses an internal quartz oscillator
for its operation.
The timer counts up the pulses
generated by the quartz
oscillator.
The timer can be used to
measure the time between two
events.
When the timer reaches its max value (overflow), an interrupt
can be generated. The register is then reset.
May use an external oscillator. In this case it is called a
counter (instead of timer).
Von Neumann vs. Harvard
21

Microcontrollers featuring a Von-


Neumann architecture (or model) have
only one bus for both data and
instructions (i.e. one memory block and
one 8-bit data bus for an 8-bit micro).
Only a single operation can be
performed by the CPU (simultaneous
operations are not possible).
The CPU can either read an instruction or read/write data
from/to the memory.
As all data is exchanged through these 8 lines, the bus is
overloaded and communication is slow and inefficient.
The Von Neumann architecture is very simple.
Von Neumann vs. Harvard
22

Microcontrollers featuring a
Harvard architecture have
two different busses. As such,
the CPU can read an
instruction and access data
memory at the same time.
One is 8 bits wide and
connects the CPU to a
memory unit (RAM).
The other bus consists of 12, 14 or 16 lines and connects the
CPU to a different memory unit (ROM).
The Harvard architecture is in general more complex
Instruction Set
23

All the instructions that are recognised by a particular


microcontroller (e.g. MOVLW k or CLRW).
The number of these special words depends on the
type of microcontroller.
A reduced instruction set computer or RISC
microcontroller has a small number of instructions. The
microcontroller recognises and executes basic
instructions only (addition, subtraction, etc ..). More
complex operations use a combination of the available
instructions.
A complex instruction set computer or CISC
microcontroller has a higher number of instructions
(200+). Offers higher speed and more complex
instructions.
PIC16F877 Core Features
24

High Performance RISC CPU


Instruction Set 35 instructions
(single cycle instructions except branch)
Operating Frequency 20 MHz
Uses Harvard architecture
Flash Program Memory 8k (14bit words)
Data Memory 368 bytes
EEPROM Data Memory 256
I/O Ports A, B, C, D, E
Capture/Compare/PWM Modules
Three Timers (0, 1 and 2)
PIC16F877 Core Features
25

Interrupts 14
8 input channels, 10-bit Analogue to
digital Converter (ADC)
Synchronous Serial Port (SSP) with SPI
(Master mode) and I2C (Master/Slave)
Universal Synchronous Asynchronous
Receiver Transmitter (USART/SCI)
Watchdog timer
8 Levels Stack
Direct and Indirect Addressing Modes
References/Further Reading
26

PIC Microcontrollers Programming in Basic with Examples,


Chapter 1: World of Microcontrollers available from:
http://www.mikroe.com/chapters/view/74/pic-basic-book-
chapter-1-world-of-microcontrollers/
PIC16F87X Data Sheet 28/40 Pin 8-Bit CMOS FLASH
Microcontrollers. Available from www.microchip.com