Professional Documents
Culture Documents
Features Single supply +5 V operation 4 KB program memory on chip 128 bytes RAM on chip Four register banks 64 KB each program and external RAM addressability one s instruction cycle 32 bidirectional I/O lines (Ports 0 to 3) Two 16 bit timers Hardware multiply/divide in 4 s.
8051 Microcontroller
Vss Vcc RST
Port 0 Port 1
8051
Port 2 Port 3
T0 T1
WR RD
SP IE
ROM
IP PCON
SBUF SCON Port 0 Port 1 Port 2 Port 3 I/O, AD0-AD7 I/O I/O, A8-A15 I/O, Int,Counter, Serial data,RD,WR TCON TMOD TL0 TH0 TL1 TH1
PC
DPTR
Bank 3
Bit/Byte Address
Instruction Set
Instructions can be divided into following groups Data Transfer Arithmetic operations Logical Operations Boolean variable manipulation Program and machine Control Data transfer using DPTR and PC Data bit transfer instructions
Arithmetic Instructions
ADD A, Rn (A)+(Rn) A ADD A, Direct ADD A, @Ri ADD A, #data8 ADDC A, Rn ADDC A, Direct (A)+(Direct)+CY ADDC A, @Ri ADDC A, #data8
Arithmetic Instructions
SUBB A, Rn A - (Rn+CY) SUBB A, Direct SUBB A, @Ri SUBB A, #data8 INC A (A) + 1 A INC Rn INC Direct INC @Ri INC DPTR A
Arithmetic Instructions
DEC A DEC Rn DEC Direct DEC @ Ri MUL AB (A)*(B) B(MSB)A(LSB) DIV AB A/B A(Quotient) B (Remainder) DAA Must be used after ADD / ADC
Logical Instruction
ANL A, Rn ANL A, Direct ANL A, @Ri ANL A, #Data 8 ANL Direct, A ANL Direct, #Data8 ORL A, Rn ORL A, Direct ORL A, @Ri
Logical Instruction
ORL A, #Data 8 XRL Direct, A XRL Direct,#Data8 CRL A (Clears Accumulator) CPL A (Compliments Contents of A) RL A (Rotate left acc without CY) RLC A (Rotate left acc once thro Carry) RR A (Rotate right ACC without CY) RRC A (Rotate right ACC thro CY) SWAP A (Swaps nibbles of Acc)
Branching Instruction
AJMP Addr Absolute jump. PC jumps to location labelled addr within 2K LJMP Addr (jump within 64K) SJMP Reladdr8 (jump to +127/-128 bytes from present position) JMP @A+DPTR ((DPTR)+(A)) PC JZ reladdr8 (jump if A=0) JNZ reladdr8
Branching Instruction
JC reladdr8 JNC reladdr8 JB bit addr, reladdr8 JB 40 H, reladdr 8 if (40H)=1 then branch JNB bit addr, reladdr8 JBC bit addr, reladdr8 (jump if bit =1 and clear the bit in addr) DJNZ Rn, reladdr (Decrement Rn by 1 and jump if not zero) DJNZ Direct, reladdr8 (Decrement contents of addr by 1 and jump if non zero
Branching Instruction
CJNE A, direct byte, reladdr8 Compares 2 byte operands and executes a jump if they disagree ACALL Addr (Unconditional CALL to within 2K locations) LCALL Addr (Unconditional CALL to within 64K locations) RET RETI (used in ISS) NOP
Sample Program
Program to initialise the registers MOV R0, #9A MOV B, #1F MOV DPTR, #4500 MOV A, #20 XCH A, R0 L1: SJMP L1
Sample Program
16 Bit addition Data1:1234 Data2 :5678 Result in 4150 and 4151 CLR C ADDC A,#56 MOV A, #34 MOVX @DPTR, A ADDC A, #78 L1: SJMP L1 MOV DPTR, #4150 MOVX @DPTR, A INC DPTR MOV A, #12
Sample Program
8 bit multiplication Multiply contents of reg A & B and store the result at 4500 & 4501 MOV A,#OA MOV B, #88 MUL AB MOV DPTR, #4500 MOVX @DPTR, A INC DPTR MOV A,B MOVX @DPTR, A L1: SJMP L1
Sample Program
8 bit division MOV A, #65 MOV B, #08 DIV AB MOV DPTR, #4500 MOVX @DPTR, A INC DPTR MOV A,B MOVX @DPTR, A L1:SJMP L1