You are on page 1of 29

Chapters 0 and 1

• 1st hour: Chapter 0: review


• 2nd hour: Chapter 1: intro to MCU
• Administrative:
• textbook:
M. Mazidi, J. Mazidi, and R. McKinlay,
The 8051 Microcontroller and Embedded
Systems Using Assembly and C,
Pearson International Edition, 2006. ISBN:
0-13-197089-5
Number systems
• Numbers vs. Numerals
• Number = value
• Numeral = text representation of number
• Base of a numeral
• Decimal: Base 10, Binary: Base 2
• Octal: Base 8, Hexadecimal: Base 16
Mapping
decimal binary octal hex Roman
0 0000 0 0 ??
1 0001 1 1 I
2 0010 2 2 II
3 0011 3 3 III
4 0100 4 4 IV
5 0101 5 5 V
6 0110 6 6 VI
7 0111 7 7 VII
8 1000 10 8 VIII
9 1001 11 9 IX
10 1010 12 A X
11 1011 13 B XI
12 1100 14 C XII
13 1101 15 D XIII
14 1110 16 E XIV
15 1111 17 F XV
2's complement
• to represent negative numbers
• "flip all bits and add one"
• example: (assume 8-bit words)
• 1 as binary: 00000001
• -1 is binary: 11111110 + 1 => 11111111
• Reason: use the same adder for + or -
• test: 00000001 + 11111111 = 00000000
(ignore the carry, keep only lower 8 bits)
Character
representation
• ASCII (American Standard Code for
Information Interchange)
Dec Char Dec Char Dec Char Dec Char Dec Char Dec Char
33 ! 49 1 65 A 81 Q 97 a 113 q
34 ~ 50 2 66 B 82 R 98 b 114 r
35 # 51 3 67 C 83 S 99 c 115 s
36 $ 52 4 68 D 84 T 100 d 116 t
37 % 53 5 69 E 85 U 101 e 117 u
38 & 54 6 70 F 86 V 102 f 118 v
39 ' 55 7 71 G 87 W 103 g 119 w
40 ( 56 8 72 H 88 X 104 h 120 x

41 ) 57 9 73 I 89 Y 105 i 121 y
42 * 58 : 74 J 90 Z 106 j 122 z
43 + 59 ; 75 K 91 [ 107 k 123 {
44 , 60 < 76 L 92 \ 108 l 124 |
45 - 61 = 77 M 93 ] 109 m 125 }
46 . 62 > 78 N 94 ^ 110 n 126 ~
47 / 63 ? 79 O 95 _ 111 o 127 _
48 0 64 @ 80 P 96 ` 112 p
Digital Logic

AND NAND
1 1 1
3 3 3
2 2 2

OR NOR
1 2 2
3 1 1
2 3 3

INVERT 1 2
buffer 1 2

XOR 1

2
3 Tristate 1

3
2
Combinational Logic vs.
Sequential Logic
• Combinational
• no memory ("stateless"); pure function
• e.g., AND gate, OR gate, connected w/out
cycle
• Sequential
• has memory ("stateful")
• built by combinational logic with feedback
Examples of
Combinational Logic
choose 1
mux
from n
from 1 to
demux
one of n
binary to
decoder
unary
A
sum and
bit-adder B
Sum

carry
Cout
Cin
Examples of Sequential
Logic
D Q

• D-latch Clk
• remembers a new value every clock edge
• D-flipflop
• remembers new value on clock edge AND
write-enable ("load")
D Q
load
Clk
Synchronous vs.
Asynchronous logic
• Both are sequential
• Synchronous:
• happens only with clock event
(rising edge or falling edge)
• Asynchronous
• not dependent on clock; happens any time
• Most of the time, we use synchronous logic
More example of
sequential logic count

• Counter load
1
• each time, add 1 adder D Q
• possible to reset clk

• option to load
• How to build it
• D-register with +1 feedback
Memory
• Conceptually: group of multiple D-flipflops
• Access to elements
• Random access: give address
• Sequential access: FIFO, LIFO (stack), ...
• R/W
• Read-only (can be viewed as combinational)
• Read-Write
Register file
Example with
Rw<4:0> Ra<4:0>
32 registers
(5-bit addressable) D<31:0>
Write load Q

1:32 demux
Enable clk
Write Rw Ra

32:1 mux
Enable 5 5 D<31:0>
busA load Q busA
clk <31:0>
busW 32 32-bit 32 busW
32 D<31:0>
Registers
Clk Clk load Q
clk

contains 32 registers, 3 shown


Bus
• Shared electrical connection
• Data, address, control
• Internal or external
• Serial or parallel
• How to share?
• Tri-state output to bus
1 2

output
• Arbitration policy enable
(master-slave, peer-to-peer, etc)
ALU: Arithmetic and Logical
Unit
• Data inputs (example: 32 bits)
– AInput, BInput: operands
• Control signal (3 bits for up to 8 operators)
– ALUCtl: add, addu, sub, subu, and, or, xor, nor
ALUctl
• Data output 3
AInput
N,Z,C,V
– Result: 32-bits 32
ALU 32
– N, Z, C, V flags Result
BInput
32
What's inside an ALU?
• Giant mux that inputs from Adder,
addu'er, ... ALUctl

AInput add AddOut


AdduOut
addu
SubOut
sub

8:1 mux
<35:32>
SubuOut MuxOut N,Z,C,V
subu
Result
AndOut <35:0>
and <31:0>
OrOut
or
XorOut
xor NorOut

BInput nor
16
Detailed connection of each unit
• Giant mux that inputs from Adder,
addu'er, ... ALUctl

AInput add AddOut


AdduOut
addu
SubOut
sub <35:32> N,Z,C,V

8:1 mux
SubuOut
AInput
add subu MuxOut
Result
AddOut
NZCV AddOut AndOut <35:0>
<35:32> and <31:0>
<35:0>
OrOut
<31> or
BInput + AddOut xor
XorOut
NorOut
<31:0>
BInput nor
17
Structure of a CPU
Reg
• Datapath file
ALU
• ALU
• Register file I/O Data memory
• Control
• Instruction decoder
• Program counter
• Program & Data memories, I/O
Chapter 1: 8051
• Microprocessors vs. MCU
• Advantages of MCUs
• Embedded systems
• Choose a microcontroller
• Speed, packaging, memory & cost per unit
• Various members of 8051 family
• Various manufacturers of 8051
CPU vs. MCU vs.
embedded microproc.
• Microprocessor, a.k.a. CPU
• general purpose, usually w/out memory, I/O
• Microcontroller (MCU)
• CPU + integrated I/O for embedded apps
• usually simpler (no MMU, no Floating Point)
• Embedded Microprocessor
• usually means higher-end CPU used in
embedded applications
8-bit MCU instruction-
set architectures
• Older
• 6811 (formerly Motorola, now Freescale)
• 8051 (Intel), Z8 (Zilog), PIC 16 (Microchip)
• Newer
• ATMega (Atmel)
• Hitachi H8
• 8-bit means registers (native data size) 8 bits
Block diagram of 8051
Why 8051 is still popular
after 25 years
• Intel allows others to make compatible MCUs
• Atmel, Philips/Signetics, Siemens, Dallas
Semiconductor
• New and improved
• Silicon Labs (100MHz! low power, hi-perf)
• Free designs available!
• integrated RF (e.g., Nordic nRF24E1,
Chipcon CC2430, RadioPulse RG2400...)
8051 Family
Feature 8051 8052 8031
ROM (on chip program
4K 8k 0k
space in bytes)
RAM (bytes) 128 256 128
Timers 2 3 2
I/O pins 32 32 32
Serial port 1 1 1
Interrupt sources 6 8 6
Question: how to
program?
• Make ROM (cheap if large quantity)
• Problem: you cannot change the program!
• Make writable ROM
• PROM: (P=programmable) write-once
• EEPROM: electrically erasable PROM
• UV-EPROM: erasable w/ultraviolet(UV) light
• Flash: a type of EEPROM
• NV-RAM: non-volatile RAM
EEPROM Programmer
and UV-Eraser
Flash memory
• NAND-flash
• cheaper, page access, erase whole page
before writing
• good for data (e.g., digital camera)
• NOR-flash
• word addressable, more expensive
• good for MCU program (firmware)
• Limited number of rewrite cycles (10,000)
Package types
• DIP (dual-inline package)
• used in breadboards
• PLCC (plastic leadless chip carrier)
• removable from socket socket

• BGA (ball-grid array)


• connect on bottom
• SMT (surface mount)
• small or no leads
Choosing a
Microcontroller
• Computing needs
• Speed, packaging, power consumption,
RAM, ROM, I/O pins, timers, radio, cost
• Voltage: TTL, CMOS, NMOS, ...
• Software development tools
• Assembler, debugger, C compiler, emulator,
technical support
• Availability & source

You might also like