Sunteți pe pagina 1din 32

www. Micro Digital Ed.

com BIHE university

Introduction to Computing
Chapter 0

The AVR microcontroller and embedded systems


using assembly and c

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi

2011 Pearson Higher Education, 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
I/O Memory CPU

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 Mazidi, Naimi, and Naimi

2011 Pearson Higher Education, 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 Mazidi, Naimi, and Naimi

2011 Pearson Higher Education, 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.

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi

2011 Pearson Higher Education, 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
E.g. a 128 x 4 memory has 128 locations, 4 bits each
128 locations

How the locations are organized

4 bits
0 1 2

Access time
How long it takes to get data from memory

127

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi

2011 Pearson Higher Education, Upper Saddle River, NJ 07458. All Rights Reserved.

Semiconductor memories
www. Micro Digital Ed. com BIHE university

ROM
Mask ROM PROM (Programmable
ROM)

RAM
)Static RAM( SRAM
)Dynamic RAM( DRAM Nonvolatile ( NV-RAM )RAM

EPROM (Erasable PROM) EEPROM (Electronic Erasable PROM) Flash EPROM

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi

2011 Pearson Higher Education, Upper Saddle River, NJ 07458. All Rights Reserved.

Memory\ROM\
www. Micro Digital Ed. com

Mask ROM
BIHE university

Programmed by the IC manufacturer

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi

2011 Pearson Higher Education, Upper Saddle River, NJ 07458. All Rights Reserved.

Memory\ROM\
www. Micro Digital Ed. com

PROM (Programmable ROM)


BIHE university

OTP (One-Time Programmable)


You can program it only once

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi

2011 Pearson Higher Education, Upper Saddle River, NJ 07458. All Rights Reserved.

Memory\ROM\
www. Micro Digital Ed. com

EPROM (Erasable Programmable ROM)


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

2764

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi

2011 Pearson Higher Education, Upper Saddle River, NJ 07458. All Rights Reserved.

Memory\ROM\

EEPROM (Electrically Erasable Programmable ROM)


BIHE university

www. Micro Digital Ed. com

Erased Electrically

RDY/BSY A12 A7 A6 A5 A4 A3 A2 A1 A0 I/O0 I/O1 I/O2 VSS

VCC WE NC

Erased instantly Each byte can be erased separately

8K x 8

A8 A9 A11 OE A10 CE I/O7 I/O6 I/O5 I/O4 I/O3

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi

2011 Pearson Higher Education, Upper Saddle River, NJ 07458. All Rights Reserved.

Memory\ROM\
www. Micro Digital Ed. com

Flash ROM
BIHE university

Erased in a Flash the entire device is erased at once

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi

2011 Pearson Higher Education, Upper Saddle River, NJ 07458. All Rights Reserved.

Semiconductor memories
www. Micro Digital Ed. com BIHE university

ROM
Mask ROM PROM (Programmable
ROM)

RAM
)Static RAM( SRAM
)Dynamic RAM( DRAM Nonvolatile ( NV-RAM )RAM

EPROM (Erasable PROM) EEPROM (Electronic Erasable PROM) Flash EPROM

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi

2011 Pearson Higher Education, Upper Saddle River, NJ 07458. All Rights Reserved.

Memory\RAM\
www. Micro Digital Ed. com

SRAM (Static RAM)


BIHE university

Made of flip-flops (Transistors) Advantages:


Faster No need for refreshing

2K x 8
SRAM

Disadvantages:
High power consumption Expensive

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi

2011 Pearson Higher Education, Upper Saddle River, NJ 07458. All Rights Reserved.

Memory\RAM\
www. Micro Digital Ed. com

DRAM (Dynamic RAM)


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 Mazidi, Naimi, and Naimi

2011 Pearson Higher Education, Upper Saddle River, NJ 07458. All Rights Reserved.

Memory\RAM\
www. Micro Digital Ed. com

NV-RAM (Nonvolatile RAM)


BIHE university

Made of SRAM, Battery, control circuitry Advantages:


Very fast Infinite program/erase cycle Non-volatile

Disadvantage:
Expensive

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi

2011 Pearson Higher Education, 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 Mazidi, Naimi, and Naimi

2011 Pearson Higher Education, Upper Saddle River, NJ 07458. All Rights Reserved.

Connecting memory to CPU


www. Micro Digital Ed. com BIHE university

Memory pin out


VCC

GND 8 D0-D7 n A0-An-1

VCC

WE
OE CS

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi

2011 Pearson Higher Education, Upper Saddle River, NJ 07458. All Rights Reserved.

Writing to memory Reading from memory to CPU Connecting memory


www. Micro Digital Ed. com

Address Address CS CS OE Data Data WE WE Time Time


VCC

BIHE university

GND 8 D0-D7

VCC

CPU

n A0-An-1 WE OE CS

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi

2011 Pearson Higher Education, 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

Graphic Card
AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi

Sound Card
2011 Pearson Higher Education, 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
Control bus Read
Write

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

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi

2011 Pearson Higher Education, 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 Control bus Read


Write

CPU
n 8

I/O 0
VCC

I/O 1

I/O 2

I/O n

GND A0-An-1 D0-D7

VCC

WE OE CS

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi

2011 Pearson Higher Education, 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 2

How could we manage it?


A0-An-1 GND D0-D7

WE

OE

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 Mazidi, Naimi, and Naimi

CS
2011 Pearson Higher Education, Upper Saddle River, NJ 07458. All Rights Reserved.

Connecting I/Os and Memory to CPU using bus (Peripheral I/O)


www. Micro Digital Ed. com BIHE university

VCC

0 1 ..

A0-An-1

GND

D0-D7

63

WE

OE

Address bus

Data bus
Write Read Control bus IO/MEM

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

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi

CS
2011 Pearson Higher Education, Upper Saddle River, NJ 07458. All Rights Reserved.

Connecting I/Os and Memory to CPU using bus (Memory Mapped I/O)
www. Micro Digital Ed. com BIHE university

0 1 ..

A0-An-1

GND

D0-D7

WE

OE

How could we make the logic circuit?

15

The logic circuit enables CS when address is between 0 and 15

VCC

Logic circuit

Address bus

Data bus Solution


Write Control 1. bus Write the address range in binary Read 2. Separate the fixed part of address 3. Using a NAND, design a logic circuit whose output activates when the fixed address is given to it.

CPU

From address 0 0 0 0 0 0 0 0 0 I/O 16 To address15 0 0 0 0 1 1 1 1

a7 a6 a5 a4 a3 a2 a1 a0

I/O 17

a4 I/O a5 18 a6 a7

CS

I/O n CS

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi

2011 Pearson Higher Education, 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.

From address 300H 0 0 1 1 0 0 0 0 0 0 0 0 To address 3FFH 001111111111


An easy way of designing

a11 a10 a9 a8 a7 a6 a5 a4 a3 a2 a1 a0

a8 a9 a10 a11

CS

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi

2011 Pearson Higher Education, 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 ALU A B

CPU
Instruction decoder

C D
registers

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi

2011 Pearson Higher Education, Upper Saddle River, NJ 07458. All Rights Reserved.

How computers work


www. Micro Digital Ed. com

0 1

31h 31 C4h 26h 81h EAh 0h 5h

VCC

2 3 4 5

A [17] BA A [6] AA+B [7]A

BIHE university

A0-An-1

GND

D0-D7

WE

OE

Address bus Data bus


Write Control bus Read

Logic circuit

ALU

CPU
PC:
1 0

A B C

D
Inst. Dec.
registers

I/O 16

I/O 17

CS

I/O 18

I/O n

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi

2011 Pearson Higher Education, Upper Saddle River, NJ 07458. All Rights Reserved.

How computers work


www. Micro Digital Ed. com

0 1

31h C4h 26h 81h EAh 0h 5h

VCC

2 3 4 5

A [17] BA A [6] AA+B [7]A

BIHE university

A0-An-1

GND

D0-D7

WE

OE

Address bus 17 Data bus


Write Control bus Read

Logic circuit

ALU

CPU
PC:
1
31

A B C
9

D
Inst. Dec.
registers

I/O 16

I/O 17

CS

I/O 18

I/O n

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi

2011 Pearson Higher Education, Upper Saddle River, NJ 07458. All Rights Reserved.

How computers work


www. Micro Digital Ed. com

0 1

31h C4 C4h 26 26h 81h EAh 0h 5 5h

VCC

2 3 4 5

A [17] BA A [6] AA+B [7]A

BIHE university

A0-An-1

GND

D0-D7

WE

OE

6 Address bus 17

Logic circuit

Data bus
Write Control bus Read

ALU

CPU
PC:
1 2 3

9 A B

D
Inst. Dec.
registers

I/O 16

I/O 17

CS

I/O 18

I/O n

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi

2011 Pearson Higher Education, Upper Saddle River, NJ 07458. All Rights Reserved.

How computers work


www. Micro Digital Ed. com

0 1

31h C4h 26h 81 81h EA EAh 0h 5h

VCC

2 3 4 5

A [17] BA A [6] AA+B [7]A

BIHE university

A0-An-1

GND

D0-D7

WE

OE

Address bus Data bus


Write Control bus Read
+
E

7
Eh

Logic circuit

ALU

CPU
PC:
4 3 5

A 9 B C

E 5

D
Inst. Dec.
registers

I/O 16

I/O 17

CS

I/O 18

I/O n

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi

2011 Pearson Higher Education, Upper Saddle River, NJ 07458. All Rights Reserved.

How Instruction decoder works


www. Micro Digital Ed. com BIHE university

Opcode

Operand Instruction

Opcode

Operand

Instruction
Operation Code 000
0011 0001
1100 0100 0010 0110 1000 0001 1110 1010 0000 0000 0000 0101 0 1 2 3 4 5 6 7 31h C4h 26h 81h EAh 0h 5h

Meaning Ax A [x] A A register (x) AA+x

A [17] BA A [6] AA+B [7]A

001 010 011

100
101 110 111

A A + register (x)
AAx Register (xH) Register (xL) [x] A

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi

2011 Pearson Higher Education, Upper Saddle River, NJ 07458. All Rights Reserved.

Von Neumann vs. Harvard architecture


www. Micro Digital Ed. com BIHE university

Code Memory

Data bus Address bus Control bus


CPU

Data bus Address bus Control bus


Data Memory

Von Neumann architecture

Code Memory

Data Memory

Data bus
CPU

Address bus Control bus

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

S-ar putea să vă placă și