Professional Documents
Culture Documents
General-purpose microprocessor
• CPU for Computers
• No RAM, ROM, I/O on CPU chip itself
• Example : Intel’s x86, Motorola’s 680x0
Data Bus
CPU
General-
Serial
Purpose RAM ROM I/O Timer COM
Micro- Port
Port
processor
Address Bus
Microcontroller :
• A smaller computer
• On-chip RAM, ROM, I/O ports...
• Example : Motorola’s 6811, Intel’s 8051, Zilog’s Z8 and
PIC 16X
Microprocessor Microcontroller
• CPU is stand-alone, RAM, • CPU, RAM, ROM, I/O
ROM, I/O, timer are and timer are all on a
separate single chip
• designer can decide on the • fix amount of on-chip
amount of ROM, RAM and ROM, RAM, I/O ports
I/O ports. • for applications in which
• expansive cost, power and space
• versatility are critical
• general-purpose • single-purpose
Embedded System
External interrupts
On-chip Timer/Counter
CPU
Bus Serial
4 I/O Ports
OSC Control Port
P0 P1 P2 P3 TxD RxD
Address/Data
Registers
. A
R0
DPTR DPH DPL
R1
R2 PC PC
R3
R5
R6
R7
MOV DPTR,#7634H
MOV DPL,#34H
MOV DPH,#76H
Note 1:
MOV A,#72H ≠ MOV A,72H
After instruction “MOV A,72H ” the content of 72’th byte of RAM will replace in Accumulator.
8086 8051
MOV AL,72H MOV A,#72H
MOV AL,’r’ MOV A,#’r’
MOV BX,72H
MOV AL,[BX] MOV A,72H
Note 2:
MOV A,R3 ≡ MOV A,3
SETB bit ; bit=1
CLR bit ; bit=0
SETB C ; CY=1
SETB P0.0 ;bit 0 from port 0 =1
SETB P3.7 ;bit 7 from port 3 =1
SETB ACC.2 ;bit 2 from ACCUMULATOR =1
SETB 05 ;set high D5 of RAM loc. 20h
Note:
SETB C ;CY=1
SUBB A,R5 ;A=A-R5-1
SETB C ;CY=1
ADC A,R5 ;A=A+R5+1
DEC byte ;byte=byte-1
INC byte ;byte=byte+1
INC R7
DEC A
DEC 40H ; [40]=[40]-1
RR – RL – RRC – RLC A
EXAMPLE:
RR A
8051 Flag bits and the PSW register
CY AC F0 RS1 RS0 OV -- P
• PSW Register
Carry flag PSW.7 CY
Auxiliary carry flag PSW.6 AC
Available to the user for general purpose PSW.5 --
Register Bank selector bit 1 PSW.4 RS1
Register Bank selector bit 0 PSW.3 RS0
Overflow flag PSW.2 OV
User define bit PSW.1 --
Parity flag Set/Reset odd/even parity PSW.0 P
0 0 0 00H-07H
0 1 1 08H-0FH
1 0 2 10H-17H
1 1 3 18H-1FH
Example: Example:
MOV A,#88H MOV A,#9CH
ADD A,#93H ADD A,#64H
88 10001000
9C 10011100
+93 +10010011
---- -------------- +64 +01100100
11B 00011011 ---- --------------
CY=1 AC=0 P=0 100 00000000
CY=1 AC=1 P=0
Example:
MOV A,#38H
ADD A,#2FH
38 00111000
+2F +00101111
---- --------------
67 01100111
CY=0 AC=1 P=1
Addressing Modes
• Immediate
• Register
• Direct
• Register Indirect
• Indexed
Immediate Addressing Mode
MOV A,#65H
MOV A,#’A’
MOV R6,#65H
MOV DPTR,#2343H
MOV P1,#65H
Example :
Num EQU 30
…
MOV R0,Num
MOV DPTR,#data1
…
ORG 100H
data1: db “IRAN”
Register Addressing Mode
MOV DPTR, A
MOV Rm, Rn
Direct Addressing Mode
Although the entire of 128 bytes of RAM can be accessed using direct
addressing mode, it is most often used to access RAM loc. 30 –
7FH.
In other word, the content of register R0 or R1 is sources or target in MOV, ADD and
SUBB insructions.
Example:
Write a program to copy a block of 10 bytes from RAM location sterting at 37h to RAM
location starting at 59h.
Solution:
MOV R0,37h ; source pointer
MOV R1,59h ; dest pointer
MOV R2,10 ; counter
L1: MOV A,@R0
MOV @R1,A
INC R0
INC R1
DJNZ R2,L1
Indexed Addressing Mode And On-Chip ROM
Access
MOVC A,@A+DPTR
A= content of address A +DPTR from ROM
Note:
Because the data elements are stored in the program
(code ) space ROM of the 8051, it uses the instruction
MOVC instead of MOV. The “C” means code.
MUL & DIV
• MUL AB ;B|A = A*B
MOV A,#25H
MOV B,#65H
MUL AB ;25H*65H=0E99
;B=0EH, A=99H
• MUL AB ;A = A/B, B = A mod B
MOV A,#25
MOV B,#10
MUL AB ;A=2, B=5
Other conditional jumps :
JZ Jump if A=0
JC Jump if CY=1
JB Jump if bit=1
• LCALL(long call)
In this 3-byte instruction, the first byte is the opcode
an the second and third bytes are used for the address
of target subroutine. Therefore, LCALL can be used
to call subroutines located anywhere within the 64K
byte address space of the 8051.
• ACALL (absolute call)
P3.0 RxD 10
P3.1 TxD 11
P3.2 INT0 12
P3.3 INT1 13
P3.4 T0 14
P3.5 T1 15
P3.6 WR 16
P3.7 RD 17