0% found this document useful (0 votes)
5 views

L3_IntroToMemoryAndComputing

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

L3_IntroToMemoryAndComputing

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

www. Micro Digital Ed.

com
BIHE university

Introduction to Computer Memory


and Computing

The AVR microcontroller


and embedded
systems
using assembly and c

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
Topics
www. Micro Digital Ed. com
BIHE university

• Internal organization of computers


– The different parts of a computer
• CPU
• I/O
• Memory
– Connecting the different parts
• Connecting memory to CPU
• Connecting I/Os to CPU
– How computers work

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
Topics
www. Micro Digital Ed. com
BIHE university

• Internal organization of computers

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
Internal organization of computers
www. Micro Digital Ed. com
BIHE university

• CPU
• Memory
• I/O
– Input
• E.g. Keyboard, Mouse, Sensor
– Output
• E.g. LCD, printer, hands of a robot

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
Memory
www. Micro Digital Ed. com
BIHE university

• Everything that can store, retain, and recall


information.
– E.g. hard disk, a piece of paper, etc.

We need same with computer.

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
Memory characteristics
www. Micro Digital Ed. com
BIHE university

• Capacity
– The number of bits that a memory can store.
• E.g. 128 Kbits, 256 Mbits
• Organization
4 bits
– How the locations are organized 0

128 locations
1
• E.g. a 128 x 4 memory 2

• It has 128 locations, 4 bits each


127

• Access time
– How long it takes to get data from memory

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
Memory Organization
www. Micro Digital Ed. com
BIHE university

Q1: A given memory chip has 12 address pins


and 4 data pins.
– Find the organization
– Find the capacity

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
Memory Organization
www. Micro Digital Ed. com
BIHE university

Q2: A 512K memory chip has 8 data pins.


– Find the organization
– How many address pins does it have?

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
Semiconductor memories
www. Micro Digital Ed. com
BIHE university

• ROM RAM •
– Mask ROM )Static RAM( SRAM –
– PROM (Programmable )Dynamic RAM( DRAM –
ROM) )Nonvolatile RAM( NV-RAM –
– EPROM (Erasable
PROM)
– EEPROM (Electronic
Erasable PROM)
– Flash EPROM

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
Memory\ROM\ Mask ROM
www. Micro Digital Ed. com
BIHE university

• Programmed by the IC manufacturer


• Not user programmable
• Cheap

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
Memory\ROM\ PROM (Programmable ROM)
www. Micro Digital Ed. com
BIHE university

• OTP (One-Time Programmable)


– You can program it only once
– Uses fuses
– Need special equiment

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
Memory\ROM\ EPROM (Erasable Programmable ROM)
www. Micro Digital Ed. com
BIHE university

• UV-EPROM
– You can shine ultraviolet (UV) radiation
to erase it
– Erasing takes up to 20 minutes
– The entire contents of ROM are erased
– Helps prototyping
Disadvantage – You have to remove it
from board to program it 2764

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
Memory\ROM\ EEPROM (Electrically Erasable
www. Micro Digital Ed. com
Programmable ROM) BIHE university

• Erased Electrically RDY/BSY


A12
VCC
WE
NC
– Erased instantly
A7
A6 8K x 8 A8
A5 A9
– Each byte can be erased separately A4
A3
A11
OE
A2 A10
A1 CE
A0 I/O7
Advantage: Can program it while on I/O0 I/O6
I/O1 I/O5
the board I/O2 I/O4
VSS I/O3

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
Memory\ROM\ Flash ROM
www. Micro Digital Ed. com
BIHE university

• Erased in a Flash
• the entire device is erased at once – But
recent modifications allows to erase in chunk
– It has erase block size

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
Semiconductor memories
www. Micro Digital Ed. com
BIHE university

• ROM RAM •
– Mask ROM )Static RAM( SRAM –
– PROM (Programmable )Dynamic RAM( DRAM –
ROM) Nonvolatile ( NV-RAM –
– EPROM (Erasable )RAM
PROM)
– EEPROM (Electronic
Erasable PROM)
– Flash EPROM

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
Memory\RAM\ SRAM (Static RAM)
www. Micro Digital Ed. com
BIHE university

• Made of flip-flops (Transistors)


• Advantages: 2K x 8

– Faster SRAM

– No need for refreshing


• Disadvantages:
– High power consumption
– Expensive
– Lots of transistor needed per flip - flop

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
Memory\RAM\ DRAM (Dynamic RAM)
www. Micro Digital Ed. com
BIHE university

• Made of capacitors
• Advantages:
– Less power consumption
– Cheaper
– High capacity
• Disadvantages:
– Slower
– Refresh needed

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
Memory\RAM\ NV-RAM (Nonvolatile RAM)
www. Micro Digital Ed. com
BIHE university

• Made of SRAM, Battery available, control


circuitry
• Advantages:
– Very fast
– Infinite program/erase cycle
– Non-volatile
• Disadvantage:
– Expensive

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
To read
www. Micro Digital Ed. com
BIHE university

• What kinds of volatile and non volatile memories


are used in avr based Arduino board these days?

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
Connecting memory to CPU
www. Micro Digital Ed. com
BIHE university

• Memory pin out

VCC

GND VCC

8
D0-D7
n
A0-An-1

WE
OE
CS

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
Connecting memory
Writing
Reading memory to CPU
to memory
from
www. Micro Digital Ed. com

Address
BIHE university

Address
CS
CS
OE
Data
Data
WE
WE
Time
Time

VCC

GND VCC

8
D0-D7

CPU n
A0-An-1

WE

OE
CS

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
Connecting I/Os to CPU
www. Micro Digital Ed. com
BIHE university

• CPU should have


lots of pins! Mouse

Network
CPU Keyboard

Sound Card
Graphic Card
AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
Connecting I/Os to CPU using bus
www. Micro Digital Ed. com
BIHE university

Address bus

Data bus
Write
Control bus Read

CPU
I/O 0 I/O 1 I/O 2 I/O n

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
Connecting I/Os and Memory to CPU
www. Micro Digital Ed. com
BIHE university

Address bus

Data bus
Write
Control bus Read

CPU I/O 0 I/O 1 I/O 2 I/O n


VCC

GND VCC

n
A0-An-1
8
D0-D7

WE

OE
CS

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
Connecting I/Os and memory to CPU using bus
www. Micro Digital Ed. com
BIHE university

VCC
0
1

How could we manage it? 2


3

A0-An-1
GND

D0-D7

WE

OE
CS
0
Address bus

Data bus
Write
Control bus Read

CPU
I/O 0 I/O 1 I/O 2 I/O n

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
Connecting I/Os and Memory to CPU using bus
www. Micro Digital Ed. com
(Peripheral I/O) BIHE university

VCC
0
1
..
63

A0-An-1
GND

D0-D7

WE

OE
CS
Address bus

Data bus
Write
Control bus Read
IO/MEM
CPU
I/O 0 I/O 1 I/O 2 I/O n

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
Connecting I/Os and Memory to CPU using bus
www. Micro Digital Ed. com
(Memory Mapped I/O) BIHE university

The logic circuit

VCC
0
1 enables CS
..
How could we make the logic 15
when address is

A0-An-1
GND

D0-D7
circuit? between 0 and

WE

OE
CS
15
Logic circuit
Address bus

Data bus
Solution
Control 1.
bus Write
Write the address range in binary
Read
2. Separate the fixed part of address
3. Using a NAND, design a logic circuit whose output
CPU
activates when the fixed address is given to it.
a7 a6 a5 a4 a3 a2 a1 a0
From address 0  0 0 0 0 0 0 0 0 a4
I/O 16 I/O 17 I/O a5
18 I/OCS
n
To address15  0 0 0 0 1 1 1 1 a6
a7

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
Another example for address decoder
www. Micro Digital Ed. com
BIHE university

• Design an address decoder for address of 300H


to 3FFH.

Solution
1. Write the address range in binary
2. Separate the fixed part of address
3. Design the logic circuit.

a11 a10 a9 a8 a7 a6 a5 a4 a3 a2 a1 a0 a8
a9
From address 300H  0 0 1 1 0 0 0 0 0 0 0 0 a10 CS
a11
To address 3FFH  001111111111

An easy way of
designing

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
Internal parts of computers\CPU
www. Micro Digital Ed. com
BIHE university

• Tasks:
– It should execute instructions
• It should recall the instructions one after another
and execute them

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
Inside the CPU
www. Micro Digital Ed. com
BIHE university

• PC (Program Counter)
• Instruction decoder
• ALU (Arithmetic Logic Unit)
• Registers

PC A
ALU B

CPU C
D
Instruction decoder
registers

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
How computers work 0 31h
31 A [17]
1 C4h BA
A  [6]
www. Micro Digital Ed. com
BIHE university

2 26h

VCC
3 81h
AA+B
[7]A
4 EAh
5 0h

A0-An-1
GND
5h

D0-D7
6

WE
7

OE
CS
Logic circuit
Address bus

Data bus
Write
Control bus Read

ALU
CPU A
B
PC: 10 C
D I/O 16 I/O 17 I/O 18 I/O n
Inst. Dec. registers

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
How computers work 0 31h A [17]
1 C4h BA
A  [6]
www. Micro Digital Ed. com
BIHE university

2 26h

VCC
3 81h AA+B
EAh
[7]A
4
5 0h

A0-An-1
GND
5h

D0-D7
6

WE
7

OE
CS
Logic circuit
Address bus 17

Data bus
Write
Control bus Read

ALU
CPU A
B
PC: 1 C 9

D I/O 16 I/O 17 I/O 18 I/O n


Inst. Dec. registers

31

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
How computers work 0 31h A [17]
1 C4
C4h BA
A  [6]
www. Micro Digital Ed. com
BIHE university

2 26
26h

VCC
3 81h AA+B
EAh
[7]A
4
5 0h

A0-An-1
GND
5
5h

D0-D7
6

WE
7

OE
CS
Logic circuit
Address bus 17
6

Data bus
Write
Control bus Read

ALU
CPU 9
A
B
PC: 1
2
3 C
D I/O 16 I/O 17 I/O 18 I/O n
Inst. Dec. registers

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
How computers work 0 31h A [17]
1 C4h BA
A  [6]
www. Micro Digital Ed. com
BIHE university

2 26h

VCC
3 81
81h
AA+B
[7]A
4 EA
EAh
5 0h

A0-An-1
GND
5h

D0-D7
6

WE
7

OE
CS
7 Logic circuit
Address bus
Eh
Data bus
Write
Control bus Read

+
ALU
E CPU A
9
B
E
5

PC: 4
35 C
D I/O 16 I/O 17 I/O 18 I/O n
Inst. Dec. registers

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
How Instruction decoder works
www. Micro Digital Ed. com
BIHE university

Opcode Operand Opcode Operand

Instruction

Instruction

Operation Code Meaning


000 Ax
0011 0001 0 31h A [17]
1100 0100 1 C4h BA 001 A  [x]
0010 0110 A  [6]
2 26h 010 A  A – register (x)
1000 0001 3 81h AA+B
1110 1010 4 EAh
[7]A 011 AA+x
0000 0000 5 0h 100 A  A + register (x)
0000 0101 6 5h
7
101 AA–x
110 Register (xH)  Register (xL)
111 [x]  A

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
Von Neumann vs. Harvard architecture
www. Micro Digital Ed. com
BIHE university

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.

You might also like