SlideShare a Scribd company logo
4
Most read
5
Most read
10
Most read
Basic Experiments
(Using ALP code)
Data Movement
a) Move a block of data within internal RAM
8051 ALP code
ORG 00H
MOV R1,#50H
MOV RO,#60H
MOV R3,#0AH
LOOP:MOV A,@R1
MOV @R0,A
INC R1
INC R0
DJNZ R3,LOOP
HERE:SJMP HERE
END
Result : Enter 10 numbers in the memory location d:0x59.Run
the program and see the result in memory location d:0x60 to
0x69
Sample Run:
Before execution: d:0x50 = 45 25 60 25 60 55 44 12 41 58
After execution : d:0x60 = 45 25 60 25 60 55 44 12 41 58
b) Exchange a block of data between internal RAM and
External memory
8051 ALP code
ORG 00H
MOV R0,#50H //SOURCE ADDRESS
MOV DPTR,#0150H //DESTINATION ADDRESS
MOV R3,#05H //COUNT
BACK:MOV A,@R0
MOV R2,A
MOVX A,@DPTR
MOV @R0,A
XCH A,R2
MOVX @DPTR,A
INC R0
INC DPTR
DJNZ R3,BACK
HERE:SJMP HERE
END
Sample Run:
Before execution: d:0x50 = 45 58 52 92 25
After execution : x:0x0150 = 45 58 52 92 25
Arithmetic Operation :
a)Evaluate simple arithmetic expression such as y=((5*2)-(4-1))/3)%2
8051 ALP code
ORG 00H
MOV A,#4
MOV R1,#1
ADD A,R1
MOV R1,A
MOV B,#05H
MOV A,#02H
MUL AB
SUBB A,R1
MOV B,#03H
DIV AB
MOV 30H,A
HERE:SJMP HERE
END
Sample Run:
Before execution: d:0x30 = 00
After execution : d:0x30 = 01
b)Addition of three 8-bit BCD numbers and obtain result in BCD form
8051 ALP code
ORG 00H
START:MOV R0,#02H
MOV R2,#00H
MOV R1,#50H
MOV A,@R1
INC R1
UP : ADD A,@R1
DA A
JNC NEXT
INC R2
NEXT : INC R1
DJNZ R0,UP
MOV O3H,A
HERE:SJMP HERE
END
Sample Run:
Before execution: d:0x50 = 05 06 04
After execution : d:0x02 = 00 15
Logical Operation :
a)Evaluate logical expression Y=a&&b||c^!d where a,b,c and d
are 8-bit data
8051 ALP code
ORG 00H
MOV R0,40H
MOV A,41H
ANL A,R0
MOV B,A
MOV R0,42H
MOV A,43H
CPL A
XRL A,R0
ORL A,B
MOV 44H,A
HERE:SJMP HERE
END
Sample Run:
Before execution: d:0x40 = 45 56 14 85
After execution : d:0x44 = 6E
b)Rotation or Shift operation on 16 bit data
8051 ALP code
ORG 00H
CLR C
MOV A,41H
RLC A
MOV B,A
MOV A,40H
RLC A
MOV 40H,A
MOV A,B
MOV ACC.0,C
MOV 41H,A
HERE:SJMP HERE
END
Sample Run:
Before execution: d:0x40 = 45 56
After execution : d:0x44 = 8A A C
Code Conversions :
a)(1)Two digit packed BCD to unpacked BCD
8051 ALP code
ORG 00H
MOV A,40H
MOV B,A
ANL A,#0F0H
SWAP A
MOV 41H,A
MOV A,B
ANL A,#0FH
MOV 42H,A
HERE:SJMP HERE
END
Sample Run:
Before execution: d:0x40 = 32
After execution : d:0x41 = 03 02
a)(2)Two digit unpacked BCD to packed BCD
8051 ALP code
ORG 00H
MOV A,40H
SAWP A
ORL A,41H
MOV 42H,A
HERE:SJMP HERE
END
Sample Run:
Before execution: d:0x40 = 03 02
After execution : d:0x44 = 32
b)(1) BCD to Binary Conversion
8051 ALP code
ORG 00H
MOV DPTR,#40H
MOVX A,@DPTR
ANL A,#0F0H
SWAP A
MOV B,#0AH
MUL AB
MOV R1,A
MOVX A,@DPTR
ANL A,0FH
ADD A,R1
INC DPTR
MOVX @DPTR,A
HERE:SJMP HERE
END
Sample Run:
Before execution: X:0x0040 = 45(Decimal/BCD)
After execution : X:0x0041 = 2D(Hex/Binary value)
b)(2) Binary to BCD Conversion
8051 ALP code
ORG 00H
MOV DPTR,#9000H
MOVX A,@DPTR
MOV B,#10
DIV AB
INC DPTR
XCH A,B
MOVX @DPTR,A
XCH A,B
MOV B,#10
DIV AB
INC DPTR
MOVX A,@DPTR
HERE:SJMP HERE
END
Sample Run:
Before execution: X:0x9000 = FF(Hex/Binary value)
After execution : X:0x9001 = 05(BCD Value)lower digit first
X:0x9002H = 05(BCD Value)
X:0x9002H = 02(BCD Value)Higher digit first
c)(1) Two digit packed BCD to ASCII
8051 ALP code
ORG 00H
MOV R1,#50H
MOV A,@R1
MOV R2,A
SWAP A
ANL A,#OFH
ORL A,#30H
INC R1
MOV @R1,A
MOV A,R2
ANL A,#0FH
ORL A,#30H
INC R1
MOV @R1,A
HERE:SJMP HERE
END
Sample Run:
Before execution: d:0x50 = 48
After execution : d:0x51 = 34 38
b)(2) Binary to BCD Conversion
8051 ALP code
ORG 00H
CLR C
MOV A,40H
SUBB A,#30H
SWAP A
MOV B,A
CLR C
MOV A,41H
SUBB A,#30H
ADD A,B
MOV 42H,A
HERE:SJMP HERE
END
Sample Run:
Before execution: d:0x40 = 34 38
After execution : d:0x42 = 48
Program to search a given 8bit number in an array of N numbers.
8051 ALP code
ORG 00H
MOV R0,#40H
MOV R1,#0AH
MOV A,#76H
BACK:MOV B,@RO
CJNE A,B,NEXT
MOV A,OFFH
SJMP LAST
NEXT:INC R0
DJNZ R1,BACK
MOV A,#0AAH
LAST:MOV 78H,B
HERE:SJMP HERE
END
Sample Run:
Before execution: d:0x40 = 45 58 39 45 89 45 22 69 76 33
Reg B = 76
After execution : d:0x78 = FF
a)To sort an array of an 6 byte of data in ascending order.
8051 ALP code
ORG 00H
MOV R0,#50
L1:MOV DPTR,#9000H
MOV A,R0
MOV R1,A
L2:MOVX A,@DPTR
MOV B,A
INC DPTR
MOVX A,@DPTR
CLR C
MOV R2,A
SUBB A,B
JNC NOEXCHG
MOV A,B
MOVX @DPTR,A
DEC DPL
MOV A,R2
MOVX @DPTR,A
INC DPTR
NOEXCHG:DJNZ R1,L2 Sample Run:
DJNZ RO,L1 Before execution:X:0x9000 = 45 58 39 45 89 95
HERE:SJMP HERE After execution :X:0x9000 = 39 45 45 58 89 95
END
a)To sort an array of an 6 byte of data in descending order.
8051 ALP code
ORG 00H
MOV R0,#50
L1:MOV DPTR,#9000H
MOV A,R0
MOV R1,A
L2:MOVX A,@DPTR
MOV B,A
INC DPTR
MOVX A,@DPTR
CLR C
MOV R2,A
SUBB A,B
JC NOEXCHG
MOV A,B
MOVX @DPTR,A
DEC DPL
MOV A,R0
MOVX @DPTR,A
INC DPTR
NOEXCHG:DJNZ R1,L2 Sample Run:
DJNZ RO,L1 Before execution:X:0x9000 = 45 58 39 45 89 95
HERE:SJMP HERE After execution :X:0x9000 = 95 89 58 45 45 39
END
Program to count the number of ones and zeros in the data
saved in two consecutive memory location.
8051 ALP code
ORG 00H
MOV R0,#00H
MOV R1,#00H
MOV R2,#08H
MOV A,#0F0H
LOOP3:CLR C
RLC A
JC LOOP1
INC R0
SJMP LOOP2
LOOP1:INC R1
LOOP2:DJNZ R2,LOOP3
HERE:SJMP HERE
END
Sample Run:
Input for execution : Ri = OFOH
Output of execution : R0 = 04
R1 = 04
Program to toggle a particular bit in the internal RAM with the
delay of N ms given the clock frequency f MHz with the use of
delay subroutine.
8051 ALP code
ORG 00H
AGAIN:
SETB P1.2
ACALL DELAY
CLR P1.2
ACALL DELAY
SJMP AGAIN
DELAY:MOV TMOD,#10H
MOV TL1,#0B0H
MOV TH1,3CH
SETB TR1
BACK:
JNB TF1,BACK
CLR TR1
CLR TF1
RET
END
Result : Run the program and observe the toggling of P1.2 bit.

More Related Content

PPTX
COUNTERS(Synchronous & Asynchronous)
ODP
Intro to Hardware Programming with the Arduino Uno
PDF
Security System Based on Ultrasonic Sensor Technology
PPTX
Demultiplexer
PPTX
Micro controller 8051 Interrupts
PPTX
8086 Micro-processor and MDA 8086 Trainer Kit
PDF
prom,pld problems
PPT
Interrupt programming with 8051 microcontroller
COUNTERS(Synchronous & Asynchronous)
Intro to Hardware Programming with the Arduino Uno
Security System Based on Ultrasonic Sensor Technology
Demultiplexer
Micro controller 8051 Interrupts
8086 Micro-processor and MDA 8086 Trainer Kit
prom,pld problems
Interrupt programming with 8051 microcontroller

What's hot (20)

PPTX
Array multiplier
PPTX
Flip flop
PPSX
Lect 3 ARM PROCESSOR ARCHITECTURE
PPTX
Digital Registers & Counters
PPT
8051 Timer
PPTX
Arithmetic and logical instructions 8051 microcontroller
PPTX
Flip flops
PPTX
Vlsi gate level design
PDF
Embedded system (Chapter 3) io_port_programming
PDF
DELD Unit IV ring and twisted ring counter
PDF
Pattern detection in mealy machine
PPTX
Sr jk flip flop by AMAN GOYAT
PDF
3 jump, loop and call instructions
PPTX
Verilog HDL
PPTX
8051 addressing modes
PPT
Interfacing LCD with 8051 Microcontroller
PPT
Addressing modes of 8051
PPTX
Lcd interfacing with microprocessor 8051
PDF
Unit 2 mpmc
PDF
Registers and counters
Array multiplier
Flip flop
Lect 3 ARM PROCESSOR ARCHITECTURE
Digital Registers & Counters
8051 Timer
Arithmetic and logical instructions 8051 microcontroller
Flip flops
Vlsi gate level design
Embedded system (Chapter 3) io_port_programming
DELD Unit IV ring and twisted ring counter
Pattern detection in mealy machine
Sr jk flip flop by AMAN GOYAT
3 jump, loop and call instructions
Verilog HDL
8051 addressing modes
Interfacing LCD with 8051 Microcontroller
Addressing modes of 8051
Lcd interfacing with microprocessor 8051
Unit 2 mpmc
Registers and counters
Ad

Similar to Micro Controller lab basic experiments (1) (20)

PPT
Microcontroller 8051- soft.ppt
PPT
Buy Embedded Systems Projects Online,Buy B tech Projects Online
PPTX
Microcontroller Introduction and the various features
PPT
Programs using Microcontrollers.ppt
PPT
Microcontroller 8051 soft
PDF
Https _doc-0o-c4-apps-viewer.googleusercontent
PPT
Microprocessor system - summarize
PDF
unit5_8051_microcontroller presentation.pdf
PPTX
Micro task1
PPTX
8051 microcontroller
PPT
Addressing modes
PPTX
WINSEM2024-25_BECE204L_TH_VL2024250502425_2024-12-19_Reference-Material-I.pptx
PPT
8085 paper-presentation
PDF
Microprocessor Part 3
PPT
Addressing mode and instruction set using 8051
PPTX
Winter training,Readymade Projects,Buy Projects,Corporate Training
PPT
microp-8085 74 instructions for mct-A :P-2
PPT
8085 Paper Presentation slides,ppt,microprocessor 8085 ,guide, instruction set
PPT
microp-8085 74 instructions for mct-A :P
PDF
8085 Architecture
Microcontroller 8051- soft.ppt
Buy Embedded Systems Projects Online,Buy B tech Projects Online
Microcontroller Introduction and the various features
Programs using Microcontrollers.ppt
Microcontroller 8051 soft
Https _doc-0o-c4-apps-viewer.googleusercontent
Microprocessor system - summarize
unit5_8051_microcontroller presentation.pdf
Micro task1
8051 microcontroller
Addressing modes
WINSEM2024-25_BECE204L_TH_VL2024250502425_2024-12-19_Reference-Material-I.pptx
8085 paper-presentation
Microprocessor Part 3
Addressing mode and instruction set using 8051
Winter training,Readymade Projects,Buy Projects,Corporate Training
microp-8085 74 instructions for mct-A :P-2
8085 Paper Presentation slides,ppt,microprocessor 8085 ,guide, instruction set
microp-8085 74 instructions for mct-A :P
8085 Architecture
Ad

Recently uploaded (20)

PDF
Machine learning based COVID-19 study performance prediction
PPTX
Cloud computing and distributed systems.
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Encapsulation theory and applications.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Spectroscopy.pptx food analysis technology
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Electronic commerce courselecture one. Pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
Machine learning based COVID-19 study performance prediction
Cloud computing and distributed systems.
Building Integrated photovoltaic BIPV_UPV.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Encapsulation theory and applications.pdf
Big Data Technologies - Introduction.pptx
MIND Revenue Release Quarter 2 2025 Press Release
Encapsulation_ Review paper, used for researhc scholars
MYSQL Presentation for SQL database connectivity
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Spectroscopy.pptx food analysis technology
Digital-Transformation-Roadmap-for-Companies.pptx
Understanding_Digital_Forensics_Presentation.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Dropbox Q2 2025 Financial Results & Investor Presentation
Network Security Unit 5.pdf for BCA BBA.
Electronic commerce courselecture one. Pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Per capita expenditure prediction using model stacking based on satellite ima...

Micro Controller lab basic experiments (1)

  • 2. Data Movement a) Move a block of data within internal RAM 8051 ALP code ORG 00H MOV R1,#50H MOV RO,#60H MOV R3,#0AH LOOP:MOV A,@R1 MOV @R0,A INC R1 INC R0 DJNZ R3,LOOP HERE:SJMP HERE END Result : Enter 10 numbers in the memory location d:0x59.Run the program and see the result in memory location d:0x60 to 0x69 Sample Run: Before execution: d:0x50 = 45 25 60 25 60 55 44 12 41 58 After execution : d:0x60 = 45 25 60 25 60 55 44 12 41 58
  • 3. b) Exchange a block of data between internal RAM and External memory 8051 ALP code ORG 00H MOV R0,#50H //SOURCE ADDRESS MOV DPTR,#0150H //DESTINATION ADDRESS MOV R3,#05H //COUNT BACK:MOV A,@R0 MOV R2,A MOVX A,@DPTR MOV @R0,A XCH A,R2 MOVX @DPTR,A INC R0 INC DPTR DJNZ R3,BACK HERE:SJMP HERE END Sample Run: Before execution: d:0x50 = 45 58 52 92 25 After execution : x:0x0150 = 45 58 52 92 25
  • 4. Arithmetic Operation : a)Evaluate simple arithmetic expression such as y=((5*2)-(4-1))/3)%2 8051 ALP code ORG 00H MOV A,#4 MOV R1,#1 ADD A,R1 MOV R1,A MOV B,#05H MOV A,#02H MUL AB SUBB A,R1 MOV B,#03H DIV AB MOV 30H,A HERE:SJMP HERE END Sample Run: Before execution: d:0x30 = 00 After execution : d:0x30 = 01
  • 5. b)Addition of three 8-bit BCD numbers and obtain result in BCD form 8051 ALP code ORG 00H START:MOV R0,#02H MOV R2,#00H MOV R1,#50H MOV A,@R1 INC R1 UP : ADD A,@R1 DA A JNC NEXT INC R2 NEXT : INC R1 DJNZ R0,UP MOV O3H,A HERE:SJMP HERE END Sample Run: Before execution: d:0x50 = 05 06 04 After execution : d:0x02 = 00 15
  • 6. Logical Operation : a)Evaluate logical expression Y=a&&b||c^!d where a,b,c and d are 8-bit data 8051 ALP code ORG 00H MOV R0,40H MOV A,41H ANL A,R0 MOV B,A MOV R0,42H MOV A,43H CPL A XRL A,R0 ORL A,B MOV 44H,A HERE:SJMP HERE END Sample Run: Before execution: d:0x40 = 45 56 14 85 After execution : d:0x44 = 6E
  • 7. b)Rotation or Shift operation on 16 bit data 8051 ALP code ORG 00H CLR C MOV A,41H RLC A MOV B,A MOV A,40H RLC A MOV 40H,A MOV A,B MOV ACC.0,C MOV 41H,A HERE:SJMP HERE END Sample Run: Before execution: d:0x40 = 45 56 After execution : d:0x44 = 8A A C
  • 8. Code Conversions : a)(1)Two digit packed BCD to unpacked BCD 8051 ALP code ORG 00H MOV A,40H MOV B,A ANL A,#0F0H SWAP A MOV 41H,A MOV A,B ANL A,#0FH MOV 42H,A HERE:SJMP HERE END Sample Run: Before execution: d:0x40 = 32 After execution : d:0x41 = 03 02
  • 9. a)(2)Two digit unpacked BCD to packed BCD 8051 ALP code ORG 00H MOV A,40H SAWP A ORL A,41H MOV 42H,A HERE:SJMP HERE END Sample Run: Before execution: d:0x40 = 03 02 After execution : d:0x44 = 32
  • 10. b)(1) BCD to Binary Conversion 8051 ALP code ORG 00H MOV DPTR,#40H MOVX A,@DPTR ANL A,#0F0H SWAP A MOV B,#0AH MUL AB MOV R1,A MOVX A,@DPTR ANL A,0FH ADD A,R1 INC DPTR MOVX @DPTR,A HERE:SJMP HERE END Sample Run: Before execution: X:0x0040 = 45(Decimal/BCD) After execution : X:0x0041 = 2D(Hex/Binary value)
  • 11. b)(2) Binary to BCD Conversion 8051 ALP code ORG 00H MOV DPTR,#9000H MOVX A,@DPTR MOV B,#10 DIV AB INC DPTR XCH A,B MOVX @DPTR,A XCH A,B MOV B,#10 DIV AB INC DPTR MOVX A,@DPTR HERE:SJMP HERE END Sample Run: Before execution: X:0x9000 = FF(Hex/Binary value) After execution : X:0x9001 = 05(BCD Value)lower digit first X:0x9002H = 05(BCD Value) X:0x9002H = 02(BCD Value)Higher digit first
  • 12. c)(1) Two digit packed BCD to ASCII 8051 ALP code ORG 00H MOV R1,#50H MOV A,@R1 MOV R2,A SWAP A ANL A,#OFH ORL A,#30H INC R1 MOV @R1,A MOV A,R2 ANL A,#0FH ORL A,#30H INC R1 MOV @R1,A HERE:SJMP HERE END Sample Run: Before execution: d:0x50 = 48 After execution : d:0x51 = 34 38
  • 13. b)(2) Binary to BCD Conversion 8051 ALP code ORG 00H CLR C MOV A,40H SUBB A,#30H SWAP A MOV B,A CLR C MOV A,41H SUBB A,#30H ADD A,B MOV 42H,A HERE:SJMP HERE END Sample Run: Before execution: d:0x40 = 34 38 After execution : d:0x42 = 48
  • 14. Program to search a given 8bit number in an array of N numbers. 8051 ALP code ORG 00H MOV R0,#40H MOV R1,#0AH MOV A,#76H BACK:MOV B,@RO CJNE A,B,NEXT MOV A,OFFH SJMP LAST NEXT:INC R0 DJNZ R1,BACK MOV A,#0AAH LAST:MOV 78H,B HERE:SJMP HERE END Sample Run: Before execution: d:0x40 = 45 58 39 45 89 45 22 69 76 33 Reg B = 76 After execution : d:0x78 = FF
  • 15. a)To sort an array of an 6 byte of data in ascending order. 8051 ALP code ORG 00H MOV R0,#50 L1:MOV DPTR,#9000H MOV A,R0 MOV R1,A L2:MOVX A,@DPTR MOV B,A INC DPTR MOVX A,@DPTR CLR C MOV R2,A SUBB A,B JNC NOEXCHG MOV A,B MOVX @DPTR,A DEC DPL MOV A,R2 MOVX @DPTR,A INC DPTR NOEXCHG:DJNZ R1,L2 Sample Run: DJNZ RO,L1 Before execution:X:0x9000 = 45 58 39 45 89 95 HERE:SJMP HERE After execution :X:0x9000 = 39 45 45 58 89 95 END
  • 16. a)To sort an array of an 6 byte of data in descending order. 8051 ALP code ORG 00H MOV R0,#50 L1:MOV DPTR,#9000H MOV A,R0 MOV R1,A L2:MOVX A,@DPTR MOV B,A INC DPTR MOVX A,@DPTR CLR C MOV R2,A SUBB A,B JC NOEXCHG MOV A,B MOVX @DPTR,A DEC DPL MOV A,R0 MOVX @DPTR,A INC DPTR NOEXCHG:DJNZ R1,L2 Sample Run: DJNZ RO,L1 Before execution:X:0x9000 = 45 58 39 45 89 95 HERE:SJMP HERE After execution :X:0x9000 = 95 89 58 45 45 39 END
  • 17. Program to count the number of ones and zeros in the data saved in two consecutive memory location. 8051 ALP code ORG 00H MOV R0,#00H MOV R1,#00H MOV R2,#08H MOV A,#0F0H LOOP3:CLR C RLC A JC LOOP1 INC R0 SJMP LOOP2 LOOP1:INC R1 LOOP2:DJNZ R2,LOOP3 HERE:SJMP HERE END Sample Run: Input for execution : Ri = OFOH Output of execution : R0 = 04 R1 = 04
  • 18. Program to toggle a particular bit in the internal RAM with the delay of N ms given the clock frequency f MHz with the use of delay subroutine. 8051 ALP code ORG 00H AGAIN: SETB P1.2 ACALL DELAY CLR P1.2 ACALL DELAY SJMP AGAIN DELAY:MOV TMOD,#10H MOV TL1,#0B0H MOV TH1,3CH SETB TR1 BACK: JNB TF1,BACK CLR TR1 CLR TF1 RET END Result : Run the program and observe the toggling of P1.2 bit.