0% found this document useful (0 votes)
9 views

8051 Microcontroller C Programming notes by NK Sinha

The document provides a detailed overview of data transfer, arithmetic, and logical instructions for the 8051 microcontroller using C programming. It includes specific instructions, their descriptions, byte requirements, and periods for execution. Additionally, it outlines practical exercises related to register manipulation and arithmetic operations.

Uploaded by

ytpremium8904
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

8051 Microcontroller C Programming notes by NK Sinha

The document provides a detailed overview of data transfer, arithmetic, and logical instructions for the 8051 microcontroller using C programming. It includes specific instructions, their descriptions, byte requirements, and periods for execution. Additionally, it outlines practical exercises related to register manipulation and arithmetic operations.

Uploaded by

ytpremium8904
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

8051 Microcontroller

C Programming
Subject: MICROPROCESSORS AND MICROCONTROLLERS Code: 3160914

N. V. SINHA, LDCE
Data Transfer Instructions

Instruction Description Bytes Periods C OV AC

MOV A,Rn Move Register to ACC 1 12


MOV A,direct Move Direct byte to ACC 2 12
MOV A,@Ri Move Indirect byte to ACC 1 12
MOV A,#data Move Immediate data to ACC 2 12
MOV Rn,A Mov ACC to Register 1 12
MOV Rn,direct Move Direct byte to Register 2 24
MOV Rn,#data Move Immediate data to Register 2 24
MOV direct,A Move ACC to Direct byte 2 12
MOV direct,Rn Move Register to Direct byte 2 24
MOV direct,direct Move Direct byte to Direct byte 3 24
MOV direct,@Ri Mov Indirect RAM to Direct byte 3 24
MOV direct,#data Move Immediate data to Direct byte 3 24
MOV @Ri,A Move ACC to Indirect RAM 1 12
MOV @Ri,direct Move direct byte to indirect RAM 2 24
MOV @Ri,#data Move Immediate data to Indirect RAM 2 12
MOV DPTR,#data16 Load datapointer with 16 bit constant 3 24
MOVC A,@A+DPTR Move code byte at ACC+DPTR to ACC 1 24

MOVC A,@A+PC Move code byte at ACC+PC to ACC 1 24


MOVX A,@Ri Move external RAM to ACC 1 24
MOVX @Ri,A Move ACC to external RAM 1 24
MOVX A,@DPTR Move external RAM to ACC 1 24
MOVX @DPTR,A Move ACC to external RAM 1 24
PUSH direct Push direct byte to stack 2 24
POP direct Pop direct byte from stack 2 24
XCH A,Rn Exchange register with ACC 1 12
XCH A,direct Exchange direct byte with ACC 2 12
XCH A,@Ri Exchange indirect RAM with ACC 1 12
XCHD A,@Ri Exchange low order digit indirect RAM with ACC 1 12

N. V. SINHA, LDCE 2
ØEnter the number 34H in registers R5, R6 and R7

ØEnter the number 8DH in RAM locations 30H to 34H

ØSwap the contents of registers R6 and R7 in register bank 0

ØLoad A, DPH, DPL with 30H

N. V. SINHA, LDCE 3
Arithmetic Instructions

Instruction Description Bytes Periods C OV AC

ADD A, Rn Add register to ACC 1 12 x x x


ADD A, direct Add direct byte to ACC 2 12 x x x
ADD A, @Ri Add indirect RAM to ACC 1 12 x x x
ADD A, #data Add immediate data to ACC 2 12 x x x
ADDC A, Rn Add register to ACC with Carry 1 12 x x x
ADDC A, direct Add direct byte to ACC with Carry 2 12 x x x
ADDC A, @Ri Add indirect RAM to ACC with Carry 1 12 x x x
ADDC A, #data Add immediate data to ACC with Carry 2 12 x x x
SUBB A, Rn Subtract Register from ACC with borrow 1 12 x x x
SUBB A, direct Subtract indirect RAM from ACC with borrow 2 12 x x x
SUBB A, @Ri Subtract indirect RAM from ACC with borrow 1 12 x x x
SUBB A, #data Subtract immediate data from ACC with borrow 2 12 x x x
INC A Increment ACC 1 12
INC Rn Increment register 1 12
INC direct Increment direct byte 2 12
INC @Ri Increment direct RAM 1 12
DEC A Decrement ACC 1 12
DEC Rn Decrement Register 1 12
DEC direct Decrement direct byte 2 12
DEC @Ri Decrement indirect RAM 1 12
INC DPTR Increment Data Pointer 1 24
MUL AB Multiply A & B 1 48 0 x
DIV AB Divide A by B 1 48 0 x
DA A Decimal Adjust ACC 1 12 x
N. V. SINHA, LDCE 4
ØAdd two 16 bit numbers

ØUnpack the packed BCD number stored in A and save the result in R0
→ (LSB) and R1→(MSB)

ØSubtract the contents of R1 of bank0 from contents of R0 of bank2

ØSubtract two 16 bit numbers

N. V. SINHA, LDCE 5
Logical Instructions
Instruction Description Bytes Periods C OV AC

ANL A,Rn AND register to ACC 1 12


ANL A,direct AND direct byte to ACC 2 12
ANL A,@Ri AND indirect RAM to ACC 1 12
ANL A,#data AND immediate data to ACC 2 12
ANL direct,A AND ACC to direct byte 2 12

ANL direct, #data AND immediate data to direct byte 3 24

ORL A,Rn OR register to ACC 1 12


ORL A,direct OR direct byte to ACC 2 12
ORL A,@Ri OR indirect RAM to ACC 1 12
ORL A,#data OR immediate data to ACC 2 12
ORL direct,A OR ACC to direct byte 2 12

ORL direct, #data OR immediate data to direct byte 3 24

XRL A,Rn XOR register to ACC 1 12


XRL A,direct XOR direct byte to ACC 2 12
XRL A,@Ri XOR indirect RAM to ACC 1 12
XRL A,#data XOR immediate data to ACC 2 12
XRL direct,A XOR ACC to direct byte 2 12

XRL direct, #data XOR immediate data to direct byte 3 24

CLR A Clear the ACC 1 12


CPL A Complement the ACC 1 12
RL A Rotate the ACC left 1 12
RLC A Rotate the ACC left through Carry 1 12 x
RR A Rotate the ACC right 1 12
RRC A Rotate the ACC right through Carry 1 12 x
SWAP A Swap nibbles in the ACC 1 12

N. V. SINHA, LDCE 6
ØClear contents of A

ØInvert every bit in R6

ØDouble the number in R2 and put result in R3 (High Byte) and R4


(Low Byte)

ØStore the most significant nibble of A in both nibbles of R5

N. V. SINHA, LDCE 7
https://www. techknowlearn.blogspot.com
N. V. SINHA, LDCE 8
ØPlace any number in RAM location 3CH and increment it until the
number equals to 2AH

ØFind maximum number from 10 numbers

ØArrange given numbers in ascending order

N. V. SINHA, LDCE 9

You might also like