You are on page 1of 45

‫بسم هللا الرمحن الرحمي‬

EE366
Microprocessors and
Microcontrollers
Lecture 04
Basic Computer Architecture
• CPU (Central Processing Unit)
• Memory
• Input/Output
Buses

I/O CPU Memory


The CPU
• Purpose: The controlling element in a computer
system that performs data transfers, integer
arithmetic and logic, and input/output operations.
• Sizes: 4-bits to 64-bits
• Speeds: up to several GHz
• A byte is 8-bits
• Memory is addressed by byte
• RISC vs. CISC
CPU Task
• Executes instructions from the memory
system.
• A program is a collection of instructions stored
sequentially in the memory.
• A program is the computer’s software.
• The stored program concept makes the
computer fast and powerful.
Data Transfer Operations
• Most of a CPUs time is spent transferring data.
• Data transfers include: instruction fetches,
transfers between memory and registers,
transfers between registers and I/O.
• Transfers occur though the data bus.
Arithmetic and Logic Operations
• The CPU performs arithmetic on integers using
addition, subtraction, multiplication, and
division (some microcontrollers do not divide).
• Logic operations include AND, OR (inclusive and
exclusive), NOT, and shift/rotate.
Decisions
• The CPU makes decisions based upon numeric
facts to control the flow of a program.
• Zero—Not Zero, Positive—Negative, Carry—
No Carry .
• Decisions modify the flow of a program.
• Flow control allows tasks to be repeated or
skipped.
Memory
• Memory in a computer system is normally
numbered in bytes.
• Memory is accessed using a memory address
(address bus) numbered from memory location
00000000.
• Memory addresses are expressed in the
hexadecimal numbering system (radix 16).
• Memory data flow through the data bus.
Data Bus
• The data bus is 4-, 8-, 16-, 32-, or 64-bits in
width in modern computers.
• The size of the CPU and its data bus are the
same or in some cases the data bus may be
twice as wide as the CPU size.
• A 16-bit computer has a 16-bit data bus.
• The Pentium 4 is a 32-bit computer with a 64-
bit data bus.
Address Bus
• The address bus selects a memory location or an I/O
device
• The size (number of bits) of the address bus
determines the maximum memory size.
• An 8-bit address can address 256 bytes of memory
(28).
• 1K = 1024 and requires a 10-bit address
• 1M = 1024 * 1024 and requires a 20-bit address
• 1G = 1M * 1024 and requires a 30-bit address
• 1T = 1G * 1024 and requires a 40-bit address
Control Bus
• The control bus controls memory and I/O.
• The control bus contains two main signals that
originate from the CPU.
• The #RD signal causes a read operation.
• The #WR signal causes a write operation.
• Some CPUs also contain a signal that selects
memory or I/O called M/#IO.
ROM
• A ROM (Read-Only Memory) is a nonvolatile
memory that is used to store programs and static
data
• The ROM is usually either an EPROM or an
EEPROM (Electrically Erasable Programmable
Read-Only Memory) memory.
• The EPROM is erased using an ultraviolet lamp.
• The EEPROM is erased electrically
• In either device, memory does not change when
power is removed from the system.
RAM
• The RAM is the read/write memory in a system that
stored dynamic data and will not retain data without
power.
• RAM is available as either SRAM or DRAM.
• SRAM stores data as long as power is applied.
• DRAM must be refreshed because it only stores data
for a few milliseconds.
RAM
• RAM generally store a bit of data in either the state
of a flip-flop, as in SRAM (static RAM), or as a charge
in a capacitor (or transistor gate), as in DRAM
(dynamic RAM),
• Large memory system usually use DRAM and small
memory systems usually use SRAM.
I/O
• The I/O in a computer allows the CPU and its
program to communicate to humans and
machines.
• A input device inputs data to the CPU and
examples include keyboards and switches.
• An output device accepts data from the CPU
and examples include printers, indicators, and
so forth.
• I/O data is often 8-bits in width.
Choosing a microcontroller
• There are 5 major 8-bit microcontrollers
• Freescale (Formerly Motorola)
68HC08/68HC11
• Intel 8051
• Atmel AVR
• Zilog Z8
• Microchip PIC

17
The PIC Families

18
The PIC Microcontroller
• The PIC stands for (Peripheral Interface Controller).
• Microchip introduced in 1989 its first microcontroller.
• It was a humble 8 pin device.
• Now microchip is a leading microcontroller manufacturer.
• There are different PIC microcontrollers:
– PIC with UV-EPROM
– PICxxFxx (Flash type)
– OTP (one-time-programmable)
• Example PIC16C432
– Masked version of PIC

19
Microchip 8-bit PIC Microcontrollers

20
Microchip 8-bit PIC Microcontrollers

21
The PIC in Class and Lab
• The PIC18F is the top of the line of 8-bit PIC
microcontrollers .
• In class we will concentrate on PIC18F.
• A good understanding of PIC18F will make it easy
to handle other 8-bit PIC microcontrollers.
• In the lab (lab 1 to 7) we will mainly use:
– The 20-Pin 8-Bit Microcontroller PIC16F690
– The 40 pin PIC16F917 which is an 8-Bit
Microcontrollers with LCD Driver
• In projects we will use the PIC18F

22
The PIC18 Architecture
• The PIC18 is an 8-bit family of microcontrollers
from Micro Chip that contain a
microprocessor, program memory, data
memory, and I/O ports.
• The PIC18 is a self-contained computer system
that rarely requires additional memory or I/O.
Example System

LCD Display

Optical Card
PIC18 Reader
Microcontroller

Keyboard

Serial Interface to
Host
Internal PIC18 Architecture
• Harvard Architecture: Separate program and
data memories.
• Program memory is 16-bits wide
• Data memory is 8-bits wide
• At least 16 I/O pins (two 8-bit named ports A
and B)
• Internal program stack (31 x 21)
26
I/O
Data Ports
Memory
8 wires

31 x 21
Stack Memory Timers

21 wires

Clock 8-bit CPU


Generation

8 wires Analog to
Digital
16 wires Converter

Program
Memory
Serial
Ports

Data
EEPROM
Other
8 wires
Peripherals
PIC Registers
• PIC have many registers.
• Registers are used for arithmetic and logic
operations.
• The Majority of PIC registers are 8-bits registers
• The PIC has one data type: 8-bit.
• Any data larger than 8 bits must be broken into 8-
bit chunks' before processing
D7 D6 D5 D4 D3 D2 D1 D0

MSB LSB
28
The WREG Register
• The working register called WREG or W is the most
important register or register file location in the
microcontroller.
• This register is used by most instructions in the
instruction set to hold the result from an operation
and also one of the numbers operated upon.
• Most computers contain a WREG often called an
accumulator.
• The WREG register is at address 0xFE8.
The WREG Register
MOVLW Instruction:

MOVLW K ;move literal value K into WREG

MOVLW 32H ;move 32H into WREG

30
The WREG Register
ADDLW Instruction:

ADDLW K ;add literal value K to WREG

MOVLW 32H ; load 32H into WREG


ADDLW 25H ; add 25H to WREG

Result WREG = 57H (32H + 25H = 57H)

31
The WREG Register
REMARKS:

• MOVLW 8H identical to MOVLW 08H


• Moving a value larger than 255 (FF in hex) to WREG will
truncate the upper byte and cause a warning in the .err
file.
• MOVLW 3A5H ; ILLEGAL 3A5H > 8 bits (FFH)

• ( WREG = A5H)

32
The PIC File Register
• The PIC has many other registers in addition to the
WREG register.
• They are called Data Memory Space to distinguish
them from Program Memory Space.
• Data Memory is called file register.
• The file register is read/write memory used by the
CPU for data storage, scratch pad, internal use and
functions
The PIC File Register
• File register size ranges from 32 bytes to several
thousands.
• Arithmetic & logic operation can be performed on
many location of the file register.
• The file register RAM is divided into two sections:
– SFR (Special Function Registers)
– GPR (General Purpose RAM)
SFRs (Special Function Register)
• Dedicated to specific functions (ALU status, timers,
serial communication, I/O ports, ADC, etc)
• The function of each SFR is fixed.
• The number of SFRs is different for each chip
depending on pin numbers and peripherals.
• The 8-pin PIC12F508 has 7 SFR
• The 40-pin PIC18F458 has 256 SFR
GPR (General-Purpose RAM)
• 8-bit RAM locations used for data storage and
scratch pad.
• The size of GPR is different for each chip.
• Larger GPR means more difficulty with Assembly.
• Larger GPR is better for C.
• The 8-pin PIC12F508 has 25 Bytes GBR ( 7 SFR + 25
GPR = 32 Byte File Register).
• Microchip provides data for RAM size as GPR size
(PIC12F508 has 25 Bytes RAM)
• The 40-pin PIC18F458 has 1536 Bytes GBR ( 256 SFR
+ 1536 GPR = 1792 Byte File Register).
GPR (General-Purpose RAM)
• We have GPR (RAM) + Flash (Program Memory) +
Data EEPROM (can also be added Externally)

Example: PIC 18F458

Parameter Name Value


Program Memory Type Flash
Program Memory (KB) 32
CPU Speed (MIPS) 10
RAM Bytes 1,536
Data EEPROM (bytes) 256
Pin Count 40
File Registers for PIC12, PIC16 and
PIC18

38
File Registers for PIC18 Family

• Can have a maximum of 4096 (4K) bytes


• Has address 000H to FFFH
• Divided into 256 bytes banks
• Maximum is 16 Banks ( 16 X 256 = 4096 )
• Every PIC18 has a default bank called access
bank.
• Is the access bank bank 0, 1, … ?

39
The Access Bank
• The access bank is divided equally (128 Byte
each) between SFR & GPR.
• Locations 00H to 7FH for GPR.
• GPR can be accessed directly by its address.
• Used to store I/O and serial ports data, timer
data, etc.
• Locations F80H to FFFH for SFR.
• SFR is at is at the last portion of file register.
40
File Registers for PIC18 Family

• Memory space for SFRs and GPRs not


contiguous?
• This is to allow location 080H to F7FH to be
used for GPR by various members of PIC18
family.
• A file register more than 256 bytes necessitate
bank switching

41
File Registers for PIC18 Family

42
SFR for PIC18 Family

43
DATA MEMORY MAP FOR PIC18F2580/4580 DEVICES

44
PIC Registers
0xFE0 Bank Select Register (BSR)

0xFE8 Accumulator (WREG)

0xFF4 Product High (PRODH)


0xFF3 Product Low (PRODL)

0xFEA File Select Register 0 High (FSR0H)


0xFE9 File Select Register 0 Low (FSR0L)

0xFE2 File Select Register 1 High (FSR1H) Major Special


0xFE1 File Select Register 1 Low (FSR1L)
Function Registers
0xFDA File Select Register 2 High (FSR2H)
0xFD9 File Select Register 2 Low (FSR2L)

0xFD8 Status Register (SR)

Program Counter (PC)


8-Bits
8 bits

Note: The program counter is an internal 21-


bit physical register that is not addressable.

You might also like