chapter 2 - microcontroller architecture & assembly language
TRANSCRIPT
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
1/41
Chapter
MICROCONTROLLER
ARCHITECTURE & ASSEMBLY
LANGUAGE
PROGRAMMING
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
2/41
PIC 12F508
PIC 16F84A
PIC 16C72
Motorola 68HC05B16
PIC 16F877
Motorola 68000
Microcontroller Packaging and Appearance
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
3/41
PIC microcontrollers in DIP and QFN packages
16-bit 28-pin PDIP PIC24 microcontroller next to a
metric ruler
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
4/41
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
5/41
PIC18 Architecture
Von Neumann Architecture: Fetches instructions and data from a single memory
space
Limits operating bandwidth
Von Neumann
Architecture
8-bit Bus
CPU
Program
& Data
Memory
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
6/41
Harvard Architecture:
Uses two separate memory spaces for program instructions and
data
Improved operating bandwidth
Allows for different bus widths
CPU
Harvard
Architecture
Data
Memory
Program
Memory
8-bit Bus
16-bit Bus
PIC18 Architecture
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
7/41
PIC18 Microcontroller Families
PIC microcontrollers are designed using
the Harvard Architecture which includes:
Microprocessor unit (MPU)
Program memory for instructions
Data memory for data
I/O ports
Support devices such as timers
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
8/41
Microcontroller with the
Harvard Architecture
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
9/41
A Brief History of PIC C
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
10/41
8-bit Architecture Overview
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
11/41
Compare 8-bit PICMCU Architectures
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
12/41
PIC18 Architecture Block Diagram
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
13/41
PIC18F4450 Block Diagram
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
14/41
PIC18F MCU and Memory
2 MB
221
4 KB
212
8 bit
16 bit
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
15/41
Includes Arithmetic Logic Unit (ALU), Registers,
and Control Unit Arithmetic Logic Unit (ALU)
WREG working register
Status register that stores flags
Instruction decoder when the instruction is fetched it goes into
the ID
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
16/41
Registers
Bank Select Register (BSR)
4-bit register used in direct addressing the data memory
File Select Registers (FSRs) 16-bit registers used as memory pointers in indirect addressing
data memory
Program Counter (PC)
21-bit register that holds the program memory address while
executing programs
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
17/41
Control unit
Provides timing and control signals to various
Read and Write operations
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
18/41
Address bus
21-bit address bus for
program memoryaddressing capacity: 2 MB
of memory
12-bit address bus for data
memory addressing
capacity: 4 KB of memory
Data bus
16-bit instruction/data bus
for program memory
8-bit data bus for data
memory
Control signals
Read and Write
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
19/41
Data RAM File Register
In the CPU, registers are used to store information temporarily.
It could be a byte of data to be processed, or an address
pointing to the data to be fetched.
Majority of PIC registers are 8-bit registers.
In the PIC there is only one data type: 8-bit.
The range goes from the MSB (most-significant bit) D7 to the
LSB least-significant bit) D0.
With an 8-bit data type, any data larger than 8 bits must be
broken into 8-bit chunks before it is processed.
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
20/41
WREG register The 8-bit WREG register is the most widely used
register in the PIC micro controller.
WREG stands for working register, as there is only one.
The WREG register is the same as the accumulator inother microprocessors.
The WREG register is used for all arithmetic and logic
instructions.
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
21/41
To understand the use of the WREG register, we will
show it in the context of two simple instructions: MOVE
and ADD.
MOVLW
The MOVLW instruction MOVES 8-bit data into theWREG register. It has the following format:
MOVLW K ;move literal value Kinto WREG
MOVLW 25H ; move value 25Hinto WREG (WREG = 25H)
Is the following code correct?
MOVLW 9H
MOVLW A23H
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
22/41
ADDLW
The ADDLW instruction ADD 8-bit data into the WREGregister. It has the following format:
ADDLW K ;ADD literal value K to WREG
ADDLW 34H ;ADD literal value 34H to WREG
Example:
MOVLW 12H ;move literal value 12Hinto WREG
ADDLW 16H ; add value 16Hinto WREG (WREG = 28H)
ADDLW 32H ; add value 32Hinto WREG (WREG = 60H)
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
23/41
PIC WREG and ALU Using Literal Value
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
24/41
It is the data memory.
Read/Write - Static RAM
Used for data storage, scratch pad and registers for internal use and function
8-bit width
File register (SFRs and GPR)
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
25/41
Register relationship in PIC
PIC File Register
Special Function RegisterGeneral Purpose RAM
EEPROMGP RAM
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
26/41
Register File
concept
All data memory
is part of register
file
Any location indata memory can
be operated
directly
All peripherals
mapped into datamemory as a
series of registers
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
27/41
SFR Special Function Register 8 bit registers
Dedicated to specific functions such as ALU status, timers,serial communication, I/O ports, ADC etc.
Each SFR functions is fixed by the CPU designer at the time of
design and it is used for controlling microcontroller/peripheral
GPR General Purpose Register 8 bit registers
A group of RAM locations in the file register that are used for
data storage.
Larger than SFR
The microchip website provides the data RAM size, which is the same as
GPR size
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
28/41
File Register Size
File Register=
SFR+
GPR
(Bytes) (Bytes) (Bytes)
PIC12F508 32 7 25
PIC16F84 80 12 68
PIC18F1220 512 256 256
PIC18F452 1792 256 1536
PIC18F2220 768 256 512
PIC18F458 1792 256 1536
PIC18F8722 4096 158 3938
PIC18F4550 2048 160 1888
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
29/41
File Registers of PIC12, PIC16, and PIC18
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
30/41
PIC Status Register
To indicate arithmetic conditions It is a 8-bit register
Five bits are used
D0: C Carry Flag
D1: DC Digital Carry Flag
D2: Z Zero Flag
D3: OV Overflow Flag
D4: N Negative Flag
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
31/41
Bits of Status Register
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
32/41
Example 1
Show the status of the C, DC, Z flags after thefollowing addition instruction
MOVLW 38H
ADDLW 2FH
Solution
38H + 2FH = 67HWREG=67H
C=0
DC=1Z=0
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
33/41
Example 2
Show the status of the C, DC, Z flags after thefollowing addition instruction
MOVLW 9CH
ADDLW 64H
Solution
9CH + 64H = 100H WREG= 00H
C=1
DC=1Z=1
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
34/41
Instruction That Affect
Flag Bits
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
35/41
Flag Bits and Decision Making
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
36/41
PIC Data Format and Directives
There is one data type
8 bits
It is the job of the programmer to break down
data larger 8 bits ( 00 to FFH or 0 to 255)
Data type can be positive or negative number
Data format are
Hex (default in PIC)12 or 0x12 or H'12' or 12H or
Binary B'00010010 or
Decimal.12 or D'12 or
ASCIIA'c' or a'c'
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
37/41
Assembler Directives
What is the difference
betweenInstruction and Directives?
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
38/41
Instruction Tells the CPU what to do
Directives (pseudo-instruction) Give directions to the assembler
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
39/41
Assembly language Format
LABEL INSTRUCTION/ OPERAND COMMENT
ASS. DIRECTIVE
START MOVLW 12H ;move literal value 12Hinto
WREG
Label:
use to represent the location of an instruction or a value no
spacing not more than 8 characters including number.
Instruction:
tells the controller what to do. Ex. MOVWF, GOTO..
Assembler directive: tells the assembler suppose to do. Ex. EQU, ORG, END
Operand:
data to operate on / source of data to operate on and its
destination after processing.
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
40/41
PIC Language Fundamental
Please refer to notes
-
8/10/2019 Chapter 2 - Microcontroller Architecture & Assembly Language
41/41
Arithmetic and Logic Instruction
Please refer to notes
Chapter 5: Arithmetic, Logic Instructions and
Programs
Muhammad Ali Mazidi, Rolin D. Mckinlay & Danny Causey (2008).
PIC Microcontroller and Embedded Systems:
Using Assembly and C for PIC18.
Pearson Prentice Hall. (ISBN: 9780136009023)