Professional Documents
Culture Documents
ACFrOgDAR Cu e5isfc2CgeNPpt5E9-5veyuZNn4IjAKG3dq78MB8ONG5U9dwpDia9pn6pMQTEGKcEbp5NtUFZjVLjXdVN OQ9GEEFhG4y9MrWgKHHpIBh TnSNS4zPz7CGk0JPJJloUzbEBIC05
ACFrOgDAR Cu e5isfc2CgeNPpt5E9-5veyuZNn4IjAKG3dq78MB8ONG5U9dwpDia9pn6pMQTEGKcEbp5NtUFZjVLjXdVN OQ9GEEFhG4y9MrWgKHHpIBh TnSNS4zPz7CGk0JPJJloUzbEBIC05
Embedded Systems
CSC504
Microprocessor
and
Microcontoller
Microprocessor Based System
CPU
External RAM, ROM, I/O
(No internal RAM, ROM, I/O ports in the CPU)
Microcontroller
• A smaller computer on a CHIP
• On-chip RAM, ROM, I/O Ports, Timer, Serial Controller…
• Example: Motorola’s 6811, Intel’s 8051, Atmel 32
Microprocessor vs. Microcontroller
Microprocessor Microcontroller
• CPU is stand-alone, RAM, • CPU, RAM, ROM, I/O and timer
ROM, I/O, timer are separate are all on a single chip
Advantages:
Speeding up the data transfer rate,
Permits the designer to implement different bus widths and word
sizes for program and data memory space.
execute instruction in fewer cycles than Von Neumann.
Princeton architecture block diagram
instruction decode
program ROM
Data
Add memory
Variable RAM interface unit Processor and built-
Ctrl in registers
Stack RAM
Harvard architecture block diagram
Data
Add instruction
decode
Ctrl
PC Stack
program ROM Variable RAM
Data
Processor and
built-in Add
registers Ctrl
Microcontrollers
Microcontrollers in embedded systems
• An embedded microcontroller is a chip which is a
computer processor with all it’s support functions
(clocking and reset), memory, and I/O built into
the device.
Control
Power dist
store
Reset
control
Clock and
timing RAM
CPU
Bus Serial
OSC 4 I/O Ports
Control Port
TXD RXD
P0 P1 P2 P3
8051 µC features
• Intel introduced 8051, referred as MCS-51, in
1981
• The 8051 is an 8-bit processor
• The CPU can work on only 8 bits of data at a time
• 1 to 16 MHz clock
• The 8051 has
• 128 bytes of RAM
• 4K bytes of on-chip ROM
• Two timers
• One serial port
• Four I/O ports, each 8 bits wide
• 2 external and 3 internal interrupt sources
Architecture of 8051 microcontroller
Pin description of 8051
8051 CPU Registers
8051 Microcontroller
• Intel introduced 8051, referred as MCS- 51, in 1981.
P2.0 - P2.7 I/O Port 2: Port 2 is an 8-bit bidirectional I/O. Port 2 emits the
high order address byte during fetches from external
program memory and during accesses to external data
memory that use 16 bit addresses.
P3.0 - P3.7 I/O Port 3: Port 3 is an 8 bit bidirectional I/O port. Port 3 also
serves special features as explained.
Pin Description Summary
PIN TYPE NAME AND FUNCTION
RST I Reset: A high on this pin for two machine cycles while the
oscillator is running, resets the device.
ALE O Address Latch Enable: Output pulse for latching the low byte
of the address during an access to external memory.
PSEN* O Program Store Enable: The read strobe to external program
memory. When executing code from the external program
memory, PSEN* is activated twice each machine cycle,
except that two PSEN* activations are skipped during
each access to external data memory.
EA*/VPP I External Access Enable/Programming Supply Voltage: EA*
must be externally held low to enable the device to fetch
code from external program memory locations. If EA* Is
held high, the device executes from internal program
memory. This pin also receives the programming supply
voltage Vpp during Flash programming. (applies for 89c5x
MCU's)
8051
Memory Space
8051 memory-register map
FFFF FFFF FFFF
up to 60 KB SF = Special Function
of external
ROM/
EPROM
up to 64
KB of 00F8 up to 64 KB
external 1000 of external
EPROM/ 21 SF registers RAM
ROM or and 0080
0FFF 007F
128 KB internal
4 KB of RAM
internal
ROM/
EPROM
0000 0000 0000
0000
F0H F7 F0 B
2F 83H DPH
E0H E7 E0 ACC
(16) bit/byte 82H DPL
D0H D7 D0 PSW
addressable
B8H BF B8 IP 81H SP
B0H B7 B0 P3
80H 87 80 P0
1F A8H AF A8 IE
(8) 8-bit registers bank
3 A0H A7 A0 P2
99H SBUF CY AC F0 RS1RS0 OV P PSW
17
4 register banks
External
External
60K
64K 64K
SFR
EXT INT 4K
128
EA = 0 EA = 1 Internal
Direct
Addressing
Only
SFR [ Special Function
Direct & Registers]
Indirect
Addressing
128 Byte Internal RAM
Special Function Registers [SFR]
Special Function Registers [SFR]
Program Status Word [PSW]
C AC F0 RS1 RS0 OV F1 P
Carry Parity
Auxiliary Carry User Flag 1
groups as follows:
1. A total of 32 bytes from locations 00 to 1F BIT Addressable
hex are set aside for register banks and the Area
128 BYTE
stack.
INTERNAL RAM
2. A total of 16 bytes from locations 20H to 2FH Reg Bank 3
are set aside for bit-addressable read/write
Reg Bank 2
memory. Register Banks
3. A total of 80 bytes from locations 30H to 7FH Reg Bank 1
are used for read and write storage, called
Reg Bank 0
scratch pad.
8051 RAM with addresses
8051 Register Bank Structure
Bank 3 R0 R1 R2 R3 R4 R5 R6 R7
Bank 2 R0 R1 R2 R3 R4 R5 R6 R7
Bank 1 R0 R1 R2 R3 R4 R5 R6 R7
Bank 0 R0 R1 R2 R3 R4 R5 R6 R7
8051 Register Banks with address
8051 Programming Model
8051 Stack
• The stack is a section of RAM used by the CPU to store
information temporarily.
• This information could be data or an address
• The CPU can access data in various ways, which are called addressing
modes
1. Immediate
2. Register
3. Direct
4. Register indirect
5. External Direct
Immediate Addressing Mode
• The source operand is a constant.
• The immediate data must be preceded by the pound sign, “#”
• Can load information into any registers, including 16-bit DPTR
register
• DPTR can also be accessed as two 8-bit registers, the high byte DPH and
low byte DPL
Register Addressing Mode
• Use registers to hold the data to be manipulated.
• The low 4 bits (bit0 - bit3) refer to the timer 0, while the high 4 bits (bit4
- bit7) refer to the timer 1.
• GATE1 enables and disables Timer 1 by means of a signal brought to the
INT1 pin (P3.3):
• 1 - Timer 1 operates only if the INT1 bit is set.
• 0 - Timer 1 operates regardless of the logic state of the INT1 bit.
• C/T1 selects pulses to be counted up by the timer/counter 1:
• 1 - Timer counts pulses brought to the T1 pin (P3.5).
• 0 - Timer counts pulses from internal oscillator.
• T1M1,T1M0 These two bits select the operational mode of the Timer 1.
T1M1 T1M0 MODE DESCRIPTION
0 0 0 13-bit timer
0 1 1 16-bit timer
1 0 2 8-bit auto-reload
1 1 3 Split mode
GATE0 enables and disables Timer 1 using a signal brought to the INT0 pin (P3.2):
1 - Timer 0 operates only if the INT0 bit is set.
0 - Timer 0 operates regardless of the logic state of the INT0 bit.
C/T0 selects pulses to be counted up by the timer/counter 0:
1 - Timer counts pulses brought to the T0 pin (P3.4).
0 - Timer counts pulses from internal oscillator.
T0M1,T0M0 These two bits select the operational mode of the Timer 0.
Timer 0 Timer 1
Mode 0 Mode 0
Mode 1 Mode 1
Mode 2 Mode 2
Mode 3
• Timer 0 in mode 0 (13-bit timer):
• This mode configures timer 0 as a 13-bit timer which consists of all 8 bits of TH0 and the lower 5 bits
of TL0. As a result, the Timer 0 uses only 13 of 16 bits. Each coming pulse causes the lower register
bits to change their states. After receiving 32 pulses, this register is loaded and automatically cleared,
while the higher byte (TH0) is incremented by 1. This process is repeated until registers count up 8192
pulses. After that, both registers are cleared and counting starts from 0.
• Timer 0 in mode 1 (16-bit timer)
• Mode 1 configures timer 0 as a 16-bit timer comprising all the bits of both registers TH0
and TL0. That's why this is one of the most commonly used modes. Timer operates in the
same way as in mode 0, with difference that the registers count up to 65 536 as
allowable by the 16 bits.
• Timer 0 in mode 2 (Auto-Reload Timer)
• Mode 2 configures timer 0 as an 8-bit timer. Actually, timer 0 uses only one 8-bit
register for counting and never counts from 0, but from an arbitrary value (0-255)
stored in another (TH0) register.
• Timer 0 in Mode 3 (Split Timer)
• Mode 3 configures timer 0 so that registers TL0 and TH0 operate as separate 8-bit
timers. In other words, the 16-bit timer consisting of two registers TH0 and TL0 is split
into two independent 8-bit timers. This mode is provided for applications requiring an
additional 8-bit timer or counter. The TL0 timer turns into timer 0, while the TH0 timer
turns into timer 1. In addition, all the control bits of 16-bit Timer 1 (consisting of the
TH1 and TL1 register), now control the 8-bit Timer 1. Thus, the operation 16 bit timer
1 is restricted when timer 0 is in mode 3.
Timer Control (TCON) Register
• Only 4 bits of this register are used for this purpose, while rest of them is
used for interrupt control.
•
• The start bit is always one bit, but the stop bit can be
one or two bits
1. SBUF Register
2. SCON Register
3. PCON Register
SBUF Register
• SBUF is an 8-bit register used solely for serial communication.
• For a byte data to be transferred via the TxD line, it must be
placed in the SBUF register.
• The moment a byte is written into SBUF, it is framed with the
start and stop bits and transferred serially via the TxD line.
• SBUF holds the byte of data when it is received by 8051 RxD line.
• When the bits are received serially via RxD, the 8051 deframes it
by eliminating the stop and start bits, making a byte out of the
data received, and then placing it in SBUF.
SCON Register
• Timer 0 Overflow.
• Timer 1 Overflow.
• Reception/Transmission of Serial Character.
• External Event 0.
• External Event 1.
--
• EA : Global enable/disable.
• --- : Reserved for additional interrupt hardware.
Serial Port
INT 0 Pin
Timer 1 Pin