Microprocessor and Interfacing
ECX 4236 - Day School 1
G. S. Nadeera Meedin
B.Tech (Hons), AMIE(SL)
WHY Microprocessor and Interfacing
?
About the Course
Why do we need to learn
Microprocessor / Controllers ?
• The microprocessor is the core of computer
systems.
• Nowadays many communication, digital
entertainment, portable devices, are controlled by
them.
• A designer should know what types of
components he needs, ways to reduce production
costs and product reliable.
The necessary tools for a
Microprocessor / controller
• CPU: Central Processing Unit
• I/O: Input /Output
• Bus: Address bus & Data bus
• Memory: RAM & ROM
• Timer
• Interrupt
• Serial Port
• Parallel Port
Microprocessors :
General-purpose microprocessor
CPU for Computers
No RAM, ROM, I/O on CPU chip itself
Example:Intel’s x86, Motorola’s 680x0
Many chips on mother board
Data Bus
CPU
General-
Serial
Purpose RAM ROM I/O Timer COM
Micro- Port
Port
processor
Address Bus
General-Purpose Microprocessor System
Microcontroller :
A smaller computer
On-chip RAM, ROM, I/O ports...
Example:Motorola’s 6811, Intel’s 8051, Zilog’s Z8 and PIC
16X
CPU RAM ROM
A single chip
I/O Timer Serial
Port Port
Microcontroller
Microprocessor vs. Microcontroller
Microprocessor Microcontroller
CPU is stand-alone, RAM, • CPU, RAM, ROM, I/O and
ROM, I/O, timer are timer are all on a single chip
separate • fix amount of on-chip ROM,
designer can decide on the RAM, I/O ports
amount of ROM, RAM and • for applications in which cost,
I/O ports. power and space are critical
expansive • single-purpose
versatility
general-purpose
Lab Organization
Lab 1 :
• Identify the basic functions available in the AES-51
development board.
• Run the self-test program and familiar with the each functions
of the AES-51 development board.
• Familiar with the 8052 simulator
• Assemble the programs written in Assignment #1 and
observe the results by using AES-51 development board.
Prerequisites
• An understanding of decimal,
hexadecimal and binary number
systems.
• A general knowledge of hardware.
Software Use
• Compiler : ASM 51
http://www.metaice.com/ASM51/ASM51.htm
• Simulator : 8052
http://www.vaultbbs.com/sim8052/download.php
First Assembly Program
• Write a simple Assembly Language
Program (ALP) to perform simple arithmetic
operations.
First Assembly Program
Assembly Language Source File
Builds a symbol table
Translation Process
Machine Language Object File • Translates the source file
• Generates the listing
First Assembly Program :
Source Code
ORG 0000H
MOV R0, #5
MOV A, #6
ADD A,R0
END
First Assembly Program : Assemble
First Assembly Program .LST file
0000 1 ORG 0000H
0000 7805 2 MOV R0, #5
0002 7406 3 MOV A, #6
0004 28 4 ADD A,R0
5 END
VERSION 1.2h ASSEMBLY COMPLETE, 0 ERRORS
FOUND
First Assembly Program : Simulate
Block Diagram
External interrupts
On-chip Timer/Counter
Interrupt ROM for
On-chip Timer 1 Counter
Control program
code RAM Timer 0 Inputs
CPU
Bus Serial
4 I/O Ports
OSC Control Port
P0 P1 P2 P3 TxD RxD
Address/Data
Pin Description of the 8051
P1.0 1 40 Vcc
P1.1 2 39 P0.0(AD0)
P1.2 3 38 P0.1(AD1)
P1.3
P1.4
4
5
8051 37
36
P0.2(AD2)
P0.3(AD3)
P1.5 6 (8031) 35 P0.4(AD4)
P1.6 7 34 P0.5(AD5)
P1.7 8 33 P0.6(AD6)
RST 9 32 P0.7(AD7)
(RXD)P3.0 10 31 EA/VPP
(TXD)P3.1 11 30 ALE/PROG
(INT0)P3.2 12 29 PSEN
(INT1)P3.3 13 28 P2.7(A15)
(T0)P3.4 14 27 P2.6(A14)
(T1)P3.5 15 26 P2.5(A13)
(WR)P3.6 16 25 P2.4(A12)
(RD)P3.7 17 24 P2.3(A11)
XTAL2 18 23 P2.2(A10)
XTAL1 19 22 P2.1(A9)
GND 20 21 P2.0(A8)
Types of Memory
On – Chip Memory
Registers
A
R0
DPTR DPH DPL
R1
R2 PC PC
R3
R4 Some 8051 16-bit Register
R5
R6
R7
Some 8-bit Registers of
the 8051
Stack in the 8051
7FH
The register used to access Scratch pad RAM
the stack is called SP
(stack pointer) register. 30H
2FH
Bit-Addressable RAM
The stack pointer in the 20H
8051 is only 8 bits wide, 1FH Register Bank 3
18H
which means that it can 17H
take value 00 to FFH. 10H
Register Bank 2
When 8051 powered up, 0FH
08H
(Stack) Register Bank 1
the SP register contains 07H
Register Bank 0
value 07. 00H
Special Function Registers
Addressing Modes
Immediate Addressing MOV A,#20h
Direct Addressing MOV A,30h
Indirect Addressing MOV A,@R0
External Direct MOVX A,@DPTR
Code Indirect MOVC A,@A+DPTR
LOOP and JUMP Instructions
Conditional Jumps :
JZ Jump if A=0
JNZ Jump if A/=0
DJNZ Decrement and jump if A/=0
CJNE A,byte Jump if A/=byte
CJNE reg,#data Jump if byte/=#data
JC Jump if CY=1
JNC Jump if CY=0
JB Jump if bit=1
JNB Jump if bit=0
JBC Jump if bit=1 and clear bit
Timers
• Keeping time and/or calculating the
amount of time between events,
• Counting the events themselves, or
• Generating baud rates for the serial
port.
How does a timer count ?
A timer always counts up
How long does a timer take to
count ?
Crystal Frequency : 11.059 MHz
A single machine cycle consists of 12 crystal pulses
A running timer will be incremented
11,059,000 / 12 = 921,583 times per second
If a timer has counted from 0 to 50,000 you may calculate:
50,000 / 921,583 = .0542 Seconds
Timer SFR
SFR Name Description SFR Address
TH0 Timer 0 High Byte 8Ch
TL0 Timer 0 Low Byte 8Ah
TH1 Timer 1 High Byte 8Dh
TL1 Timer 1 Low Byte 8Bh
TCON Timer Control 88h
TMOD Timer Mode 89h
TMOD (89 H)
Bit Name Explanation of Function Timer
When this bit is set the timer will only run when INT1
7 GATE1 (P3.3) is high. When this bit is clear the timer will run 1
regardless of the state of INT1.
When this bit is set the timer will count events on T1
6 C/T1 (P3.5). When this bit is clear the timer will be 1
incremented every machine cycle.
5 T1M1 Timer mode bit (see below) 1
4 T1M0 Timer mode bit (see below) 1
When this bit is set the timer will only run when INT0
3 GATE0 (P3.2) is high. When this bit is clear the timer will run 0
regardless of the state of INT0.
When this bit is set the timer will count events on T0
2 C/T0 (P3.4). When this bit is clear the timer will be 0
incremented every machine cycle.
1 T0M1 Timer mode bit (see below) 0
0 T0M0 Timer mode bit (see below) 0
Timer Modes
TxM1 TxM0 Timer Mode Description of Mode
0 0 0 13-bit Timer.
0 1 1 16-bit Timer
1 0 2 8-bit auto-reload
1 1 3 Timer mode
TCON SFR
Bit Time
Bit Name Explanation of Function
Address r
Timer 1 Overflow. This bit is set by the
7 TF1 8Fh 1
microcontroller when Timer 1 overflows.
Timer 1 Run. When this bit is set Timer 1
6 TR1 8Eh is turned on. When this bit is clear Timer 1 1
is off.
Timer 0 Overflow. This bit is set by the
5 TF0 8Dh 0
microcontroller when Timer 0 overflows.
Timer 0 Run. When this bit is set Timer 0
4 TR0 8Ch is turned on. When this bit is clear Timer 0 0
is off.
TCON SFR
Bit Time
Bit Name Explanation of Function
Address r
Timer 1 Overflow. This bit is set by the
7 TF1 8Fh 1
microcontroller when Timer 1 overflows.
Timer 1 Run. When this bit is set Timer 1
6 TR1 8Eh is turned on. When this bit is clear Timer 1 1
is off.
Timer 0 Overflow. This bit is set by the
5 TF0 8Dh 0
microcontroller when Timer 0 overflows.
Timer 0 Run. When this bit is set Timer 0
4 TR0 8Ch is turned on. When this bit is clear Timer 0 0
is off.
Using Timers
• Initializing a Timer
• Reading the value of a Timer
Or
• Detecting Timer Overflow
• Timing the length of events
Port 0 with Pull-Up Resistors
Vcc
10 K
P0.0
Port
DS5000 P0.1
P0.2
8751 P0.3
8951 P0.4 0
P0.5
P0.6
P0.7
Course Summary
Learn a lot
… and have fun doing it!