Chapter 2 Microntrollers
Chapter 2 Microntrollers
Chapter 2
Embedded Microcontrollers
Abebaw.Z
1
Outline
Embedded Microcontrollers
1. Structure of a basic computer system
Elements of computer
Elements of embedded system
Architectures(Von Neumann and Harvard Architecture)
RISC and CISC
2. CPU families used in microcontrollers
3. Memories
4. Basic I/O devices and technologies
5. Interrupts
2
Structure of a basic computer system
3
Structure of a basic computer system
A Microprocessor
Intel (R) Core i7-3770 CPU 3.4GHz
A Large Memory
(Primary and Secondary)
(RAM, ROM and caches)
Input Units
(Keyboard, Mouse, Scanner, etc.)
Output Units
(Monitor, printer, etc.)
Networking Units
(Ethernet Card, Drivers, etc.)
I/O Units
(Modem, Fax cum Modem, etc.)
4
Structure of a basic computer system
Elements of embedded system
5
Structure of a basic computer system
Elements of embedded system
Processor
Memory
Parallel ports
Serial communication ports
Input interfacing device
Output interfacing device
Timers and counter
Interrupt controller
Power supply, reset and oscillation circuit
6
Structure of a basic computer system
Von Neumann Architecture
Shared memory (data and program )
one data path (both instruction and data)
CPU does one operation at a time
Fetch or read/write
supports simple hardware
Slow
Improved by cache memory
7
Structure of a basic computer system
Harvard Architecture
Separate storage for instructions and data
Separate bus for data and instruction
Simultaneous access to both instructions and data
Programs needed to be loaded by an operator
the processor could not boot itself
8
Structure of a basic computer system
CISC is a Complex Instruction Set Computer
Larger set of instructions.
Easy to program
Many addressing modes causing complex instruction formats.
Instruction length is variable.
Higher clock cycles per second.
Emphasis is on hardware
Slower execution, as instructions are to be read from memory
and decoded by the decoder unit.
Pipelining is not possible.
9
Structure of a basic computer system
RISC Reduced Instruction Set Computer
Smaller set of Instructions.
Difficult to program.
Few addressing modes, fix instruction format.
Low clock cycle per second
Emphasis is on software
Faster execution, as each instruction is to be executed by
hardware.
Pipelining of instructions is possible, considering single clock
cycle
10
CPU families used in microcontrollers
Processor
A Processor is the heart of the Embedded System.
For an embedded system designer knowledge of microprocessor and
microcontroller is a must.
Two Essential Units: Operations
Control Unit (CU), Fetch
Execution Unit (EU) Execute
11
CPU families used in microcontrollers
Classifications of processor
12
CPU families used in microcontrollers
Microprocessor
A microprocessor is a single chip semi conductor device also which is a
computer on chip, but not a complete computer.
Its CPU contains
ALU,
a program counter,
a stack pointer,
working register,
clock timing circuit and
interrupt circuit on a single chip.
Complete micro computer must have
memory usually ROM and RAM,
memory decoder,
oscillator and
a number of serial and parallel ports.
13
CPU families used in microcontrollers
History of microprocessor
1st Generation (4 bit processors)
early 1970 by Intel (Integrated Electronics)
4004 and 4040 4 bit
Followed by:
The 80186 & 80286 (16 bit processor), the 80386 & 80486 (a 32 bit processor), leading to
the Pentium range of microprocessors (64 bit processors) available today. The 80x86 and
Pentium processors have all been designed for use in personal computer type applications
and have large memory maps.
14
CPU families used in microcontrollers
Various microprocessors
Intel Zilog
4004, 4040
8080, 8085 Z80, Z180, eZ80
8086, 8088, Z8, eZ8
80186, 80188 and others
80286, 80386
x86-64
Motorola
6800
6809
68000
G3, G4, G5
15
CPU families used in microcontrollers
Microcontroller
A microcontroller is a functional computer system-on-a-
chip.
It contains a processor, memory, and programmable
input/output peripherals.
Microcontrollers include an integrated CPU, memory (a
small amount of RAM, program memory, or both) and
peripherals capable of input and output.
Computer On The Box
16
CPU families used in microcontrollers
Various microcontrollers
INTEL
8031,8032,8051,8052,8751,8752
PIC
8-bit PIC16, PIC18,
16-bit DSPIC33 / PIC24,
PIC16C7x
Motorola
MC68HC11
17
CPU families used in microcontrollers
Microprocessor vs. Microcontroller
MICROPROCESSOR MICROCONTROLLER
Rapid movements of code and data Rapid movements of code and data
between external memory & MP within MC
It is used for designing general purpose They are used for designing application
digital computers system specific dedicated systems
18
CPU families used in microcontrollers
Embedded processor
19
CPU families used in microcontrollers
Digital signal processor
DSP as a GPP is a single chipVLSI unit.
20
CPU families used in microcontrollers
Application specific system processor (ASSP)
Examples : IIM7100,W3100A
21
CPU families used in microcontrollers
Multi processor system using GPSS
22
PIC
What is PIC?
A family of Harvard architecture
23
Microchip’s MCU families
24
PIC families
25
PIC microcontroller Architecture
26
Some members of PIC18 features
28
PIC18F4520 block diagrams
29
PIC18F4520 ALU
Arithmetic and logic unit
8- bit ALU
75 instruction set
Input operands are
Working register
Content of file register or literals
Result of operation stored in :
Working register
File register
30
PIC18F4520 Working Register
The working Register, W
Inside the CPU
Usually store result of last operation by CPU
31
PIC18F4520 Working Register
What if result exceed 8 bit , for example a case of overflow ?
Will use status register like carry flag, DC flag , zero flag ……to indicate
the condition
Detail of status register will be covered soon
32
PIC18F4520 memory
There are three types of memory in PIC18
• Program Memory
• Data RAM
• Data EEPROM
As Harvard architecture devices, the data and program
memories use separate busses;
this allows for concurrent access of the two memory spaces.
33
Program memory PIC18F4520
Program memory
32 Kbytes of Flash memory
Address range 0000H – 7FFFH
100,000 erase/write cycles
Location 0000H reserved for reset
Location 0008H reserved for high priority interrupt
Location 00018H reserved for low priority interrupt
34
Program memory map
35
Program memory
Program counter
Hold address of next instruction to be executed
21 bit wide
Has three separate 8-bit registers
PCL
Lower Byte
Readable and writable
PCH,
Higher byte (PC<15:8> bits)
Not directly readable or writable
But indirectly through PCLATH register
PCU
Upper byte ,PC<20:16>bits
Not directly readable or writable
But indirectly through PCLATU register
The contents of PCLATH and PCLATU are transferred to the program counter
by any operation that writes PCL.
Similarly, the upper two bytes of the program counter are transferred to
PCLATH and PCLATU by an operation that reads PCL.
36
Stack
31 level of stack
The PC is pushed onto the stack when a CALL or RCALL instruction
or
When an interrupt is Acknowledged.
The PC value is pulled off the stack on a RETURN, RETLW
or a RETFIE instruction.
Note: PCLATU and PCLATH are not affected by any of the
RETURN or CALL instructions.
Use STKPTR (5 bits) to push on or pop from stack
37
STKPTR register
38
Top-of-Stack Access
Only the top of the return address stack (TOS) is
readable and writable
three registers, TOSU:TOSH:TOSL, to hold content
pointed by STKPTR
After a CALL, RCALL or interrupt, the software can read
the pushed value by reading the TOSU:TOSH:TOSL
registers.
Can use user defined software stack. At return time, the
software can return these values to TOSU:TOSH:TOSL and
do a return.
39
Return Stack Pointer (STKPTR)
The stack pointer increments before values are pushed onto
the stack and
decrements after values are popped off the stack.
On Reset, the stack pointer value will be zero
40
Data memory
Implemented as SRAM
12 bit address = 4096 memory space
16 banks that contain 256 bytes
Special Function Registers(SFRs) and
control status of the controller and peripheral functions,
General Purpose Registers (GPRs)
Data storage
Access: Direct, Indirect or Indexed Addressing.
41
Data memory map
42
43
44
Data memory
Access Bank
first 128 bytes of memory (00h-7Fh) in Bank 0
For frequently used data
Default bank when we power up the PIC
For GSR
And the last 128 bytes of memory (80h-FFh) in Block 15
For SFRs
For access efficiency
single cycle operation
No need of BSR(accessed directly by its address)
GPR general purpose registers
available for use by all instructions.
start at the bottom of Bank 0 grow toward SFRs
45
The Special Function Registers (SFRs)
For controlling desired operation of devices.
used by the CPU and peripheral modules
static RAM.
SFRs start at the top of data memory (FFFh) and
extend the top half of Bank 15 (F80h to FFFh).
46
47
Status register
arithmetic status of the ALU
CLRF STATUS
Set the Z bit
48
Basic I/O devices and technologies
Peripherals such as LEDs and keypads are essential
components of microcontroller-based systems
Input devices
Provide digital information to an MPU
Examples: switch, keyboard, scanner, and digital camera
Output devices
Receive digital information from an MPU
Examples: LED, seven-segment display, LCD, and printer
Devices are interfaced to an MPU using I/O ports
49
I/O Interfacing
50
Interfacing and Addressing
I/O ports
Buffers and latches on the MCU chip
Assigned binary addresses by decoding the address bus
Generally bidirectional
Internal data direction registers
To read binary data from an input peripheral
MPU places the address of an input port on the address bus
Enables the input port by asserting the RD signal
Reads data using the data bus
To write binary data to an output peripheral
MPU places the address of an output port on the address bus
Places data on data bus
Asserts the WR signal to enable the output port
51
PIC18F4520 I/O Ports
MCU includes five I/O ports
PORTA, PORTB, PORTC, PORTD, PORTE
Ports are multiplexed
Can be set up to perform various functions
Each I/O port is associated with several SFRs
PORT
Functions as a latch or a buffer
TRIS
Data direction register
Logic 0 sets up the pin as an output
Logic 1 sets up the pin as an input
52
Interfacing Output Peripherals
Commonly used output peripherals in embedded systems
LEDs
Seven-Segment Displays
LCDs
Two ways of connecting LEDs to I/O ports
Common Cathode
LED cathodes are grounded
Logic 1 from the I/O port turns on the LEDs
Current is supplied by the I/O port called current sourcing
Common Anode
LED anodes are connected to the power supply
Logic 0 from the I/O port turns on the LEDs
Current is received by the chip called current sinking
53
Interfacing Output Peripherals
55
Seven-Segment Display
Common Anode
All anodes are connected together to a power supply
Cathodes are connected to data lines
Logic 0 turns on a segment
Example: To display the digit 1
All segments except b and c should be off
11111001 = F9H
Common Anode
56
Seven-Segment Display
Common Cathode
All cathodes are connected together to ground
Anodes are connected to data lines
Logic 1 turns on a segment
Example: To display digit 1
All segments except b and c should be off
00000110 = 06H
57
Example
Interfacing Seven-Segment Display to PORTB
Common Anode
Table Look-Up
58
Interfacing Input Peripherals
Commonly used input peripherals
DIP switches, push-button keys, keyboards, and A/D converters
DIP switch
One side of the switch is tied high
To a power supply through a resistor called a pull-up resistor
The other side is grounded
The logic level changes when the position is switched
Push-button key
Same as the DIP switch except that contact is momentary
59
Interfacing Dip Switches
60
Thank you
61