You are on page 1of 30

MICROCONTROLLERS

8051

UNIT-V

A single chip

Applications

Appliances
(microwave oven, refrigerators, television and VCRs, stereos)

Computers and computer equipment


(laser printers, modems, disk drives)

Automobiles
(engine control, diagnostics, climate control),

Environmental control
(factory, home)

Instrumentation

Aerospace

Robotics, etc...

Popular Microcontrollers

8048 (Intel)

8051 (Intel and others)

PIC (Micro Chip)

Z8 (Zilog)

MC14500 (Motorola)

Port 3 has alternate functions

RxD - Serial input port


TxD - Serial output port
INT0 - External interrupt
INT1 - External interrupt
T0 - Timer 0 external input
T1 - Timer 1 external input
WR - External data memory
write strobe
RD - External data memory
read strobe

Intel 8051: PSW

Part

Intel 8051: Memory Organization

Architecture supports several distinct physical address


spaces functionally separated at the hardware level:
On - chip program memory
On - chip data memory
Off - chip program memory
Off - chip data memory

Intel 8051: Memory Organization


data

memory

Addressing Modes
Direct
Register
Register Indirect
Immediate
Indexed

Direct Addressing Mode

MOV A, 4
MOV 6, 2

; MOV A, R4
; copy R2 to R6
; MOV R6,R2 is invalid !

Indexed Addressing Mode

MOV A,@A+DPTR
MOV A,@A+PC

Some Simple Instructions

MOV dest,source

; dest = source

MOV A,#72H
;A=72H
MOV R4,#62H;R4=62H
MOV B,0F9H
;B=the content of F9th byte of RAM
MOV DPTR,#7634H
MOV DPL,#34H
MOV DPH,#76H
MOV P1,A

;mov A to port 1

Note 1:
MOV A,#72H MOV A,72H
After instruction MOV A,72H the content of 72th byte of RAM will
replace in Accumulator.

Note 2:
MOV A,R3

MOV A,3

ADD A, Source

;A=A+SOURCE

ADDA,#6

;A=A+6

ADDA,R6

;A=A+R6

ADD

A,6

;A=A+[6] or A=A+R6

ADD

A,0F3H

;A=A+[0F3H]

SUBB A, Source

;A=A-SOURCE-C

SUBB

A,#6

;A=A-6

SUBB

A,R6

;A=A+R6

MUL & DIV

MUL
AB ;B|A = A*B
MOV
A,#25H
MOV
B,#65H
MUL
AB ;25H*65H=0E99
;B=0EH, A=99H

DIV
MOV
MOV
DIV

AB ;A = A/B, B = A mod B
A,#25H
B,#10H
AB ;A=2H, B=5H

SETB bit
CLR bit

; bit=1
; bit=0

SETB
SETB
SETB
SETB
SETB

; CY=1
;bit 0 from port 0 =1
;bit 7 from port 3 =1
;bit 2 from ACCUMULATOR =1
;set high D5 of RAM loc. 20h

C
P0.0
P3.7
ACC.2
05

Note:

CLR instruction is as same as SETB


i.e.:
CLR
C
;CY=0
But following instruction is only for CLR:
CLR
A
;A=0

DEC
INC

byte
byte

;byte=byte-1
;byte=byte+1

INC
DEC
DEC

R7
A
40H

; [40]=[40]-1

RR RL RRC RLC A
EXAMPLE:
RR
A
RR:
RRC:

RL:
RLC:

ANL - ORL XRL


Bitwise Logical Operations:
AND, OR, XOR
EXAMPLE:
MOV
R5,#89H
ANL R5,#08H

CPL
Example:
MOV
CPL

;1s complement
A,#55H ;A=01010101 B
A

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

LJMP(long jump)
LJMP is an unconditional jump. It is a 3-byte instruction. It
allows a jump to any memory location from 0000 to FFFFH.
AJMP(absolute jump)
In this 2-byte instruction, It allows a jump to any memory
location within the 2k block of program memory.
SJMP(short jump)
In this 2-byte instruction. The relative address range of 00FFH is divided into forward and backward jumps, that is ,
within -128 to +127 bytes of memory relative to the address of
the current PC.

CALL Instructions
Another control transfer instruction is the CALL
instruction, which is used to call a subroutine.

LCALL(long call)
This 3-byte instruction can be used to call
subroutines located anywhere within the 64K byte
address space of the 8051.
ACALL (absolute call)
ACALL is 2-byte instruction. the target
address of the subroutine must be within 2K
byte range.

THANK YOU

You might also like