Fyit MP Practical Mannual Final

Download as pdf or txt
Download as pdf or txt
You are on page 1of 33

MICROPROCESSOR PRACTICAL JOURNEL

Practical 1: Store the data byte 32H into memory location/ Exchange the contents of memory
locations
Practical No. 1 A) Store the data byte 32H into memory location 2000H.

Aim: Store the data byte 32H into memory location 2000H.

Apparatus: Microprocessor 8085 simulator software kit 1.0.

Algorithm:

Step 1: Get the number to store in accumulator.

Step 2: Store the number in accumulator at intended memory location.

Step 3: Halt.

Program:

1. MVI A, 32H : "Store 32H in the accumulator"

2. STA 4000H : "Copy accumulator contents at address 4000H"

3. HLT : "Terminate program execution"

Alternate method:

1. LXI H : "Load HL with 4000H"

2. MVI M : "Store 32H in memory location pointed by HL register pair (4000H)"

3. HLT : "Terminate program execution"

Output:

Sample problem:

Conclusion:

1
Practical no.1B) Exchange the contents of memory locations 2000H and 4000H.
Aim: Exchange the contents of memory locations 2000H and 4000H.

Apparatus: Microprocessor 8085 simulator software kit 1.0.

Algorithm:
Step 1: Initialize HL pair with memory location 2000h where a number is stored.
Step 2: Get the contents of memory location into register B.
Step 3: Initialize HL pair with memory location 4000h where a number is stored.
Step 4: Get the contents of memory location into register A i.e. Accumulator.
Step 5: Move the contents of Register B into memory.
Step 6: Store the contents of Accumulator into memory location 2000h.

Program:

1. LDA 2000H : "Get the contents of memory location 2000H into accumulator"

2. MOV B, A : "Save the contents into B register"

3. LDA 4000H : "Get the contents of memory location 4000Hinto accumulator"

4. STA 2000H : "Store the contents of accumulator at address 2000H"

5. MOV A, B : "Get the saved contents back into A register"

6. STA 4000H : "Store the contents of accumulator at address 4000H"

Alternate method:

1. LXI H 2000H : "Initialize HL register pair as a pointer to memory location 2000H."

2. LXI D 4000H : "Initialize DE register pair as a pointer to memory location 4000H."

3. MOV B, M : "Get the contents of memory location 2000H into B register."

4. LDAX D : "Get the contents of memory location 4000H into A register."

5. MOV M, A : "Store the contents of A register into memory location 2000H."

6. MOV A, B : "Copy the contents of B register into accumulator."

7. STAX D : "Store the contents of A register into memory location 4000H."

8. HLT : "Terminate program execution."

2
Output:
Sample problem:

Conclusion:

3
Practical no.2 Add two 8-bit numbers
Aim: Add the contents of memory locations 4000H and 4001H and place the result in memory location 4002H.

Apparatus: Microprocessor 8085 simulator software kit 1.0.

Algorithm:

Step1:"HL points 4000H"

Step2:"Get first operand"

Step3:"HL points 4001H"

Step4:"Add second operand"

Step5:"HL points 4002H"

Step6:"Store result at 4002H"

Step7:"Terminate program execution"

Program:

1. LXI H 4000H

2. MOV A, M

3. INX H

4. ADD M

5. INX H

6. MOV M, A

7. HLT

Output:

Sample problem:

Conclusion:

4
Practical no.3 Subtract two 8-bit numbers
Aim: Subtract the contents of memory location 4001H from the memory location 2000H and place the result in
memory location 4002H.

Apparatus: Microprocessor 8085 simulator software kit 1.0.

Algorithm:

Step1: "HL points 4000H"

Step2: "Get first operand"

Step3: "HL points 4001H"

Step4: "Subtract second operand"

Step5: "HL points 4002H"

Step6: "Store result at 4002H"

Step7: "Terminate program execution"

Program:

1. LXI H, 4000H

2. MOV A, M

3. INX H

4. SUB M

5. INX H

6. MOV M, A

7. HLT

Output:
5
Sample problem:

Conclusion:

6
Practical no.4 Add two 16-bit numbers
Aim: Add the 16-bit number in memory locations 4000H and 4001H to the 16-bit number in memory locations
4002H and 4003H. The most significant eight bits of the two numbers to be added are in memory locations 4001H
and 4003H. Store the result in memory locations 4004H and 4005H with the most significant byte in memory location
4005H.

Apparatus: Microprocessor 8085 simulator software kit 1.0.

Algorithm:
1. "Get first I6-bit number in HL"

2. "Save first I6-bit number in DE"

3. "Get second I6-bit number in HL"

4. "Get lower byte of the first number"

5. "Add lower byte of the second number"

6. : "Store result in L register"

7. "Get higher byte of the first number"

8. "Add higher byte of the second number with CARRY"

9. "Store result in H register"

10. "Store I6-bit result in memory locations 4004H and 4005H"

11. "Terminate program execution"

"Get first I6-bit number in HL"

12. Save first I6-bit number in DE"

13. "Get second I6-bit number in HL"

14. "Get lower byte of the first number"

15. "Add lower byte of the second number"

16. "Store result in L register"

17. "Get higher byte of the first number"

18. "Add higher byte of the second number with CARRY"

19. "Store result in H register"

7
20. "Store I6-bit result in memory locations 4004H and 4005H"

21. "Terminate program execution"

Program:

1. LHLD 4000H

2. XCHG

3. LHLD 4002H

4. MOV A, E

5. ADD L

6. MOV L, A

7. MOV A, D

8. ADC H

9. MOV H, A

10. SHLD 4004H

11.HLT

Alternate method:

1. LHLD 4000H : Get first I6-bit number

2. XCHG : Save first I6-bit number in DE

3. LHLD 4002H : Get second I6-bit number in HL

4. DAD D : Add DE and HL

5. SHLD 4004H : Store I6-bit result in memory locations 4004H and 4005H.

6. HLT : Terminate program execution

8
Output:

Sample problem:

Conclusion:

9
Practical no.5 Add contents of two memory locations
Aim: Add the contents of memory locations 4000H and 4001H and place the result in the memory locations
4002Hand 4003H.

Apparatus: Microprocessor 8085 simulator software kit 1.0.

Algorithm:

1. "HL Points 4000H"

2. "Get first operand"

3. "HL Points 4001H"

4. "Add second operand"

5. "HL Points 4002H"

6. "Store the lower byte of result at 4002H"

7. "Initialize higher byte result with 00H"

8. "Add carry in the high byte result"

9. "HL Points 4003H"

10. "Store the higher byte of result at 4003H"

11. "Terminate program execution"

Program:

1. LXI H, 4000H

2. MOV A, M

3. INX H

4. ADD M

5. INX H

6. MOV M, A

7. MVIA, 00H

10
8. ADC A

9. INX H

10. MOV M, A

11. HLT

Output:

Sample problem:

Conclusion:

11
Practical no.6 Subtract two 16-bit numbers
Aim: Subtract the 16-bit number in memory locations 4002H and 4003H from the 16-bit number in memory
locations 4000H and 4001H. The most significant eight bits of the two numbers are in memory locations 4001H and
4003H. Store the result in memory locations 4004H and 4005H with the most significant byte in memory location
4005H.

Apparatus: Microprocessor 8085 simulator software kit 1.0.

Algorithm:

1. "Get first 16-bit number in HL"

2. "Save first 16-bit number in DE"

3. "Get second 16-bit number in HL"

4. "Get lower byte of the first number"

5. "Subtract lower byte of the second number"

6. "Store the result in L register"

7. "Get higher byte of the first number"

8. "Subtract higher byte of second number with borrow"

9. "Store l6-bit result in memory locations 4004H and 4005H"

10. "Store l6-bit result in memory locations 4004H and 4005H"

11. "Terminate program execution"

Program:

1. LHLD 4000H

2. XCHG

3. LHLD 4002H

4. MOV A, E

5. SUB L

6. MOV L, A

7. MOV A, D

8. SBB H
12
9. MOV H, A

10. SHLD 4004H

11. HLT

Output:

Sample problem:

Conclusion:

13
Practical no.7 Finding one’s complement of a number
Aim: Find the l’s complement of the number stored at memory location 4400H and store the complemented
number at memory location 4300H.

Apparatus: Microprocessor 8085 simulator software kit 1.0.

Algorithm:

1. "Get the number"

2. "Complement number"

3. "Store the result"

4. "Terminate program execution"

Program:

1. LDA 4400B

2. CMA

3. STA 4300H

4. HLT

Output:

Sample problem:

Conclusion:

14
Practical no.8 Finding Two’s complement of a number
Aim: Find the 2′s complement of the number stored at memory location 4200H and store the complemented number
at memory location 4300H

Apparatus: Microprocessor 8085 simulator software kit 1.0.

Algorithm:

1. "Get the number"

2. "Complement the number"

3. "Add one in the number"

4. "Store the result"

5. HLT

Program:

1. LDA 4200H

2. CMA

3. ADI, 01 H

4. STA 4300H

5. HLT

Output:

Sample problem:

Conclusion:

15
Practical no.09 Right shift, bit of data (8 bit and 16 bit)
Aim: Write a program to shift an eight bit data four bits right. Assume data is in register C.

Apparatus: Microprocessor 8085 simulator software kit 1.0.

Program:

MVI C,10H

1. MOV A, C

2. RAR

3. RAR

4. RAR

5. RAR

6. MOV C, A

7. HLT

Output:

Sample problem:

Conclusion:

16
Practical no.10 Left Shifting of a 16-bit data
Aim: Program to shift a 16-bit data 1 bit left. Assume data is in the HL register.

Apparatus: Microprocessor 8085 simulator software kit 1.0.

Program:

LXI H,1025H

DAD

HLT

Output:

Sample problem:

1. HL = 1025 = 0001 0000 0010 0101

2. HL = 0001 0000 0010 0101

3. + HL = 0001 0000 0010 0101

4. ----------------------------

5. Result = 0010 0000 0100 1010

Conclusion:

17
Practical 11
AIM: Design and develop a reprogrammable embedded computer using 8051
microcontrollers and to show the following aspects.

a. Programming
b. Execution
c. Debugging
Apparatus: Keil uvision 4.0.

The components of a reprogrammable embedded computer using 8051


microcontroller are shown below –

R/ W EPROM EPROM

Switch LCD
8051
Motor

Interface

Block diagram of 8051 microcontroller embedded system


A reprogrammable can be considered as an embedded system which can be
reprogrammed number of times easily, while providing flexibility. In other words,
we can say that for a reprogrammable embedded system, Microcontroller unit can
be reprogrammed without actually completely pulling out the MCU.

The reprogrammable microcontroller based embedded system also provides debug


facility for users.

The Reprogrammable embedded system consists of:

• Sockets for placing microcontroller- 40 pin


• DC socket for external power supply (DC 5V)
• 1 LED for power on indication and 1 push button for reset
• 11.0592 MHz Quartz Crystal Oscillator
• 8 LEDs for output pin state indication at port P0
• 1 DIP switch (8 switch) for input pin activation
• Connector and driver for serial communication RS232
18
• Multiple-pin connectors for direct access to I/O ports
• Connector for SPI programming
• 1 Piezo buzzer for audio/frequency output
• Additional power supply connectors

Steps-
1.First open Keil IDE software.
2.Go to new project.
3. Give name of project (do not add any .asm or c.extesion).
4. Now save your project after that select your microcontroller Atmel 89C51.
5. Now go to file and select new file.
6. Now save this editor file in the same folder where you save your project.

Algorithm-

1. Declare three unsigned char values.


2. Assign some data to two variables.
3. Declare port P0 as an output port.
4. Perform addition and store result into variables.
5. Display the result on port P0.
6. Stop.
9: Now add this file (save it with extension .c) in the project i.e. in source group 1.
10. Now right click on source group and click on build target.
11: Now go to debug section and click on start/stop.
12: Go to peripherals and select port here i m using port 1 .
13: Now run the project and you will get addition of two numbers in port 1.
write your program code here & save it.
Embedded C Code -
#include <reg51.h>
void main (void)
{
unsigned char x,y,z;
x=0x34;
y=0xa9;
P1=0x00;
z=x+y;
P1=z;
}
Calculation-

Addition of 0x34(0011 0100) + 0xa9(1010 1001) =(1101 1101) i.e 0xDD

19
Expected Output-

CONCLUSION-

20
Practical 12
Configure timer control registers of 8051 and develop a program to generate
given time delay.

Aim: Write an embedded C 8051 program to generate time delay for 1 second using the
timer control register. Demonstrate the delay by interfacing 8 LEDs with parallel port
P0, and blinking the LEDs with 1 s delay.

Apparatus: Keil uvision 4.0.

Algorithm-
1. Initialize Port 0 as output port.
2. Send a low value to the port 0 to turn off the LED. i.e. Move the data value
00 to port 0. This will switch off the LEDs connected at port 0.
3. Call delay function which will wait for calculated time interval.
4. Send active high value to the port 0 to turn on the LED. i.e. Move the data
value FF to port 0 this will glow all the LEDs connected at port 0.
5. Call delay
6. Repeat steps 2 – 5 in infinite loop.

21
Hardware connections

Circuit Dig of interfacing the LEDs with 8051 microcontroller using port1

22
Steps in Execution-

Open suitable development environment and create a new project. Add a new C file to
the project and save it as timer.c
Write the appropriate code. Build the hex file.
Use Flash Magic software to load the program in 8051 microcontroller. Execute the
program and observe output.

Embedded C Code -
#include<reg51.H>

void Delay(void);

void main(void)
{
while(1)
{
P1 = 0xFF; // Make all bits of P1 high
Delay();
P1 = 0x00; // Make all bits of P1 low
Delay();
}
}

void Delay(void)
{
int j;
int i;
for(i = 0; i < 1000; i++)
{
}
for(j = 0; j < 1000; j++)
{
}
}

23
Expected Output

CONCLUSION-

24
Practical 13
Port I / O: Use one of the four ports of 8051 for O/P interfaced to eight LED’s. Simulate binary
counter (8 bit) on LED’s

Aim: Write an embedded C program to configure Port 1 of 8051 microcontroller as output port.
Construct a binary counter output at port 1 of 8051. The counter should start counting from 00 H to
FF H. Demonstrate the output using 8 bit LED interface.

Apparatus: Keil uvision 4.0.

Algorithm-

1. Initialize port1 as output port.

2. Move the binary data value 00000000 to port1 this will switch off the LEDs connected at port1.

3. Call delay function which will wait for calculated time interval.

4. Increment the binary value by 1.

5. Call delay

6. Repeat steps 2 – 5 in infinite loop.

Hardware Connection-

25
Embedded C Code –

#include<REG51.H>

void main()

unsigned char seg [10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0X82,0XF8,0X80,0X90};

unsigned char x;

unsigned int i;

P1=0X00;

while(1)

for(x=0;x<10;x++)

P1=seg[x];

for(i=0;i<60000;i++);

26
Expected Output-

CONCLUSION-

27
Practical 14

To interface 8 LEDs at Input-output port and create different patterns.


Aim: Configure port 1 of 8051 microcontroller as output port. Connect a 8 bit LED interface at
port 1. Write an embedded C program to generate different patterns and display on the LED
interface.
Apparatus: Keil uvision 4.0.

Algorithm-

1. Set port 1 as output port.


2. set a value to generate a pattern. For example, 55 H will turn ON the
alternate LEDs
3. Call delay.
4. Change pattern.
5. Repeat steps 2 to 4 in an infinite loop.

Hardware Connections-

Same as 3 (a)

Embedded C Code

#include <reg51.h>

void ToDelay(void); // delay() function prototype

void main(void)
{
while(1)
{
P1=0xAA; // pattern to turn on alternate LEDs
ToDelay();
P1=0x55; // Reverse the sequence.
ToDelay();
}
}

void ToDelay()
{
unsigned int i,j;
for (j =0; j<24; j++)
for(i=0;i<1000;i++);
}

28
Expected Output-

LED Interface showing alternate LEDs turned ON

Some other patterns can be –

1.Four LEDs ON and four LEDs OFF; or alternate nibbles. (F0H and 0FH)

2.Two LEDs ON and Two OFF (11001100 – 00110011 or CCH and 33 H)

CONCLUSION-

29
Practical 15
Flash Magic

Aim: To demonstrate the procedure for flash programming for reprogrammable


embedded system board using Flash Magic
Apparatus: Flash magic 3.

Using Flash Magic-

Software required to use the hex file in the embedded systems is flash magic. Run
the flash magic software. Following interface appears

Fig 32 flash magic interface

Step 1
Select the communication device as 89V51RD2. This is the NXP microcontroller
used for executing the embedded system programs.

Step 2
Select the appropriate COM port. If a serial cable is used to connect the TKbase kit
to the PC at the default serial port, this would be a COM1 port. It can be checked
from control panel – hardware and sound – Device Manager - ports
Step 3
Select COM1 and baud rate as 9600.
30
If a USB to serial converter is used to connect the PC with the TKbase trainer, the
device drivers would be installed for a relevant COM port.
This can be checked in the Device manager. Select the relevant COM port. Baud
rate for this communication will however, remain 9600.

Step 4
Select the default None (ISP) interface.

Step 5
From options – Advance options – hardware config tab, uncheck the marks for use
DTR for control RST as well as Assert DTR and RTS while COM port open option.
This is shown below

Fig 33 setting options for flash magic communication software

Fig 34 after all correct settings

31
Step 6
Choose to erase all flash memory contents to make place or
to load the fresh program into 8051 memory.

Step 7
Browse and select the compiled and build program in the form of hex file.
Choose the verify after programming option in step4. Do not
check any other option.

Step 8
Connect the TKbase trainer kit with the PC using relevant port.
Use the serial data cable, or USB to serial converter or bridge for
this connection. Do necessary hardware connections.

Step 9
Give power to the kit. Press the reset button on the kit. Then click
on the start button of the flash magic interface as shown above.
After the software prompts to reset device in ISP mode, press
reset again.

Step 10
Now the hex file is downloaded. Press reset again to execute
the downloaded program.

CONCLUSION-

32
33

You might also like