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

Microprocessor_&_Microcontroller_Lab_Manual_(CSE)

Uploaded by

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

Microprocessor_&_Microcontroller_Lab_Manual_(CSE)

Uploaded by

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

Microprocessor and Microcontrollers

LAB MANUAL
Semester: IV
Batch: 2020-24

Prepared By:
R N Shukla & Kapol Nashine

Verified By:

SCHOOL OF ENGINEERING
Department of Computer Science and Engineering
O P JINDAL UNIVERSITY
O P JINDAL KNOWLEDGE PARK, PUNJIPATRA, RAIGARH-496109

Microprocessor & Microcontroller Lab CSE


EXPERIMENTS LIST

Microprocessor 8086:

*Working with 8086 Simulator ‘EMU8086’


1. To write a program to perform two 8-bit addition and subtraction.
2. To write a program to perform two 16-bit addition and subtraction.
3. A) To write a program to perform to multiply two 16-bit no. and store the result in memory location.
B) To write a program to perform division of two 16-bit no. and store the result in memory location.
4. To find the largest number from a block of 15 bytes
5. To find the smallest number from a block of 15 bytes
6. To write a program to add series of 20 bytes.
7. To write an assembly language program to solve following arithmetic equation: 3AX+5DX+BP.
8. To write a program to arrange a data block in ascending order.
9. To write a program to arrange a data block in descending order.

Microcontroller 8051:

*8051 Microcontroller programming using Keil Uvision IDE

10. WAP in assembly to perform different arithmetic operations on two numbers.


11. Find the largest number out of a string of 5 numbers
12. Write a microcontroller 8051 program to get hex data on the range of 00-FFh from port 0 and convert
it to decimal. Save the digits in R7, R6 and R5, where the least significant digit is in R7.
13. Write an assembly language program (WALP) to add two 16 Bit signed numbers
14. Write a microcontroller 8051 program to transfer the bytes into RAM locations starting at 50h, assuming that
rom space starting at 240h contains CHHATTISGARH by using –
a) a counter, b) null char for end of string.
15. WALP to generate a delay of 13 sec
16. WAP in C a switch is connected to P1.1, monitor the switch & create the following frequency on P1.2:
(i) SWITCH == 0, 500Hz (ii) SWITCH == 1, 1000Hz
17. WAP in ‘C’ to transmit the word ‘OPJU’ character by character.
18. WAP in ‘C’ to use the external Interrupt of 8051 to toggle a led.
19. WAP in ‘C’ to interface LCD with 8051.
Microprocessor & Microcontroller Lab CSE
20. WAP in ‘C’ to interface L293D motor Controller with 8051(AT89C51).

Working with 8086 Simulator ‘EMU8086’.

a) EMU8086 is the emulator of 8086 (Intel and AMD compatible) microprocessor and integrated assembler with
tutorials for beginners. The emulator runs programs like the real microprocessor in step-by-step mode. It shows
registers, memory, stack, variables and flags.

1. On the desktop, double click on ‘emu8086’ icon.


2. You will observe following window

3) Here you can select ‘code examples’ for ready examples or


you can select ‘new’ button to generate new code template where in you have to write your program for
simulation.
4) After pressing ‘new’ button you will observe following window

Microprocessor & Microcontroller Lab CSE


Microprocessor & Microcontroller Lab CSE
5) Here you have to write program for simulation after ‘org100h’.

6) After writing your program to run this example in the emulator,

click emulate button (or press F5). The program then attempts to assemble and save the executable to c:\
emu8086\MyBuild. If the assembler succeeds in creating the file, the emulator ll also automatically load it into
memory & displayed two more window of ‘emulator’ & ‘original source code’.
7) You can then click single step (or press F8) to step through the code one instruction at a time, or click run to
simulate program directly with/ without various delays (0-1-100-200-300-400ms). Also observe status of registers,
flags, stack, vars, memory on the emulator screen. You can also click step back (or press F6) to see what happens
when reversing those changes.

Microprocessor & Microcontroller Lab CSE


Experiment No. 1

Aim: -To write a program to perform two 8 bit addition and subtraction.
Requirement apparatus: - Experiment kit Anshuman XPO-86, SMPS, PC & EMULATOR OF 8086
Program:-

Memory Label Mnemonics Comments


location

1000:0100H MOV AH,05H Move immediate data 05 in register AH


1000:0102H MOV BH,03H Move immediate data 03 in register BH
1000:0104H ADD AH,BH Add contents of AH & BH
1000:0106H MOV CH,AH Move content of AL to register CH
1000:0108H INT A5/ HLT
1000:0100H MOV AH,05H Move immediate data 05 in register AH
1000:0102H MOV BH,03H Move immediate data 03 in register BH
1000:0104H SUB AH,BH Subtrect contents of AH & BH
1000:0106H MOV CH,AH Move content of AL to register CH
1000:0108H INT A5/ HLT

Result:
For 8 bit addition

INPUT OUT PUT

AH 05H AH 08H
BH 03H CH 08H

Microprocessor & Microcontroller Lab CSE


For 8 bit subtraction

INPUT OUT PUT

AH 05H AH 02H
BH 03H CH 02H

Viva Questions:
1. What is a Microprocessor?
2. What is Instruction Set?
3. What are the features of Intel 8086 ?
4. What is Logical Address?
5. What is The Effective Address?

Microprocessor & Microcontroller Lab CSE


Experiment No. 2
Aim: -To write a program to perform two 16-bit addition and subtraction.
Requirement apparatus: - Experiment kit Anshuman XPO-86, SMPS, PC & EMULATOR OF 8086
Program:-

Memory Label Mnemonics Comments


location

1000:0100H MOV AX, 1234H Move immediate data 1234 in register AX


1000:0102H MOV BX, 1234H Move immediate data 1234 in register BX
1000:0104H ADD AX,BX Add contents of AX & BX
1000:0106H MOV CX,AX Move content of AX to register CX
1000:0108H INT A5/ HLT
1000:0100H MOV AX, 2345H Move immediate data 2345 in register AX
1000:0102H MOV BX, 1234H Move immediate data 1234 in register BX
1000:0104H ADD AX,BX Add contents of AX & BX
1000:0106H MOV CX,AX Move content of AX to register CX
1000:0108H INT A5/ HLT

Result:
For 16bit addition

INPUT OUT PUT

AX 1234H AH 2468H
BX 1234H CH 2468H

For 16 bit subtraction

INPUT OUT PUT

AX 2345H AX 1111H
BX 1234H CX 1111H

Viva Questions:
1. What is Physical Address?
2. What are the flags in 8086?
3. Why crystal is a preferred clock source?
4. What is Tri-state logic?
5. What happens when HLT instruction is executed in processor?

Microprocessor & Microcontroller Lab CSE


Experiment No. 3A
Aim: -To write a program to perform to multiply two 16-bit no. and store the result in memory location.
Requirement apparatus: - Experiment kit Anshuman XPO-86, SMPS, PC & EMULATOR OF 8086
Program:-

Memory Label Mnemonics Comments


location

1000:0100H MOV AX, 0006H Move immediate data 0006H in register AX


1000:0103H MOV BX,0002 H Move immediate data 0002H in register BX
1000:0106H MUL BX Multiply contents of AX & BX
1000:0107H LEA SI,[200H] Load effective address in SI register
1000:010BH MOV [SI],AX Move the content of AX in Memory location
1000:010DH MOV [SI+1],AX Move the carry of AX in SI+1 memory location
1000:0110H INT A5/ HLT

Result:

For 16 bit Multiplication

INPUT OUT PUT

AX 0006 H [200H] 03 H
BX 0002 H [201H] 00 H

Viva Questions:
What is Program counter?
What is 1st / 2nd / 3rd / 4th generation processor?
Name the processor lines of two major manufacturers?
How many bit combinations are there in a byte?
Have you studied buses? What types?

Microprocessor & Microcontroller Lab CSE


Experiment No. 3B
Aim: -To write a program to perform division of two 16-bit no. and store the result in memory location
Requirement apparatus: - Experiment kit Anshuman XPO-86, SMPS, PC & EMULATOR OF 8086
Program:-

Memory Label Mnemonics Comments


location

1000:0100H MOV AX, 0FFFH Move immediate data 0FFFH in register AX


1000:0103H MOV BX,FEH Move immediate data FEH in register BX
1000:0106H DIV BX Divide contents of AX & BX
1000:0107H LEA SI,[200H] Load effective address in SI register
1000:010BH MOV [SI],AX Move the content of AX in Memory location
1000:010DH MOV [SI+1],AX Move the carry of Ax in SI+1 memory location
1000:0110H INT A5/ HLT

Result:

For 16 bit Division

INPUT OUT PUT

AX 0FFF H [200H] 10 H
BX 00FE H [201H] 1F H

Viva Questions:
What is the Maximum clock frequency in 8086?
What is meant by Maskable interrupts?
What is Non-Maskable interrupts?
What are the different functional units in 8086?
What are the various segment registers in 8086?

Microprocessor & Microcontroller Lab CSE


Experiment No. 04
Aim: -To find the largest number from a block of 15 bytes.
Requirement apparatus: - Experiment kit Anshuman XPO-86, Smps, PC& Emulator of 8086
Program:-

Memory Label Mnemonics Comments


location
1000:0100H LEA SI,[0200H] Load effective address into SI register
1000:0104H MOV CX,0E H Set the counter 0E in CX register
1000:0107H MOV AL,[SI] Transfer the data into AL register
1000:0109H UP INC SI Increment the memory location of SI by 1
1000:010AH CMP AL,[SI] Compare the content of SI with accumulator
1000:010CH JNC OUT Jump if not carry
1000:010EH MOV AL,[SI] Content of SI is moved to accumulator
1000:0110H OUT LOOP UP Jump the program into the level mention
1000:0112H INT A5/ HLT

Result:
INPUT OUTPUT(AL)

[200H] 44H
[201H] 25H
[202H] 06H
[203H] 76H
[204H] 56H
[205H] 38H
[206H] 77H
[207H] 02H 87H
[208H] 12H
[209H] 67H
[20AH] 60H
[20BH] 05H
[20CH] 87H
[20DH] 35H
[20EH] 07H

Viva Questions:
Which Stack is used in 8086?
What is SIM and RIM instructions?
What are the different types of Addressing Modes?
What are the General Data Registers & their uses?

Microprocessor & Microcontroller Lab CSE


Experiment No. 05
Program: -To find the smallest number from a block of 15 bytes.
Requirement apparatus: - Experiment kit Anshuman XPO-86, SMPS, PC & EMULATOR of 8086
Program:-

Memory Label Mnemonics Comments


location
1000:0100H LEA SI,[0200H] Load effective address into SI register
1000:0104H MOV CX,0E H Set the counter 0E in CX register
1000:0107H MOV AL,[SI] Transfer the data into AL register
1000:0109H UP INC SI Increment the memory location of SI by 1
1000:010AH CMP AL,[SI] Compare the content of SI with accumulator
1000:010CH JC OUT If CF=1 then OUT
1000:010EH MOV AL,[SI] Content of SI is moved to accumulator
1000:0110H OUT LOOP UP Jump the program into the level mention
1000:0112H INT A5/ HLT

Result:
INPUT OUT PUT(AL)

[200H] 44H
[201H] 25H
[202H] 06H
[203H] 76H
[204H] 56H
[205H] 38H
[206H] 77H
[207H] 02H 02H
[208H] 12H
[209H] 67H
[20AH] 60H
[20BH] 05H
[20CH] 87H
[20DH] 35H
[20EH] 07H

Viva Questions:
What are Segment Registers & their uses?
What are Flag registers?
What does the 8086 Architecture contain?
What are Data Copy/Transfer Instructions?

Microprocessor & Microcontroller Lab CSE


Experiment No. 06
Program: -To write a program to add series of 20 bytes.
Requirement apparatus: - Experiment kit Anshuman XPO-86, SMPS, PC & EMULATOR OF 8086
Program:-

Memory Label Mnemonics Comments


location

1000:0100H LEA SI,[200H] Load effective address into SI register


1000:0104H MOVAH,00H Clear AH register
1000:0106H MOV CX,12H Set the counter
1000:0109H MOV AL,[SI] Take data in AL register to SI pointer
1000:010BH INC SI Increment the SI register by 1
1000:010CH UP ADD AL,[SI] Add the content of SI with AL
1000:010EH JNC DOWN Jump if no carry
1000:0110H INC AH Increment the AH register by 1
1000:0112H DOWN INC SI Increment the si register by 1
1000:0113H LOOP UP Go back again &again when counter is zero
1000:0115H INT A5/ HLT

Result:

INPUT OUTPUT

[200H] 01H
[201H] 01H
[202H] 01H
[203H] 01H
[204H] 01H
[205H] 01H
[206H] 01H
[207H] 01H
[208H] 01H
AX 13H
[209H] 01H
[20AH] 01H
[20BH] 01H
[20CH] 01H
[20DH] 01H
[20EH] 01H
[20FH] 01H
[210H] 01H
[211H] 01H
[212H] 01H
[213H] 01H

Viva Questions:
What are Machine Control Instructions?
What are Flag Manipulation Instructions?
What is an Interrupts.
Microprocessor & Microcontroller Lab CSE
Experiment No. 07
Program: -To write an assembly language program to solve following arithmetic equation: 3AX+5DX+BP
Requirement apparatus: - Experiment kit Anshuman XPO-86, SMPS, PC & EMULATOR OF 8086
Program:-

Memory Label Mnemonics Comments


location

1000:0100H LEA SI,[200H] Load effective address into SI register


1000:0104H LEA DI,[201H] Load effective address into DI register
1000:0108H LEA BP,[202H] Load effective address into BP register
1000:010AH MOV AL,[SI] Transfer the content of SI register into AL register
1000:010CH MOV BX,03H 03H is moved to BX register
1000:010EH MUL BX Multiply the content of BX to AX
1000:0110H MOV BX,AX Transfer the data of AX to BX register
1000:0112H MOV AL,[DI] Transfer the data of DI into AL register
1000:0114H MOV DX, 05H 05H is moved to DX register
1000:0116H MUL DX Multiply the content of DX to AL register
1000:0118H MOV DX,AX Transfer the data of AX to DX register
1000:011AH MOV AX,BX Transfer the data of BX to AX register
1000:011CH ADD AX, DX Add the content of AX to DX register
1000:011EH MOV DL ,[BP] Transfer the data from BP to DL register
1000:0120H ADD AX, DX Add the content of DX to AX register
1000:0123H INT A5/ HLT

Result:
INPUT OUT PUT(AX)

[200H] 02H
(AX) 1BH
[201H] 03H
(DX)
[202H](BP) 06H

Viva Questions:
What is an Opcode?
What is an Operand?
Explain the difference between a JMP and CALL instruction?
What is meant by Polling?
What is meant by Interrupt?

Microprocessor & Microcontroller Lab CSE


Experiment No. 08
Program: -To write a program to arrange a data block in ascending order.
Requirement apparatus: - Experiment kit Anshuman XPO-86, SMPS, PC & EMULATOR OF 8086
Program:-

Memory Label Mnemonics Comments


location

1000:0100H LEA SI,[200H] Load effective address in SI register


1000:0104H MOV CX,0B Set the counter in CX register
1000:0107H UP MOV AL,[SI] Transfer the content of SI register to AL register
1000:0109H MOV BH.0B Set the counter in BX register
1000:010BH AGAIN MOV AL,[SI] Transfer the content of SI memory location to AL
register
1000:010DH MOV BL,[SI+1] Transfer the content next memory location to BL
register
1000:0110H CMP AL,BL Compare the content BL to AL register
1000:0112H JC NEXT IF CF =1 then go to NEXT
1000:0114H MOV [SI],BL Transfer the content of BL to SI memory location
1000:0116H MOV [SI+1],AL Content of AL is moved to SI+1 memory location
1000:0119H NEXT INC SI Increment the memory location of SI by 1
1000:011AH DEC BH Decrement the BH by 1
1000:011CH JNZ AGAIN Jump if CF=0then go AGAIN
1000:011EH LEA SI,[200H] Load effective address to SI register
1000:0122H LOOP UP Loop will continue when CX=0
1000:0124H INT A5/ HLT

Result:
INPUT OUT PUT

[200H] 09H [200H] 01H


[201H] 34H [201H] 08H
[202H] 23H [202H] 09H
[203H] 01H [203H] 12H
[204H] 08H [204H] 21H
[205H] 12H [205H] 22H
[206H] 32H [206H] 23H
[207H] 21H [207H] 32H
[208H] 45H [208H] 34H
[209H] 67H [209H] 38H
[20AH] 22H [20AH] 45H
[20BH] 38H [20BH] 67H

Viva Questions:
What is an Instruction?
What is Microcontroller and Microcomputer?
What is Assembler?

Microprocessor & Microcontroller Lab CSE


Define Pipelining?

Experiment No. 09
Aim: -To write a program to arrange a data block in descending order.
Requirement apparatus: - Experiment kit Anshuman XPO-86, SMPS, PC & EMULATOR OF 8086
Program:-

Memory Label Mnemonics Comments


location

1000:0100H LEA SI,[200H] Load effective address in SI register


1000:0104H MOV CX,0B Set the counter in CX register
1000:0107H UP MOV AL,[SI] Transfer the content of SI register to AL register
1000:0109H MOV BH.0B Set the counter in BX register
1000:010BH AGAIN MOV AL,[SI] Transfer the content of SI memory location to AL
register
1000:010DH MOV BL,[SI+1] Transfer the content next memory location to BL
register
1000:0110H CMP AL,BL Compare the content BL to AL register
1000:0112H JNC NEXT IF CF =0 then go to NEXT
1000:0114H MOV [SI],BL Transfer the content of BL to SI memory location
1000:0116H MOV [SI+1],AL Content of AL is moved to SI+1 memory location
1000:0119H NEXT INC SI Increment the memory location of SI by 1
1000:011AH DEC BH Decrement the BH by 1
1000:011CH JNZ AGAIN Jump if CF=0then go AGAIN
1000:011EH LEA SI,[200H] Load effective address to SI register
1000:0122H LOOP UP Loop will continue when CX=0
1000:0124H INT A5/ HLT

Result:
INPUT OUT PUT

[200H] 09H [200H] 67H


[201H] 34H [201H] 45H
[202H] 23H [202H] 38H
[203H] 01H [203H] 34H
[204H] 08H [204H] 32H
[205H] 12H [205H] 23H
[206H] 32H [206H] 22H
[207H] 21H [207H] 21H
[208H] 45H [208H] 12H
[209H] 67H [209H] 09H
[20AH] 22H [20AH] 08H
[20BH] 38H [20BH] 01H

Viva Questions:
What is the use of HLDA?
Explain about "LEA"?
Difference between "Shift" and "Rotate".
Microprocessor & Microcontroller Lab CSE
Difference between JMP and JNC?

Microprocessor & Microcontroller Lab CSE


Microcontroller 8051:
 8051 Microcontroller programming using Keil Uvision IDE
Step 1: Download the Keil Uvision IDE
Download the C51 version for programming on 8051 microcontroller architecture.

Step 2: To initiate the programming you must create a project using the keil Uvision IDE
The option to create a new project will be available under the project tab in the toolbar. Next, you have to store the
project in a folder and give a suitable name to it.

Step 3: Selecting the type of device you are working with


The device selection dialog provides you with the option to select the 8051 derivatives for which you want to
develop the program. Here in this case choose AT89C51/52/55 from ATMEL device and click OK to confirm.

Microprocessor & Microcontroller Lab CSE


Once you select the chip, a message box will be displayed. It asks whether to load Startup code into
the Project: (select Yes)

Step 4:
For writing code: Select New file (or Ctrl+N) from file drop down menu. On Right Hand Side is the
editor where the code can be written.
Once the code is written, and save project with the extension (.C or .ASM):

For Assembly :

Microprocessor & Microcontroller Lab CSE


Step 5: Coding in C
The main part has finally arrived, so now you can go along with programming in C with your respective
microcontroller.
It has to be added to the Project. To do those right click on the Source group and select “add files to
source group” option.
Then select the file to be added. You can see the file added on Left Hand side in the Source group:
Step 6 :
To build the project, go to Project Drop Down menu and select Build (or press F7). Once the project is
built, the result can be seen at the bottom. If any errors are present, the list of errors will be displayed
or if the project has no errors the build is said to be successful:

Microprocessor & Microcontroller Lab CSE


Step 7: Generating the hex file using Keil Uvision IDE
When the project is built, it only compiles and links all the files in project. If the same code is to be
loaded onto the chip flash memory, we need the hex file. Hex file is the downloadable file which is used
to load onto the flash memory of the chip. In order to generate the Hex file, right click on target folder
in Project workspace (the first folder visible) and select “Options for Target ‘’.Check the check box –
Create Hex file and press OK Once the option is selected to create Hex file, once again bu ild the
Project. This time the Hex

Microprocessor & Microcontroller Lab CSE


file is created. You can see the hex file in the folder where the Project is saved . If
you want to check for the correctness of the code:

Step 8:
For Debuging: Debug drop down Menu and select “Start/Stop Debug Session”.
Here you simulate the program in SIMULATOR mode here you can see Yellow arrow
mark that will move step while pressing F11.

Step 9: Burning the hex code into 8051 microcontroller


In order to burn the hex code to your microcontroller, there are two ways which are
specific to the device you are working with. Some devices, for example, P89V51 they have
their own built-in bootloader and you can burn the hex code directly through the serial
port. Mostly you will require a specific programmer for your 8051 microcontroller through

Microprocessor & Microcontroller Lab


which you can easily upload your hex code by connecting the programmer via normal USB
port.

Experiment No.10
Aim: WAP in assembly to perform different arithmetic operations on two numbers.
Requirements: Keil µvision IDE
Program:
ORG 00H
MOV R1, #25H
MOV R2, #02H
ACALL plus //CALLING SUBROUTINE FOR ADDITION
ACALL minus //CALLING SUBROUTINE FOR SUBTRACTION
ACALL mult //CALLING SUBROUTIE FOR MULTIPLICATION
ACALL divi //CALLINING SUBROUTINE FOR DIVISON
ORG 10H
plus: ACALL LOAD
ADD A, B
MOV R3, A
MOV 32H, R3
RET
ORG 20H
minus: ACALL LOAD
SUBB A, B
MOV R3, A
MOV 33H, R3
RET
ORG 30H
mult: ACALL LOAD
MUL AB
MOV R3, A
MOV 34H, R3
RET
ORG 40H
divi: ACALL LOAD
DIV AB
MOV R3, A
MOV 35H, R3
RET

ORG 50H // subroutine for loading the variables in the accumulator


LOAD:
MOV A, R1
MOV B, R2
RET

END

Microprocessor & Microcontroller Lab


Microprocessor & Microcontroller Lab
Result:

Loading into R1,R2 Loading into Reg. A &B Result of Addition in R3 Result of
Subtraction in R3

Result of Multiplication in R3 Result of Division in R3

Viva Questions:
Intel 8051 follows which architecture?
What is the difference between Harvard Architecture and von Neumann
Architecture?
8051 was developed using which technology?
Why 8051 is called an 8-bit microcontroller?

Microprocessor & Microcontroller Lab


Experiment No.11

Aim : Find the largest number out of a string of 5 numbers Requirements: Keil µvision IDE

Program : ORG 00H


MOV DPTR, #300H
MOV R0,#05H
MOV B,#00H
JUMP: CLR A
MOVC A, @A+DPTR
CJNE A,B,NEXT
SJMP LAST
NEXT: JNC CARRY
SJMP LAST
CARRY: MOV B,A
LAST: INC DPTR
DJNZ R0,JUMP
ORG 300H
DB 2,5,3,6,7
END

Microprocessor & Microcontroller Lab


Experiment No.12
Aim: Write a microcontroller 8051 program to get hex data on the range of 00-FFh from port 0
and convert it to decimal. Save the digits in R7, R6 and R5, where the least significant digit is in
R7.

Requirements: Keil µvision IDE


Program :
ORG 00H
MOV A, P0
MOV B,#0AH
DIV AB
MOV R7,B
MOV B,#0AH
DIV AB
MOV R6,B
MOV B,#0AH
DIV AB
MOV R5,B
END

Microprocessor & Microcontroller Lab


Experiment No.13
Aim: Write an assembly language program to add two 16 Bit signed numbers

Requirements: Keil µvision IDE


Program:

ORG 00H
CLR C ; CLEAR CY FLAG
MOV R2,#02H ; Move Into R2 The Number Of Bytes In Each Nmber
MOV R0,#40H ; R0 POINTS TO THE LOW BYTE OF THE 1ST NO.
MOV R1,#50H ; R1 POINTS TO THE LOW BYTE OF THE 2ND NO.
SETB PSW.3 ; SWITCH TO BANK 1
MOV R0,#60H ;USE R0 OF BANK 1 AS POINTER TO THE RESULT
CLR PSW.3 ; RETURN TO BANK 0
BACK: MOV A,@R0 ; BRING ONE BYTE OF THE 1ST NO INTO A
CPL A ; 1'S COMPLIMENTS
ADD A,#01 ; 2'S COMPLIMENTS
MOV @R0, A ; 2'S COMPLIMENTS NO MOV FROM A TO ADDRS GIVEN BY R0
MOV A,@R1 ; BRING ONE BYTE OF THE 1ST NO INTO A
CPL A ; 1'S COMPLIMENTS
ADD A,#01 ; 2'S COMPLIMENTS
ADD A,@R0 ; ADD ONE BYTE OF THE 2ND NO
INC R0 ; INCREMENT 1ST NO
INC R1 ; INCREMENT 1ST NO
SETB PSW.3 ; SWITCH TO BANK 1
MOV @R0,A ; SIGN NUMBER ADDITION RESULT STORE OF IN MEMORY LOC
INC R0 ; Increment R0 For Address Of Next Addition Result
CLR PSW.3 ; RETURN TO BANK 0
DJNZ R2, BACK ; Repeat Until All Two Sign ;Bytes (16 ;Bit) Have Been Added
SETB PSW.3
DEC R0
DEC @R0
END

INPUT : 1st NO : (-213B) + 2nd NO : (-1452)

Microprocessor & Microcontroller Lab


Execute the program in Keil software:

OUTPUT: (-213B) + (-1452) = (-358D)


2’s Compliment of (-358D) = 1CA73

Microprocessor & Microcontroller Lab


Experiment No.14

AIM: Write a microcontroller 8051 program to transfer the bytes into RAM locations starting at
50h, assuming that rom space starting at 240h contains CHHATTISGARH by using –
a) a counter, b) null char for end of string.

Requirements: Keil µvision IDE

Program:
;a) a Counter

ORG 00H
MOV DPTR,#MYDATA ; LOAD ROM POINTERT
MOV R0,#50H ; LOAD RAM POINTER
MOV R2,#12 ; LOAD COUNTER
BACK: CLR A
MOVC A,@A+DPTR ; MOVE DATA FROM CODE SPACE
MOV @R0,A ; SAVE IT IN RAM
INC DPTR ; INCREMENT ROM POINTER
INC R0 ; INCREMENT RAM POINTER
DJNZ R2,BACK ; LOOP UNTIL COUNTER=0
HERE: SJMP HERE

ORG 240H
MYDATA: DB "CHHATTISGARH"
END

Input: ROM space starting at 240H contains CHHATTISGARH

Microprocessor & Microcontroller Lab


Execute the program in Keil software:

Output: Transferred the bytes into RAM locations starting at 50H

; b) null char for end of string .

ORG 0000
MOV DPTR, #MYDATA ; LOAD ROM POINTER

Microprocessor & Microcontroller Lab


MOV R0,#50H ; LOAD RAM POINTER
BACK: CLR A
MOVC A,@A+DPTR ; MOVE DATA FROM CODE SPACE
JZ HERE ; EXIT IF NULL CHARACTER ;
; EXAMINESTHE CONTENTS OF THE ‘’A’’
; & JUMPS IF IT HAS VALUE ZERO
MOV @R0,A ; SAVE IT IN RAM
INC DPTR ; INCREMENT ROM POINTER
INC R0 ; INCREMENT RAM POINTER
SJMP BACK ; LOOP
HERE: SJMP HERE
ORG 240H
MYDATA: DB "CHHATTISGARH",0 ; NOTICE NULL CHAR '0' FOR END OF STRING
END
Input: ROM space starting at 240H contains CHHATTISGARH

Execute the program in Keil software:

Microprocessor & Microcontroller Lab


Output: Transferred the bytes into RAM locations starting at 50H

Microprocessor & Microcontroller Lab


Experiment No.15
AIM : Program to generate a delay of 13 sec
Requirements: Keil µvision IDE

Program:

ORG 00H
MOV TMOD,#01H
COMP: CPL P1.5
MOV R0, #0C8H
JUMP: MOV TH0,#02H
MOV TL0,#18H
SETB TR0
AGAIN: JNB TF0,AGAIN
CLR TR0
CLR TF0
DJNZ R0,JUMP
SJMP COMP
END

Microprocessor & Microcontroller Lab


Viva Questions on 8051 Microcontroller:

Why 8051 is called an 8-bit microcontroller?


What is the width of the data bus?
What is the width of the address bus?
List the features of the 8051 microcontrollers?
What location code memory space and data memory space begins?
How Much on-chip RAM is available?
With 12 MHz clock frequency how many instructions (of 1 machine cycle and 2 machine cycle) can execute
per second?
List out addressing Modes in MCS-51.
How much total external data memory that can be interfaced to the 8051?
What are Special Function Registers (SFR)?
What are the difference between bit addressable and byte address in microcontroller 8051?
What are the types of interrupts in 8051?
What are the four distinct types of memory in 8051?
Tell the addresses which are bit addressable?
What is a .lst file?
Explain DB.
What is EQU?
How are labels named in assembly language?
Are all the bits of flag register used in 8051?
Which bit of the flag register is set when output overflows to the sign bit?
What are the issues related to stack and bank 1?
Which 2 ports combine to form the 16-bit address for external memory access?
Can a single bit of a port be accessed in 8051?
Other than SETB, CLR are there any single bit instructions?
Internal RAM is located from address 0x00 to ___?
Explain JNC
What is 8051 Microcontroller ?
What are registers in Microcontroller ?
List Interrupts available in 8051 Microcontroller
What is stack pointer in 8051 Microcontroller?
List some features of 8051 Microcontroller.
What is an Interrupt service routine in Microcontroller?
What is an interrupt? List various types of interrupts available in 8051 Microcontroller?
Explain architecture of 8051 Microcontroller?
What is Address Bus, Data Bus and Control Bus in Microprocessor 8051 ?
Which interrupt has highest priority in Microcontroller ?
List some 8051 Microcontroller applications in embedded systems ?
What are applications of 8051 microcontrollers?
What is the difference between microprocessor and microcontroller?
What is a PIC microcontroller?
What is the use of PIC microcontroller?
What is ARM microcontroller?
Where ARM chips are used?
List some 8051 microcontroller interrupts?
List some microcontroller examples?
What is a data pointer in 8051 Microcontrollers?
What is embedded Microcontroller?
List major components of microcontroller?
What are different types of Microcontrollers?

Microprocessor & Microcontroller Lab


EXPERIMENT – 16
Aim : WAP IN C A SWITCH IS CONNECTED TO P1.1, MONITOR THE SWITCH & CREATE THE
FOLLOWING FREQUENCY ON P1.2
(i) SWITCH == 0, 500Hz (ii) SWITCH == 1, 1000Hz
Requirements: PC, Keil microvision IDE

Program:

#include <reg51.h>
sbit sw = P1^1; // SETTING SWITCH AS PORT 1.1
sbit out = P1^2;// SETTING OUTPUT AS PORT 1.2
void t0delay(char ch) // delay function
{
TMOD = 0x01; // TIMER 0 MODE-1 , 16 BIT TIMER
if(ch == '0') //CHECKING SWITCH CONDITION
{ // FOR 500Hz

Microprocessor & Microcontroller Lab


// FFFF - COUNT VALUE + 1
TL0 = 0x66;
TH0 = 0xFC;
}
else if(ch == '1')// CHECKING SWITCH CONDITION
{ //FOR 1000Hz
//FFFF - COUNT VALUE + 1
TL0 = 0x33;
TH0 = 0xFE;
}
TR0 = 1; // TIMER 0 RUN AS SET
while(TF0==0); // CHECKING TIMER FLAG 0
TR0 = 0; // CLEARING TIMER 0 RUN
TF0 = 0; // CLEARING TIMER FLAG 0
}
void main() // main function
{
sw = 0;
while(1) // running continuously
{
if(sw==1)

out = 1;
t0delay('1'); // CALLING t0delay function FOR 1000Hz
out = 0;
t0delay('1');
}
else
{
out = 0;
t0delay('0');// CALLING t0delay FOR 500Hz
out = 1;
t0delay('0');
}
}
}

Result:

Microprocessor & Microcontroller Lab


Microprocessor & Microcontroller Lab
EXPERIMENT – 17
Aim: WAP in ‘C’ to transmit the word ‘OPJU’ character by character
Requirement: PC, Keil microvision IDE
Program:
#include <reg51.h>
void transmit(unsigned char x);
void main()
{
TMOD = 0x20;
TH1 = 0xFD;
SCON = 0x50;
TR1 = 1;
while(1)
{
transmit('O');
transmit('P');
transmit('J');
transmit('U');
transmit(' ');
}
}
void transmit(unsigned char x)
{
SBUF = x;
while(TI==0);
TI = 0;
}

Result:

Microprocessor & Microcontroller Lab


EXPERIMENT – 18
Aim: WAP in ‘C’ to use the external Interrupt of 8051 to toggle a led.
Requirements: PC, Keil microvision IDE, Proteus (Demo Version)
Program:

//P1^0 Status will change by EXT intrrupt 0 by using clock of frequency 990HZ at Port3 pin 2
#include <reg51.h>

sbit led = P1^0;

void Ext_int_init()
{
EA = 1;
EX0 = 1;
IT0 = 1;
}
void External0_ISR() interrupt 0
{
led = ~led;
}
void main()
{
Ext_int_init();
while(1);
}

Result:

Microprocessor & Microcontroller Lab


Microprocessor & Microcontroller Lab
EXPERIMENT – 19
Aim: WAP in ‘C’ to interface LCD with 8051.
Requirements: PC, Keil microvision IDE, Proteus (Demo Version), 16x2 LCD
Program:
#include <reg51.h>
#define databus P2
sbit RS = P1^0; // Register Select Pin of 16X2 LCD
sbit RW = P1^1; // Read Write Pin of 16X2 LCD
sbit EN = P1^2; // Enable pin of 16X2 LCD
//Defining Delay Function
void delay_us(unsigned int cnt)
{
int i;
for(i = 0;i<cnt;i++);
}
//CMD FOR FUNCTION FOR SENDING command
void CMD(char cmd)
{
databus = cmd;
RS = 0; // Register Select = 0 to select instruction
RW = 0; // Reading = 0 and for Writing = 1
EN = 1;
delay_us(1);
EN = 0;
delay_us(1000);
}
//DATA FUNCTION FOR SENDING DATA
void DATA(char dat)
{
databus = dat;
RS = 1; // Register Select = 0 to select data register
RW = 0; // Reading = 0 and for Writing = 1
EN = 1;
delay_us(1);
EN = 0;
delay_us(1000);

}
//INIT FUNCTION OF LCD
void lcd_init()
{
CMD(0x38); // Initialising two array lines of lcd
CMD(0x0E); // display on cursor blinking
CMD(0x01); // clear screen
CMD(0x80); // 1st line of lcd
}
void main()
{
int i;
char a[]={"WELCOME TO CLASS"}; // Storing Character in String form using array
lcd_init();
DATA('H'); // Sending to the LCD character by Character to the first line of LCD
DATA('E');
DATA('L');
DATA('L');

Microprocessor & Microcontroller Lab


DATA('O');
CMD(0xC0); //2nd Line of LCD
for(i = 0; i<16;i++)
{
DATA(a[i]); // Sending string to the 2nd Line of LCD

}
while(1);
}
Result:

Microprocessor & Microcontroller Lab


EXPERIMENT – 20
Aim: WAP in ‘C’ to interface L293D motor Controller with 8051(AT89C51).
Requirement: PC, Keil microvision IDE, Proteus (Demo Version), DC Motor, L293D motor Controller
Program:

#include<reg51.h>
#include<stdio.h>
void delay(void);
sbit motor1_pin_1 = P2^0;
sbit motor1_pin_2 = P2^1;
sbit motor2_pin_1 = P2^2;
sbit motor2_pin_2 = P2^3;
void main()
{
do
{
motor1_pin_1 = 1;
motor1_pin_2 = 0; // Motor1 Rotates Anit Clockwise
motor2_pin_1 = 1;
motor2_pin_2 = 0; // Motor2- Rotates Anit Clockwise

delay();
motor1_pin_1 = 1;
motor1_pin_2 = 1; //Motor1 Stop
motor2_pin_1 = 1;
motor2_pin_2 = 1; //Motor2 Stop

delay();
motor1_pin_1 = 0;
motor1_pin_2 = 1; // Motor1 Rotates Clockwise
motor2_pin_1 = 0;
motor2_pin_2 = 1; //Motor2 Rotates Clockwise

delay();
motor1_pin_1 = 1;
motor1_pin_2 = 0; // Motor1 Rotates Anit Clockwise
motor2_pin_1 = 0;
motor2_pin_2 = 1; //Motor2 Rotates Clockwise
delay();

motor1_pin_1 = 0;
motor1_pin_2 = 1; // Motor1 Rotates Clockwise
motor2_pin_1 = 1;
motor2_pin_2 = 0; // Motor2- Rotates Anit Clockwise
delay();
motor1_pin_1 = 0;
motor1_pin_2 = 0; //Stop Motor1
motor2_pin_1 = 0;
motor2_pin_2 = 0; //Stop Motor2
delay();
}while(1);
}
void delay()
{

Microprocessor & Microcontroller Lab


int i,j;
for(i=0;i<500;i++)
{
for(j=0;j<500;j++)
{
}
}
}

Result:

Microprocessor & Microcontroller Lab

You might also like