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

Microprocesssors

and
Microcontrollers
Laboratory
Manual

DK Raheja
Contents
1(a). Write a program to add two 16-bit numbers with/without carry using 8086 microprocessor. .... 1
1(b). Write a program to subtract two 16-bit numbers with/without borrow using 8086
microprocessor. ...................................................................................................................................... 5
2. Write a program to multiply two 8-bit numbers by repetitive addition using 8086. ......................... 9
3. Write a program to generate Fibonacci series up to 16 terms. ........................................................ 13
4. Write a program to generate factorial of a number from 0 to 9. ..................................................... 17
5 .Write a program to read 16 bit data from a port and display the same in another port. ................ 23
7 .Write a program to generate square wave of 10 KHz using timer 1 in mode 1(using 8051
microcontroller). ................................................................................................................................... 27
9. Write a program to transfer data from ROM memory to RAM memory. .................................... 31
10. Write a program for the traffic light controller using 8086 microprocessor. ................................. 35
1(a). Write a program to add two 16-bit numbers with/without
carry using 8086 microprocessor.

Apparatus: 8086 trainer kit and 8086 emulator software.


Flow Chart

Start

Initialize CX register with


0000H

Get the first number in AX


register and second number
in BX

Add the two numbers

Yes
Is carry
Increment
generated
the CX
?
register
No

Move the sum at the address


3004H and carry at address
3006H

Stop

Program written on 8086 Trainer Kit


Memory Address Instruction Comment
2000 MOV CX,0000 Move data 0H to CX register

1
2003 MOV AX,92F0 Move data 92F0H to AX
register
2006 MOV BX,92F0 Move data 92F0H to BX
register
2009 ADD AX, BX Add the content of AX and
BX registers
200B JNC 200E Jump to the address 200EH if
no carry is generated from
the AX register
200D INC CX Increment the content of CX
register
200E MOV [3004], AX Move the content to AX
register to the address 3004H
2012 MOV [3006], CX Move the content to CX
register to the address 3004H
2016 INT 3 Call the interrupt type 3 to
insert breakpoint

Procedure to be followed for the 8086-trainer kit


1. Connect the keyboard to the 8086- trainer kit.
2. Switch on the power supply and the trainer kit.
3. Press Enter Key to come on the main menu containing alphabets (. i.e., A, D, F, G, I, M, P,
T, L)
4. To load the Assemble Language Program, type key ‘A’, space, the starting address of the
program and press Enter Key.
e.g. A 2000
5. Now, type the above program. Press Enter Key after writing the each instruction and use
backspace key to correct any mistake.
6. After writing the program, press F7 key to come on the main menu.
7. To execute the program, type key‘G’ and the starting address of the program. (e.g. G
0000:2000). After that press Enter Key and F7.
8. To check the result, press D key, space, memory address of the result and press Enter Key.
(e.g. D 3004 and D 3006)

Result on 8086 trainer kit


The two same numbers are added, which is 92F0 H. Output shown in the 8086 Trainer Kit is
0000:3004 E0 25 01 00. Where E0H is the lower byte at address 3004H,25H is the upper byte
at address 3005H and carry ‘01H’is at the address 3006H.Therefore, the sum of the two
numbers=125E0 H.
Procedure for the 8086 Emulator
1. Press New Tab, select COM template and press OK.
2. Delete the previously written instructions and type the program as shown in the Figure 1.
3. Click on the Emulate Tab and a dialog box appears. Then, click on the Run Tab to execute
the program.

2
4. To check the result, click on the Vars Tab which is at the bottom of the dialog box.

Figure 1.16 bit Addition using Assembler Directives in the 8086 emulator.

3
Result on 8086 emulator
The two same 16 -bit numbers are added, which are stored at the memory address labelled as
NUM1 and NUM2. The sum of the two numbers are stored at the memory address labelled as
SUM and the carry is stored at the memory address labelled as CARRY as shown in the Figure
2(. i.e., 92F0 H+92F0 H=125E0 H).

Figure 2. Output of the addition of two 16-bit numbers using 8086 emulator

4
1(b). Write a program to subtract two 16-bit numbers with/without
borrow using 8086 microprocessor.

Apparatus: 8086 trainer kit and 8086 emulator software.


Flow Chart:

Start

Initialize CX register with


0000H

Get the first number in AX


register and second number
in BX

Subtract second number from first number numbers

Yes
Is borrow
Increment
generated
the CX
register
No

Store the sum at the address


3004H and carry at address
3006H

Stop

Program (8086 Trainer Kit)

Memory Address Instruction Comment


2000 MOV CX,0000 Move data 0H to CX register

5
2003 MOV AX,92F0 Move data 92F0 H to AX
register
2006 MOV BX,60AE Move data 60AE H to BX
register
2009 SUB AX, BX Subtract the content of BX
register from AX register
200B JNC 200E Jump to the address 200EH if
no borrow from the AX
register
200D INC CX Increment the content of CX
register
200E MOV [3004], AX Move the content to AX
register to the address 3004H
2012 MOV [3006], CX Move the content to CX
register to the address 3004H
2016 INT 3 Call the interrupt type 3 to
insert breakpoint

Procedure to be followed for the 8086-trainer kit


1. Connect the keyboard to the 8086- trainer kit.
2. Switch on the power supply and the trainer kit.
3. Press Enter Key to come on the main menu containing alphabets (. i.e., A, D, F, G, I, M, P,
T, L)
4. To load the Assemble Language Program, type key ‘A’, space, the starting address of the
program and Enter Key.
e.g. A 2000
5. Now, type the above program. Press Enter Key after writing the single instruction and use
backspace key to correct any mistake.
6. After writing the program, press F7 key to come on the main menu.
7. To execute the program, type key ‘G’ and the starting address of the program. (e.g. G
0000:2000). After that Press Enter Key and F7.
8. To check the result, press D key, space, memory address of the result and Enter Key. (e.g.
D 3004 and D 3006)

Result using 8086 trainer kit:


The 16-bitnumber 60AE H is subtracted from 16-bit number 92F0 H. Output shown in the 8086
Trainer Kit is 0000:3004 42 32 01 00. Where 42 is the lower byte at address 3004H, 32 is the
upper byte at address 3005H and borrow ‘00’is at the address 3006H.Therefore, the subtraction
of the two numbers=3242 H.
Procedure for the 8086 Emulator
1. Press New Tab, select COM template and press OK.
2. Delete the previously written instructions and type the program as shown in the Figure 3.
3. Click on the Emulate Tab and a dialog box appears. Then, click on the Run Tab to execute
the program.

6
4. To check the result, click on the Vars Tab which is at the bottom of the dialog box.

Figure 3.16-bit subtraction using Assembler Directives in the 8086 emulator.


Result using 8086 emulator
The 16 -bit numbers 60AE stored at the memory address labelled as NUM2 is subtracted from
the 16 bit number 92F0H stored at the memory address labelled as NUM1. The subtraction of
the two numbers are stored at the memory address labelled as SUBT and the borrow is stored
at the memory address labelled as BORROW as shown in the Figure 4(. i.e., 92F0 H- 60AE
H=3242 H).

7
Figure 4 Output of the subtraction of two 16-bit numbers using 8086 emulator

8
2. Write a program to multiply two 8-bit numbers by repetitive
addition using 8086.

Apparatus: 8086 trainer kit and 8086 emulator.


Flow Chart:

Start

Initialize AL register
with 00H

Move first number in


BL register

Initialize CL register
with 00H

Move second number


in DL register

Add content of AL
and BL registers

No
Is carry
generate
d?
Yes
Stop
Increment the CL
register by one
Move the result from
the AX register to
Decrement the DL memory address
register by one 3004H

Move the data from


Yes Is DL No
register not CL register to AH
zero? register
9
Program written on 8086 kit
Memory Address Instruction Comment
2000 MOV AL,00 Initialize AL register with
00H
2002 MOV BL, FF Move first number in BL
register
2004 MOV CL,00 Initialize CL reg. with 00H
2006 MOV DL, FF Move second number in DL
register
2008 ADD AL, BL Add content of AL and BL
registers
200A JNC 200E Jump to the memory address
200EH if carry is generated
200C INC CL Increment the CL register
200E DEC DL Decrement the DL register
2010 JNZ 2008 Jump to the memory address
2008H if data in DL register
is not zero
2012 MOV AH, CL Move the data from CL
register to AH register
2014 MOV [3004], AX Move the result from the AX
register to memory address
3004H
2018 INT 3 Call the interrupt type 3 to
insert breakpoint

Procedure to be followed for the 8086-trainer kit


1. Connect the keyboard to the 8086- trainer kit.
2. Switch on the power supply and the trainer kit.
3. Press Enter Key to come on the main menu containing alphabets (. i.e., A, D, F, G, I, M, P,
T, L)
4. To load the Assemble Language Program, type key ‘A’, space, the starting address of the
program and press Enter Key.
e.g. A 2000
5. Now, type the above program. Press Enter Key after writing the each instruction and use
backspace key to correct any mistake.
6. After writing the program, press F7 key to come on the main menu.
7. To execute the program, type key‘G’ and the starting address of the program. (e.g. G
0000:2000). After that press Enter Key and F7.
8. To check the result, press D key, space, memory address of the result and press Enter Key.
(e.g. D 3004)

10
Result on 8086 trainer kit
The two same 8 bit numbers are multiplied, which is FF H. Output shown in the 8086 Trainer
Kit is 0000:3004 01 FE 09 00.Where 01H is the lower byte at address 3004H,FEH is the upper
byte at address 3005H.Therefore, the multiplication of the two numbers=FE01 H.

Procedure for the 8086 Emulator


1. Press New Tab, select COM template and press OK.
2. Delete the previously written instructions and type the program as shown in the Figure 5.
3. Click on the Emulate Tab and a dialog box appears. Then, click on the Run Tab to execute
the program.
4. To check the result, click on the Vars Tab which is at the bottom of the dialog box.

Figure 5. Multiply 8 bit number using emu8086 software.

11
Result on 8086 emulator
The two same 8 -bit numbers are multiplied, which are stored at the memory address labelled
as NUM1 and NUM2. The multiplication of the two numbers are stored at the memory address
labelled as ANS as shown in the Figure 6(. i.e., FF H×FF H=FE01 H).

Figure 6. Result of 8 bit multiplication.

12
3. Write a program to generate Fibonacci series up to 16 terms.

Apparatus: 8086 trainer kit and 8086 emulator software.


Flow Chart

Start

Move the number of terms in


the CL register

Initialize BL register with 0H


and DL register with 01H
respectively

Move the starting location of


the result in the DI register

Move data from DL register to


AL register

Add data in AL and BL


registers

Move the data from AL register


to the address stored in DI
register

Increment the DI register by


one

Move data from DL to the BL


register and AL to DL register

Decrement the CL register by


one

Yes
Is data in No
CL register Stop
not zero?
13
Program written on 8086 emulator
Memory Address Instruction Comment
1100 MOV CL,10 Move the number of terms (.i.e.,10H) in the CL
register
1102 MOV BL,00 Initialize BL register with 0H
1104 MOV DL,01 Initialize DL register with 01H
1106 MOV DI,2000 Move the starting location of the result in the DI
register
1109 MOV AL,DL Move data from DL register to AL register
110B ADD AL,BL Add data in AL and BL registers
110D MOV [DI],AL Move the data from AL register to the address
stored in DI register
110F INC DI Increment the DI register to go to the next memory
location
1110 MOV BL,DL Move data from DL to the BL register
1112 MOV DL,AL Move data from AL to DL register
1114 DEC CL Decrement the CL register by one
1116 JNZ 110B Jump to the 110B address if data in CL register is
not zero
1118 INT 3 Call the interrupt type 3 to insert breakpoint

Procedure to be followed for the 8086-trainer kit


1. Connect the keyboard to the 8086- trainer kit.
2. Switch on the power supply and the trainer kit.
3. Press Enter Key to come on the main menu containing alphabets (. i.e., A, D, F, G, I, M, P,
T, L)
4. To load the Assemble Language Program, type key ‘A’, space, the starting address of the
program and press Enter Key.
e.g. A 2000
5. Now, type the above program. Press Enter Key after writing the each instruction and use
backspace key to correct any mistake.
6. After writing the program, press F7 key to come on the main menu.
7. To execute the program, type key‘G’ and the starting address of the program. (e.g. G
0000:1100). After that press Enter Key and F7.
8. To check the result, press D key, space, memory address of the result and press Enter Key.
(e.g. D 2000)

Result on 8086 trainer kit


The number of terms of the Fibonacci series is 16.Output shown in the 8086 Trainer Kit is
0000:2000 01 02 03 05 08 0D 15 22
0000:2008 37 59 90 E9 79 62 DB 3D

14
The first terms .i.e., 01H is at the 2000H address, second term .i.e., 02H is at 2001H address,
third term .i.e., 03H is at 2002 H address and so on. Therefore the generated Fibonacci series
is 01H,02H,03H,05H,08H,0DH,15H,22H,37H,59H,90H,E9H,79H,62H,DBH and 3DH.

Procedure for the 8086 Emulator


1. Press New Tab, select COM template and press OK.
2. Delete the previously written instructions and type the program as shown in the Figure 7.
3. Click on the Emulate Tab and a dialog box appears. Then, click on the Run Tab to execute
the program.
4. To check the result, click on the Vars Tab which is at the bottom of the dialog box.

Figure 7.Fibonacci series program in emu8086 software.

15
Result on 8086 emulator
The number of terms of the Fibonacci series is 16. The output of the generated Fibonacci series
is shown in the Figure 8.The generated Fibonacci series is
01H,02H,03H,05H,08H,0DH,15H,22H,37H,59H,90H,E9H,79H,62H,DBH and 3DH.

Figure 8.Result of Fibonacci Series in emu8086 software

16
4. Write a program to generate factorial of a number from 0 to 9.

Apparatus: 8086 Trainer Kit and 8086 Emulator software.


Flow Chart:
Start

Move a number whose factorial


is to be find in the BX register

Move 01H to the AX and CX


register

Initialize DX register with 00H

Compare data in BX register


with zero

Yes
Is data
= 00h

No

Multiple data in CX register with


data in AX register

Increment data in CX register


Decrement data in BX register

Yes Is data in BX
register not
equal to zero?

No

Move the result from AX reg. and


BX reg. to memory location 3004H
and 3006H respectively

Stop
17
Program written on trainer kit:
Memory Address Instruction Comment
2000 MOV BX, [0500] Move data from memory address
0500 to BX register
2004 MOV AX,01 Move data 01H in AX register
2007 MOV CX,01 Move data 01H in CX register
200A MOV DX,00 Move data 00H in DX register
200D CMP BX,00 Compare data in BX register
with 00H
2011 JZ 2019 Jump if data in BX register is
zero to memory address 2019H
2013 MUL CX Multiple data in CX register with
data in AX register
2015 INC CX Increment data in CX register
2016 DEC BX Decrement data in BX register
2017 JNZ 2013 Jump if data in BX register is not
zero to memory address 2013H
2019 MOV [3004], AX Move the data in AX register to
the memory address 3004H
201D MOV [3006], DX Move the data in DX register to
the memory address 3006H
2021 INT 3 Call the interrupt type 3 to insert
breakpoint

Procedure to be followed for the 8086-trainer kit


1. Connect the keyboard to the 8086- trainer kit.
2. Switch on the power supply and the trainer kit.
3. Press Enter Key to come on the main menu containing alphabets (. i.e., A, D, F, G, I, M, P,
T, L)
4. To load the Assemble Language Program, type key ‘A’, space, the starting address of the
program and Enter Key.
e.g. A 2000
5. Now, type the above program. Press Enter Key after writing the single instruction and use
backspace key to correct any mistake.
6. After writing the program, press F7 key to come on the main menu.
7. Load the memory address 0500H with a number whose factorial is be find, before
executing the program by doing the step number 9 and type number at the exact location
using movement of the cursor.
8. To execute the program type key ‘G’ and the starting address of the program. (e.g. G
0000:2000). After that Press Enter Key and F7.
9. To check the result, press D key, space, memory address of the result and Enter Key. (e.g.
D 3004 and D 3006)
10. To again check result of the same program follow the following procedure
a. Press F7
b. Press reset key
c. Do step 7, 8 and 9.

18
Result on 8086 trainer kit:
Factorial of nine
0000:3004 80 89 05 00
According to the above result, the factorial of 9 is 0058980H.

Factorial of zero
0000:3004 01 00 00 00
According to the above result, the factorial of 0 is 00000001H

Procedure for the 8086 Emulator


1. Press New Tab, select COM template and press OK.
2. Delete the previously written instructions and type the program as shown in theFigure 10.
3. Click on the Emulate Tab and a dialog box appears. Then, click on the Run Tab to execute
the program.
4. As soon as Run Tab is pressed, emulator screen will appear to take user input.
5. Enter a number from 0 to 9, whose factorial is to be find on the emulator screen as shown
in the Figure 11and Figure 13.A message appears as shown in theFigure 9. Then press OK.
6. To check the result, click on the Vars Tab which is at the bottom of the dialog box.

Figure 9. Message.

19
Program on 8086 emulator

Figure 10. Factorial of a number in emu8086 software

Result on 8086 emulator


Factorial of nine
For finding the factorial of the nine, number 9 is entered on the emulator screen. After executing
the program, the lower word of the result is moved to the memory address labelled as FACT

20
AX and upper word of the result is moved to the memory address labelled as FACTDX.As
shown in the Figure 12, factorial of 9 is 00058980H.
Factorial of zero
For finding the factorial of the nine, number 0 is entered on the emulator screen. After executing
the program, the lower word of the result is moved to the memory address labelled as FACT
AX and upper word of the result is moved to the memory address labelled as FACTDX.As
shown in the Figure 14, factorial of 9 is 0000 0001H.

Figure 11. Assembler takes 9 as user input

Figure 12. Result of factorial of 9.

21
Figure 13.Assembler takes 0 as user input.

Figure 14.Result of factorial of 0.

22
5 .Write a program to read 16 bit data from a port and display
the same in another port.

Apparatus: 8086 emulator software


Flow Chart
Start

Move 16 bit data in AX


register

Write the data into


PORT1 from AX register

Reset the AX register

Read the data in AX register


from PORT1

Move the data to a


memory location from the
AX register

Write the data into


PORT2 from AX register

Read the data in AX


register from PORT2

Move the data to another


memory location from the
AX register

Stop

23
Program
Assembler Directives Instruction Comment
. MODEL SMALL Select the small model
.DATA Start Data segment
READ_P1 DW? 16 bit space is allocated
starting at memory location
READ_P1
WRITE_P2 DW? 16 bit space is allocated
starting at memory location
WRITE_P2
.CODE Start Code segment
.STARTUP Start program
DATA1 EQU 1234H Data 1234H is replaced by
the name DATA1
PORT1 EQU 112 Port address 112 is replaced
by name PORT1
PORT2 EQU 110 Port address 110 is replaced
by name PORT2
MOV AX, DATA1 Move 16 bit data in AX
register
OUT PORT1,AX Write the data into PORT1
from AX register
MOV AX,0 Reset the AX register
IN AX,PORT1 Read the data in AX register
from PORT1
MOV [READ_P1],AX Move the data to memory
location READ_P1 from the
AX register
OUT PORT2,AX Write the data into PORT2
from AX register
IN AX,PORT2 Read the data in AX register
from PORT2
MOV [READ_P2],AX Move the data to memory
location READ_P2 from the
AX register
.EXIT Terminate the execution
END End of program

Procedure
1. Press New Tab, select COM template and press OK.
2. Delete the previously written instructions and type the program as shown in the Figure 15.
3. Click on the Emulate Tab and a dialog box appears. Then, click on the Run Tab to execute
the program.
4. To check the result, click on the Vars Tab which is at the bottom of the dialog box.
5. The output can be seen by clicking the virtual devices tab as shown in the Figure 16.

24
Figure 15. Program to read16 bit data from port1 and display the same on Port2

Figure 16. Virtual Devices Tab

25
Result
As shown in the Figure 17, 1234H is read from the port 1 and moved the memory address
labelled as READ_P1.The same data is written on the port 2 and moved to the memory address
labelled as READ_P2.
The same data is shown at both ports with port addresses 110 and 112 as shown in the Figure
18.The data read on the port 112 is 1234H and on port 110 is 34H. The data shown in the port
110 is lower byte of the 16 bit data because port 110 is inbuilt programmed to show only lower
8 bit of data.

Figure 17. Result of reading same data on port1 and port2.

Figure 18. Result on the Virtual Ports.

26
7 .Write a program to generate square wave of 10 KHz using
timer 1 in mode 1(using 8051 microcontroller).

Apparatus: Keil µVision5 Software


TMOD Register value: 0001000 B
Calculation of delay
The frequency of the square wave is 10 KHz. So, the time period of the 1 cycle of square wave
is calculated by the following equation
1 1
T= = = 0.1 ms
f 10 × 103
Therefore, the time period of half cycle of square wave is 50μs.
Crystal frequency=11.0592 MHz≈ 12MHz.
The crystal frequency is divided by 12 because 1 machine cycle comprises of 12 clocks.
Crystal frequency 12 MHz
= = 1MHz
12 12
1
Therefore, delay required to execute one instruction=1MHz = 1μs

But our requirement is 50µs delay.


50×10−6
So, the number of cycles required in timer = 1×10−6 = 50 cycles

Now, convert 50(decimal) cycles to hexadecimal number = 32H


Now, subtract this value from maximum value of timer, which is FFFFH to calculate the delay.
DELAY=FFFFH-0032H=FFCDH
So, FFH is loaded in the higher byte timer1 (TH1) and CDH is loaded in the lower byte Timer
1(TL1).

27
Flow Chart
Start
DELAY (Subroutine)

Move 10 H in the
Move FFH to higher
TMOD register
nibble of Timer 1
Main
Program Move 00H to the port1
Move CD H to lower
nibble of Timer 1
Move FFH to the port1
Set the Timer 1
Short Jump
Check the overflow
condition of Timer 1
Stop

Clear the Timer 1

Clear the TF1

Return to the main


program

Program
Assembler Directive Instruction Comment
ORG 0000H Starting address of the
program is 0000H
TMOD_REG EQU 10H 10 H is replaced by
TMOD_REG
COUNT_H EQU 0FFH 0FFH is replaced by
COUNT_H
COUNT_L EQU 0CDH 0CD H is replaced by
COUNT_L
P1_H EQU 0FFH 0FFH is replaced by P1_H
P1_L EQU 00H 00H is replaced by P1_L
MOV TMOD Move 10H in TMOD register
,#TMOD_REG
BACK MOV P1,#P1_L Move 00H to the port1
ACALL DELAY Call the DELAY subroutine
MOV P1,#P1_H Move FF H to the port1
ACALL DELAY Call the DELAY subroutine
SJMP BACK Short jump to the BACK

28
DELAY MOV TH1,#COUNT_H Move FFH to the lower byte
of Timer1
MOV TL1,#COUNT_L Move CDH to the higher
byte of Timer1
SETB TR1 Start the Timer 1
LOOP JNB TF1,LOOP Monitor the Timer 1 flag
CLR TR1 Stop the Timer 1
CLR TF1 Clear the Timer 1 flag
RET Return to the main program
END End of program

Procedure
1. Go to the Tab ‘Project’ and select ‘New µvision Project’. After that give the project name
and save it.
2. Then a dialog box appers automatically for selecting the reqiured 8051 chip. Select
Microchip and then select AT 89C51 microcontroller chip.
3. Go to the File Tab.Click on ‘New’ tab . Then a new page named’Text1’ appears, in which
we write the program as shown in the Figure 21.
4. After writing the program, Save it with name same as before with the extension of .asm
(for assembly language program). After saving , all the keywords are highlighted.
5. Right click on Target1 (on the project Window) ,a dialog box appears. Now go to ‘Options
for Target ‘Target’ Tab and then, change the crystal frequency of the microcontroller (for
AT89C51) to 11.0592 GHz.

6. Now, click on icon to translate for running the first time .This will give errors and

warnings. After that, click on icon to build the program.

7. To debug the program, click on icon .


8. To see the square wave, click on the icon to see the logic analyser. Then click on this
icon and wirte the port name for example P1 for port1. Also select bit from Disply Type.
9. To run the program ,click on the icon .

29
Figure 19. Program to generate square wave in Keil software.
Result
The generated square wave of 10 KHz on Port 1 is shown in the Figure 20.

Figure 20. Generated Square Wave

30
9. Write a program to transfer data from ROM memory to RAM
memory.
Apparatus: Keil µVision5 Software
Flow Chart
Start

Load the ROM pointer

Load the RAM pointer

Load the counter

Move data from ROM to


accumulator

Move data from


accumulator to RAM

Increment the ROM


pointer

Increment the RAM


pointer

Clear the accumulator

Decrement the counter

No
Is counter
zero?

Stop

31
Program
Assembler Directive Instruction Comment
ORG 0000H Starting address of the
program is 0000H
ROM_POINTER EQU Replace 600H with
600H ROM_POINTER
RAM_POINTER EQU 60H Replace 60H with
RAM_POINTER
COUNTER EQU 06H Replace 06H with
COUNTER
MOV DPTR, Load the ROM pointer in
#ROM_POINTER DPTR register
MOV R0,#RAM_POINTER Load the RAM pointer in R0
register
MOV R7,#COUNTER Load the counter in R7
register
BACK MOVC A,@ A+DPTR Move the data from ROM
code space to Accumulator
MOV @R0,A Save it in the RAM
INC DPTR Increment the ROM pointer
INC R0 Increment the RAM pointer
CLR A Clear the Accumulator
DJNZ R7,BACK Decrement R7 and jump if R7
is not zero to BACK
ORG 600H Go to the ROM address 600H
DB Save the six 8-bit numbers
23H,45H,55H,67H,88H,97H
END End of program

Procedure
1. Go to the Tab ‘Project’ and select ‘New µvision Project’. After that give the project name
and save it.
2. Then a dialog box appers automatically for selecting the reqiured 8051 chip. Select
Microchip and then select AT 89C51 microcontroller chip.
3. Go to the File Tab.Click on ‘New’ tab . Then a new page named’Text1’ appears, in which
we write the program as shown in the Figure 21.
4. After writing the program, Save it with name same as before with the extension of .asm
(for assembly language program). After saving , all the keywords are highlighted.
5. Right click on Target1 (on the project Window) ,a dialog box appears. Now go to ‘Options
for Target ‘Target’ Tab and then, change the crystal frequency of the microcontroller (for
AT89C51) to 11.0592 GHz.

6. Now, click on icon to translate for running the first time .This will give errors and

warnings. After that, click on icon to build the program.

7. To debug the program, click on icon .

32
8. To see ROM memory, write C:600H in the memory window (Select from View Tab) and
to see RAM memory, write D:60H in the same the memory window.
9. To run the program ,click on the icon .

Figure 21. Program to transfer data from ROM memory to RAM memory.
Result
ROM memory is shown in the Figure 22, containing the saved six 8-bit numbers and RAM
memory is shown in the Figure 23, containing the same six 8-bit numbers (after the execution
of program).

Figure 22. ROM Memory

33
Figure 23. RAM Memory

34
10. Write a program for the traffic light controller using 8086
microprocessor.

Apparatus: 8086n emulator software


Flow Chart
Start

Write data on port address 04H to


turn ON all red lights

Move the offset of memory


address ’SITUATION’ in the SI
register

Load the data containing various situation


of traffic light from memory address
pointed by the register SI in AX register
and write it on port address 04H
Delay/Wait

Go to the next situation

Compare data in SI register with


SIT_END

Yes Is Situation
below from
SIT_END?

No
Move the offset of memory
address ’SITUATION’ in the SI
register

Stop

35
Program
Assembler Directives Instructions Comment
.MODEL SMALL Select the small model
.DATA Start data segment
SITUATION DW Allocate space starting
030CH,069AH,0861H,0861H,04D3H at the memory address
‘SITUATION’ for five
16 bit number.
.CODE Start code segment
.STARTUP Start the program
SIT_END EQU $ Replace $ with name
‘SIT_END’
ALL_RED EQU 0249H Replace number 0249H
with name ‘ALL_RED’
MOV AX,ALL_RED Move all_red data in
AX register
OUT 04H,AX Write the data on port
address 04H
MOV SI,OFFSET Move the offset of
SITUATION memory address
‘SITUATION’ in the SI
register
NEXT MOV AX,[SI] Move the data from
memory address
pointed by the register
SI in AX register
OUT 04H,AX Write that data on port
address 04H
MOV CX,4CH Move the higher order
word of count for delay
in register CX
MOV DX,4B40H Move the lower order
word of count for delay
in register DX
MOV AH,86H Interrupt of wait/delay
INT 15 H
ADD SI,2 Go to the next word
CMP SI,SIT_END Compare data in SI
register with SIT_END
JB NEXT Jump if below to NEXT
MOV SI,OFFSET Again, Move the offset
SITUATION of memory address
’SITUATION’ in the SI
register
JMP NEXT
.EXIT Terminate the program
execution

36
END Stop reading the
program

Procedure
1. Press New Tab, select COM template and press OK.
2. Delete the previously written instructions and type the program as shown in the Figure 24.
3. Click on the Emulate Tab and a dialog box appears. Then, click on the virtual devices tab
and then select traffic light option.
4. To execute the program click on Run Tab to the output.

Figure 24. Program for the traffic light controller


Result
In the output, different situations of traffic light can be seen as shown in the Figure 25. For
example

37
 ALL_RED is used to turn ON all the red lights to stop the traffic.
 SITUATION (030CH) is used to move traffic in north and south direction.
 SITUATION (069AH) is used to make the traffic wait.
 SITUATION (0861H) is used to move traffic in east and west direction.
 SITUATION (04D3H) is used to make the traffic wait.

Figure 25.Traffic light controller output

38

You might also like