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

MPMC Manual

The document describes an assembly language programming lab that covers 8086 and 8051 microprocessors. It lists experiments on arithmetic operations, sorting, interfacing peripherals, and ARM Cortex M3 programming. The equipment required includes power supplies, oscilloscopes, microprocessor and microcontroller kits.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

MPMC Manual

The document describes an assembly language programming lab that covers 8086 and 8051 microprocessors. It lists experiments on arithmetic operations, sorting, interfacing peripherals, and ARM Cortex M3 programming. The equipment required includes power supplies, oscilloscopes, microprocessor and microcontroller kits.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 80

Microprocessors and Microcontrollers Lab

COURSE CODE: UR19PCEC611


B.Tech.VI Semester L T P C
0 0 3 1.5
MICROPROCESSOR AND MICROCONTROLLERS LAB
Internal Marks: 15
External Marks: 35
COURSE OBJECTIVES:
1. This course introduces the assembly language programming of 8086 and 8051
microcontroller.
2. It gives a practical training of interfacing the peripheral devices with the 8086
microprocessor.
3. The course objective is to introduce the basic concepts of microprocessor and
to develop in the student the assembly language programming skills and real
time applications of microprocessor as well as microcontroller.
LIST OF EXPERIMENTS:
PART – A: (Minimum of 5 experiments has to be performed) 8086 assembly
language programming and Interfacing
1. Programs for 16 – bit arithmetic operations (using various addressing modes.)
a. Addition of n – BCD numbers.
b. Multiplication and Division operations.
2. Program for sorting and array.
3. Program for Factorial of given n – number.
4. Interfacing ADC to 8086.
5. Interfacing DAC to 8086.
6. Interfacing of stepper motor to 8086.
PART – B: (Minimum of 5 experiments has to be performed) 8051 assembly
language programming and interfacing
1. Finding number of 1‟s and number of 0‟s in a given 8 – bit number.
2. Average of n – numbers.
3. Program and verify timer/ Counter in 8051.
4. Interfacing traffic light controller to 8051.
5. UART operation in 8051.
6. Interfacing LCD to 8051.
PART – C: (Minimum of 2 Experiments has to be performed) conduct the following
experiments using ARM CORTEX M3 PROCESSOR USING KEIL MDK ARM.
1. Write an assembly program to multiply of two 16 – bit binary numbers.
2. Write an assembly program to find the sum of first 10 integer‟s numbers.
3. Write a program to toggle LED every second using timer interrupt.
EQUIPMENT REQUIRED:
1. Regulated power supplies.
2. Analog/ Digital storage Oscilloscopes.
3. 8086 Microprocessor kits.
4. 8051 Microcontroller kits.

URCET Department of ECE


Microprocessors and Microcontrollers Lab

Experiment no - 1

INTRODUCTION TO TASM

URCET Department of ECE


Microprocessors and Microcontrollers Lab

EXP.NO:- DATE:-
ASSEMBLY LANGUAGE PROGRAMMING USING TASM SOFTWARE
The programs are written using assembly language in editor then compile it. The
complier converts assembly language statements into machine language
statements/checks for errors. Then execute the compiled program.

There are different softwares developed by different companies for


assembly language programming, they are:

MASM -Microsoft Company

TASM -Bore Land Company

MERITS OF MASM:

1. Produces binary code


2. Referring data items by their names rather than by their address

HOW TO ENTER INTO TASM EDITOR:

➜ Click DOS BOX icon on the desktop.


➜ Path setting
Suppose it display path as Z: \>

Then type MOUNTCZ: \TASM then drive c is mounted as local directory

Z:\TASM\
Then the path is Z: \>

Then type C: \>

Then the path is C: \>


Then type edits i.e.; C:\>edit

Then you enter into TASM text editor


Write the ALP (Assembly Language Program) in this editor

After writing the program, save the file name with .asm extension
After save the file, click on file menu then go to exit then exit from the editor and go to
prompt

URCET Department of ECE


Microprocessors and Microcontrollers Lab

Then type TASM file name.ASM


I.e .C: \>TASM file name.ASM
Then link this file using C:\>tlink filename.OBJ
i.e., link the program in assembly with DOS then debug to create exe file
C:\>tdfilename.EXE
Then it display“-”on the screen

After that type „R‟ displays there glisters contents and starting step of the program.

„T‟ tracing at contents of program step by step


Suppose you need to go for break point debugging. Then type that instruction no where you
need to check your register. For example T10 it will display the contents of register after
executing 10 instructions.
DEBUG:
This command utility enables to write and modify simple assembly language programs in
an easy fashion. It provides away to run and test any program in a controlled environment.
We can change any part of the program and immediately execute the program with
resemble of it. We can also run machine language (Object files) directly by using DEBUG.
DEBUG COMMANDS:

ASSEMBLE A [address] ; Assembly the instructions at a particular address


COMPARE C range address ; Compare two memory ranges

DUMP D [range] ; Display contents of memory

ENTER E address[list] ; Enter new or modifies memory contents


beginning at specific Location.
FILL F [range] list ; Fill in arrange of memory
GO G [=address] [addresses] ; Execute a program in memory

HEX H value1 value2 ; Add and subtract two Hex values INPUT I port

LOAD L [address] [drive] [first sector] [number]

MOVE M range address

NAME N [path name] [arg list]

URCET Department of ECE


Microprocessors and Microcontrollers Lab

OUTPUT O port byte

PROCEED P [=address] [number]

QUIT Q

REGISTER R [register]

SEARCH S range list

TRACE T [=address][value]

UN ASSEMBLE U [range]

WRITE W [address] [drive] [first sector] [number]

ALLOCAT E expanded memory XA [#pages]

DE ALLOCAT E expanded memory XD [handle]

MA P expanded memory pages XM [L page] [P page] [handle]

DISPLAY expanded memory status XS

URCET Department of ECE


Microprocessors and Microcontrollers Lab

Experiment no: - 1.A

ADDITION OF N-BCD NUMBERS


USING 8086 TASM SOFTWARE

URCET Department of ECE


Microprocessors and Microcontrollers Lab

Flow chart:-

Start

Data is moved into the AX segment

Contents of AX register moved to DS register

Move 00H to AH

Move contents of N1 to AL register

Add contents of N2 with AL register

Add contents of N3 with AL register

Data C decimal adjustments off addition

Move the contents of AL to result

Move ACH into AH register

Program interrupt

Stop

URCET Department of ECE


Microprocessors and Microcontrollers Lab

EXP.NO:- 1.A DATE:-

PROGRAMS FOR 16 BIT ARITHMETIC OPERATIONS FOR 8086 (USING


VARIOUS ADDRESSING MODES).
ADDITION OF N-BCD NUMBERS USING 8086 TASM SOFTWARE
AIM: To write an assembly language program to perform addition of n-BCD
numbers using 8086 TASM software.
PORT USED: None
REGISTERS USED: AX, BL and DX
ALGORITHM:
Step 1: Start
Step 2: Initialize data segment
Step 3: Load CX register with count
Step 3: Initialize AX and DX register values to zero
Step 4: Load SI with offset list
Step 5: Copy the contents from memory location SI to AL
Step 6: Copy the contents of AL to BL
Step 7: Perform multiplication between the contents of AL and BL
Step 8: Perform addition between the contents of Ax and DX
Step 9: Increment SI
Step 10: Decrement CX and jump to step 5 if no zero
Start 11: Store the result to the data memory
Step 12: Stop.

URCET Department of ECE


Microprocessors and Microcontrollers Lab

Physical Address
Mnemonic
Segment Offset Label Hex Code Comments
Operands
Address Address

URCET Department of ECE


Microprocessors and Microcontrollers Lab

PROGRAM:
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
N1 DB 09H
N2 DB 07H
N3 DB 06H
RESULT DB ?
DATA ENDS
CODE SEGMENT
START:
MOV AX, DATA
MOV DS, AX
MOV AL, 00H
MOV AL, N1
ADD AL, N2
ADD AL, N3
DAA
MOV RESULT, AL
MOV AH, 4CH
INT 21H
CODE ENDS
END START

RESULT:

URCET Department of ECE


Microprocessors and Microcontrollers Lab

Experiment no: - 1.B

MULTIPLICATION AND DIVISION


OPERATIONS USING 8086

URCET Department of ECE


Microprocessors and Microcontrollers Lab

Flow chart: -

Start

Move data into AX Register

Copy AX contents into DS

Transfer NUM 1 into AX Register

Transfer NUM 2 into BX Register

Multiplication of BX contents

Transfer DX into the result

Move the DX into the [result +1]

Move NUM 1 Contents into AX

Division of BX is performed

Move AX Contents into [result +2]

Move DX into [result +3]

Program interrupts and terminated

END

URCET Department of ECE


Microprocessors and Microcontrollers Lab

EXP.NO:- 1.B DATE:-

MULTIPLICATION AND DIVISION OPERATIONS USING 8086 TASM


SOFTWARE
ABSTRACT: Assembly language program to perform multiplication and division
operations using 8086 TASM software.
APPARATUS: A Personal computer with TASM software.
ALGORITHM:
Step 1: Start
Step 2: Move the data into AX register.
Step 3: Copy the x contents into ds.
Step 4: Transfer Num1 to AX register.
Step 5: Transfer Num2 to DX register.
Step 6: Multiplication of BX contents.
Step 7: Transfer AX into BX contents.
Step 8: Move the DX into the “(result +1)”
Step 9: Move the Num1 contents into AX.
Step10: Division of BX is performed.
Step11: Move the AX contents into “(result + 3)”
Step12: Move DX into “(result + 3)”
Step13: Program interrupts & terminated.

URCET Department of ECE


Microprocessors and Microcontrollers Lab

Physical Address
Mnemonic
Segment Offset Label Hex Code Comments
Operands
Address Address

URCET Department of ECE


Microprocessors and Microcontrollers Lab

PROGRAM:
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
N1 DW 0004H
N2 DW 0002H
RESULT DW ?
DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV AX, N1
MOV BX, N2
MUL BX
MOV RESULT, AX
MOV [RESULT+1], BX
DIV BX
MOV [RESULT+2], AX
MOV [RESULT+3], BX
INT 21H
CODE ENDS
END START

RESULT:

URCET Department of ECE


Microprocessors and Microcontrollers Lab

Experiment no: - 2

PROGRAM FOR SORTING AN


ARRAY

URCET Department of ECE


Microprocessors and Microcontrollers Lab

FLOW CHART Start

Initialize data segment and Load SI


with offset list & Get a count with
CX register.

Copy the contents from CX to DX

Copy to contents from SI to AL register

Increment SI

Compare the contents of AL and SI

YES
If carry
equal to 0
NO
Oo
Exchange the contents of AL & SI

Decrement SI & move the contents of AL into SI

Increment SI

NO
Decrement
CX

If CX =0 YES
NO

Decrement
DX
YES
If DX=0
Stop

URCET Department of ECE


Microprocessors and Microcontrollers Lab

EXP.NO:-2 DATE:-
SORTING OF „N‟ NUMBERS
ABSTRACT: Assembly language program to do sorting of numbers in a given series
PORT USED: None
REGISTERS USED: CX, DX, AL, SI
ALGORITHM:
Step1: Start
Step2: Initialize data segment
Step3: Load CX register with count
Step4: Copy the contents from CX to DX
Step5: Load SI with offset list
Step6: Copy the contents from DX to CX
Step7: Move the contents from memory location SI to AL
Step8: Increment SI
Step9: Compare AL contents with [SI]
Step10: Jump to step15 if carry
Step11: Exchange the contents of AL with [SI]
Step12: Decrement SI
Step13: Move the contents from AL to memory location SI
Step14: Increment SI
Step15: Decrement CX and jump to step7 if no zero
Step16: Decrement DX and jump to step5 if no zero
Step17: Stop.

URCET Department of ECE


Microprocessors and Microcontrollers Lab

Physical Address
Mnemonic
Segment Offset Label Hex Code Comments
Operands
Address Address

URCET Department of ECE


Microprocessors and Microcontrollers Lab

PROGRAM:
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
LIST DB 56H, 12H, 72,32H
COUNT EQU 0003H
DATA ENDS
CODE SEGMENT
ORG 1000H
START: MOV AX, DATA
MOV DS, AX
MOV CX, COUNT
MOV DX, CX
AGAIN: MOV SI, OFFSET LIST
MOV CX, DX
BACK: MOV AL, [SI]
INC SI
CMP AL, [SI]
JC NEXT
XCHG [SI], AL
DEC SI
MOV [SI], AL
INC SI
NEXT: LOOP BACK
DEC DX
JNZ AGAIN
MOV AH, 4CH
INT 21H
CODE ENDS
END START
RESULT:

URCET Department of ECE


Microprocessors and Microcontrollers Lab

Experiment no: - 3
PROGRAMS FOR FACTORIAL OF
GIVEN N - NUMBERS

URCET Department of ECE


Microprocessors and Microcontrollers Lab

Flow chart: -

Start

Initialize data segment

Move data into AX Register

Load 000H into AX register

Load 000H into CX register

Copy the contents from NUM to DX

Multiply Contents of CX

Decrement of CX

Jump back if no array

Move contents from AX to fact

END

URCET Department of ECE


Microprocessors and Microcontrollers Lab

EXP.NO:-3 DATE:-
PROGRAMS FOR FACTORIAL OF GIVEN N - NUMBERS
ABSTRACT: Assembly language program to perform factorial of given n-numbers
using 8086 TASM software.
PORT USED: None
REGISTERS USED: AX, CX
ALGORITHM:
Step 1: Start
Step 2: Initialize data segment
Step 3: Initialize AX and CX register values to zero
Step 4: Increment the content of AX register
Step 5: Copy the given number into CL register
Step 6: Compare the contents of CL register with 01H
Step 7: Jump if equal to step 10
Step 8: Multiply the contents of AX register with CL register
Step 9: Decrement CX and jump to step 8 if no zero
Step 10: Store the result to the data memory
Start 11: Stop.

URCET Department of ECE


Microprocessors and Microcontrollers Lab

Physical Address
Mnemonic
Segment Offset Label Hex Code Comments
Operands
Address Address

URCET Department of ECE


Microprocessors and Microcontrollers Lab

PROGRAM:
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
NUM DB 08H
FACT DW ?
DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV AX, 0001H
MOV CX, 0000H
MOV CL, NUM
BACK: MUL CX
DEC CX
JNZ BACK
MOV AH, 4CH
INT 21H
CODE ENDS
END START
RESULT:

URCET Department of ECE


Microprocessors and Microcontrollers Lab

Experiment no: - 4

INTERFACE ANALOG – TO - DIGITAL


CONVERTER TO 8086

URCET Department of ECE


Microprocessors and Microcontrollers Lab

URCET Department of ECE


Microprocessors and Microcontrollers Lab

EXP.NO:-4 DATE:-
INTERFACE ANALOG – TO - DIGITAL CONVERTER TO 8086
AIM: - To write alp to interface ADC with 8086.
APPARATUS:
 Microprocessor power supply kit
 Microprocessor kit
 ADC module
 Key board
ALGORITHM:
 Copy address of control word register of 8255 ppi to one of general-purpose
register.
 Copy the control word of 91H to the accumulator.
 Load the control word into cwr of 8258 to make the port a, port c (or) input.
 Send out the number of 67H to port B to output enable to clear previous
output.
 Start the conversion by send the Hexadecimal number of 87H to port-b and
then reset by send 04H E7H Hexadecimal number to port b.
 Send continuously check the port c lower bit pc to check conversion is
ended.
PROCEDURE:
 Switch on the kit (reset the trainer ALSSDA86-STA)

 PRESS A trice to go to assembler mode ALS86 Assembler.

URCET Department of ECE


Microprocessors and Microcontrollers Lab

Physical Address
Mnemonic
Segment Offset Label Hex Code Comments
Operands
Address Address

URCET Department of ECE


Microprocessors and Microcontrollers Lab

PROGRAM:
MOV AX, 0000
MOV AL, 98H
MOV DX, OFFC6H
OUT DX, AL
MOV AL, 02
MOV DX, OFFC2
OUT DX, AL
MOV AL, 00
MOV DX, OFFC4
OUT DX, AL
MOV AL, 01
MOV DX, OFFC4
OUT DX, AL
WAIT: MOV DX, OFFC4
IN AL, DX
MOV CL, D1
RCL AL, CL
JNC WAIT
MOV DX, OFFCO
IN AL, DX
INT 03
RESULT:

URCET Department of ECE


Microprocessors and Microcontrollers Lab

Experiment no: - 5
INTERFACING DIGITAL - TO -
ANALOG CONVERTER TO 8086

URCET Department of ECE


Microprocessors and Microcontrollers Lab

URCET Department of ECE


Microprocessors and Microcontrollers Lab

Flow chart: -

Start

Initialize CWD as Pa & PB as output

Load ADC Value with data 00H

Display ACC data on LED display in 8056 trainer kit

Delay of few m.sec

All values with data 10H

Stop

URCET Department of ECE


Microprocessors and Microcontrollers Lab

EXP.NO:-5 DATE:-
INTERFACING DIGITAL - TO - ANALOG CONVERTER TO 8086
GENERATION OF WAVE FORMS:
AIM: program to generate the following wave forms:
 Triangular wave forms
 Saw tooth wave forms
 Square wave
 Sine wave
REGISTERS USED: general purpose registers: AL, DX, and CX
PORTS USED: out (port-B)
CONNECTION: J4 of ESA 86/88 to J1 DAC interface.
DESCRIPTIONS: As can be from the circuit only 17 lines from the connector are
used totally. The port A and port B of 8255 programmable peripheral interface are
used as output ports. The digital inputs to the DAC‟s are provided through the port
A and port B of 8255.the analog outputs of the DAC‟s are connected to the inverting
inputs of op-amps µA741 which acts as current to voltage converters. The out puts
from the op- amps are connected to points marked Xout and Yout at which the wave
forms are observed on a CRO. (port A is used to control Xout port B is used to control
Yout).the difference voltage for the DAC‟s is derived from an on-board voltage
regulator µA 723 .it generates a voltage of about 8V.the offset balancing of the op-
amps is done by making use of the two 10k pots provided. The output wave forms
are observed at Xout and Yout on an oscillator.
THEORY:
BASIC DAC TECHNIQUE:
Vo = K VFS (d1 .2-1 + d2 . 2-2 + . . . . . . . .+dn . 2-n )
Where d1 = MSB, d2 = LSB
VFS = Full scale reading / out put voltage
K --- Conversion factor is adjusted to „unity‟.
D/A converters consist of „n‟ bit binary word „D‟and is combined with a reference
voltage VR to give an analog output. The out put can be either voltage or current
Out put voltage Vo = K VFS (d1 .2-1 + d2. 2-2 + . . . . . . . . +dn. 2-n)

URCET Department of ECE


Microprocessors and Microcontrollers Lab

MSB weight = ½ VFS if d1 = 1 and all are zero‟s, K = 1.


LSB weight = VFS/2n if dn = 1 and all are zero‟s, K = 1
DUAL DAC INTERFACE:
 This program generates a square wave or a Triangular wave at points Xout or
Yout of interface. The waveforms may be observed on an oscilloscope.
 This program can be executed in STAND-ALONE MODE or SERIAL MODE of
operation.
 The program starts at memory location 3000H

URCET Department of ECE


Microprocessors and Microcontrollers Lab

PROGRAM: -

MOV DX, 0FFC6

MOV AL, 88

OUT DX, AL

MOV AL, 00

CALL 4013

MOV AL, OFF

CAL 4013

JMP 4006

MOV DX, OFFCO

OUT DX, AL

CALL 40FF

RET

MOV CX, OOFF

LOOP 4022

RET

RESULT: Interfacing of 8086 in 8086processor kit is verified.

URCET Department of ECE


Microprocessors and Microcontrollers Lab

Experiment no: - 6
INTERFACING STEPPER MOTOR TO
8086

URCET Department of ECE


Microprocessors and Microcontrollers Lab

URCET Department of ECE


Microprocessors and Microcontrollers Lab

FLOW CHART:

Start

Initialized the data R2 with #00H

Load the data R3 with #00H

Load the data R0 with #56H

Load the data R1 with #08H

Load the data with R0

Rotate right the register a data

Skip

Increment the R2

Decrement R1

END

URCET Department of ECE


Microprocessors and Microcontrollers Lab

EXP.NO:-6 DATE:-
INTERFACING STEPPER MOTOR TO 8086
ABSTRACT: C language program to do stepper motor interface
APPARATUS: A personal computer with keil software.
PROGRAM:
# include < reg.A5.h >
# include < studio.h >
Void delay (void);
8 bit motor_ pin _1 = p2^ 6;
8 bit motor_ pin _2 = p2^ 7;
Void main ()
{
Do
{
Motor _ pin _ 1= 1;
Motor _pin _ 2 = 0; // Rotates motor anti clock wise
Delay ();
Motor _ pin _ 1= 1;
Motor _ pin _ 2= 1; // stops motor
Delay ();
Motor _ pin _ 1 = 0;
Motor _ pin _ 2= 1; // rotates motor clock wise
Delay ();
Delay ();
}
While (1);
}
Void delay ()
{
Int I,j ;
For ( I>0; I= 500; I++)

URCET Department of ECE


Microprocessors and Microcontrollers Lab

{
For ( j= 0; j= 7000; j++)
{
}
}
}
PROCEDURE:
 Start computer & open keil software.
 Create new micro vision project & click on file -> new.
 Write the code & save it.
 Add source file to the source group.
 Build target and rebuild the target.
 Observe the results in peripherals in the peripheral window.

RESULT:

URCET Department of ECE


Microprocessors and Microcontrollers Lab

Experiment no: - 7
FINDING NUMBER OF 1‟S AND
NUMBER OF 0‟S IN A GIVEN 8 – BIT
NUMBER

URCET Department of ECE


Microprocessors and Microcontrollers Lab

FLOW CHART:

Start

Take numbers from register location 5000H

Move first number into R2 through A

Assign count value #06H to R0

Move second number into A

ADD A with R2 and Move result from a to R2

Increment data pointer and move non zero


number into A

ADD A with R0 and store results in B

Divide A values with B and store results in 60H

END

URCET Department of ECE


Microprocessors and Microcontrollers Lab

EXP.NO:-7 DATE:-

FINDING NUMBER OF 1‟S AND NUMBER OF 0‟S IN A GIVEN 8-BIT


NUMBER
ABSTRACT: Assembly language program to find number of 1‟s and 0‟s
PORTS USED: None
REGISTERS USED: R1, R2, R7, A, DPTR
APPARATUS: A personal computer with keil C software.
ALGORITHM:
Step 1: Start
Step 2: Initialize R1 and R2 registers with zeros
Step 3: Load the value 08H into R7 register
Step 4: Initializing base address location where given number is stored
Step 5: Coping value from memory location at which DPTR is pointing
Step 6: Rotate Accumulator Left Through Carry
Step 7: if CY=1 then Jump to Step 10
Step 8: Increment the content of R1 register
Step 9: Jump to Step11
Step 10: Increment the content of R2 register
Step 11: Decrement register R7 and jump if not Zero to step 6
Step 12: Moving the content of R1 to register A
Step 13: Increment the content of DPTR register
Step 14: Moving the content of register A to external RAM
Step 15: Moving the content of R2 to register A
Step 16: Increment the content of DPTR register
Step 17: Moving the content of register A to external RAM
Step 18: Repeat step18

URCET Department of ECE


Microprocessors and Microcontrollers Lab

Physical Address
Mnemonic
Segment Offset Label Hex Code Comments
Operands
Address Address

URCET Department of ECE


Microprocessors and Microcontrollers Lab

PROGRAM:
ORG 000H
JMP MAIN
ORG 40H
MAIN: MOV R0, #12
MOV R1, #08
MOV A, R0
LOOP: RLC A
JC LABEL 1
INC R2
SJMP LABEL 2
LABEL1: INC R3
LABEL2: DJNZ R1, LOOP
END
PROCEDURE:
 Start computer & open keil C software.
 Create new micro vision project & click on file -> new.
 Write the code & save it.
 Add source file to the source group.
 Build target and rebuild the target.
 Observe the results in peripherals in the peripheral window.
RESULT:

URCET Department of ECE


Microprocessors and Microcontrollers Lab

Experiment no: - 8
AVERAGE OF N - NUMBERS

URCET Department of ECE


Microprocessors and Microcontrollers Lab

EXP.NO:-8 DATE:-
FIND AVERAGE OF N - NUMBERS
AIM: To write assembly language program to find average of N numbers
APPARATUS: A Personal computer with keil c software.
ALOGRITHM:
1. Take two numbers from 500h location using DPTR register & send first numbers
into R0 register through a register.
2. Assign count value to R1 register.
3. Move and count value into B register through A register.
4. Move second number in to A register.
5. This operation is continued till count value is equal to zero offer that R0 value is
moved to n register.
6. Divide the A register value with B the result is stored in 600h location.
PROGRAM:
MOV R0, #50H
MOV A, @R0
MOV R2, A
MOV R1, #60H
INC R0
BACK: MOV A, @R0
ADD A, R2
MOV R2, A
INC R0
DJNZ R1, BACK
MOV B, #06H
DIV AB
MOV 60H, A
MOV 60H, B
END

URCET Department of ECE


Microprocessors and Microcontrollers Lab

PROCEDURE:
 Start computer & open keil c software.
 Create new micro vision project & click on file -> new.
 Write the code & save it.
 Add source file to the source group.
 Build target and rebuild the target.
 Observe the results in peripherals in the peripheral window.
RESULT:

URCET Department of ECE


Microprocessors and Microcontrollers Lab

Experiment no: - 9

PROGRAM AND VERIFY TIMER/


COUNTER IN 8051

URCET Department of ECE


Microprocessors and Microcontrollers Lab

EXP.NO:-9 DATE:-
PROGRAM AND VERIFY TIMER/COUNTER IN 8051
AIM: To verify the operation of timer/counter
APPARATUS REQUIRED: A personal computer with Keil c Assembler
THEORY:
The 8051 has two timers/counters. They can be used either as timers to generate a
time delay or as counters to count events happening outside the microcontroller.
PROGRAMMING 8051 TIMERS:
The 8051 has two timers: Timer 0 and Timer 1. They can be used either as timers or
as event counters. In this section we first discuss the timers‟ registers and then
show how to program the timers to generate time delays.
BASIC REGISTERS OF THE TIMER:
Both Timer 0 and Timer 1 are 16 bits wide. Since the 8051 has an 8-bit
architecture, each 16-bit timer is accessed as two separate registers of low byte and
high byte. Each timer is discussed separately.
TIMER 0 REGISTERS:
The 16-bit register of Timer 0 is accessed as low byte and high byte. The low byte
register is called TLO (Timer 0 low byte) and the high byte register is referred to as
THO (Timer 0 high byte). These registers can be accessed like any other register,
such as A, B, RO, Rl, R2, etc. For example, the instruction “MOV TLO , #4FH”
moves the value 4FH into TLO, the low byte of Timer 0. These registers can also be
read like any other register. For example, “MOV R5 , THO” saves THO (high byte of
Timer 0) in R5.

Timer 0 Registers
Timer 1 registers

URCET Department of ECE


Microprocessors and Microcontrollers Lab

TIMER 1 REGISTERS:
Timer I is also 16 bits, and its 16-bit register is split into two bytes, referred to as
TLl (Timer I low byte) and TH1 (Timer 1 high byte). These registers are accessible in
the same way as the registers of Timer 0.
TMOD (TIMER MODE) REGISTER:
Both timers 0 and 1 use the same register, called TMOD, to set the various timer
operation modes. TMOD is an 8-bit register in which the lower 4 bits are set aside
for Timer 0 and the upper 4 bits for Timer 1. In each case, the lower 2 bits are used
to set the timer mode and the upper 2 bits to specify the operation. These options
are discussed next.

URCET Department of ECE


Microprocessors and Microcontrollers Lab

PROGRAM:
MOV TMOD, #01;
HERE: MOV TLO, #0F2H;
MOV THO, #0FFH;
CPL P1.5;
ACALL DELAY;
SJMP HERE;
DELAY: SET B TRO;
AGAIN: JNBTFO AGAIN;
CLR TRO;
CLR TFO;
RET
END
OUTPUT:

RESULT: Verified the timer/counter operation of 8051.

URCET Department of ECE


Microprocessors and Microcontrollers Lab

Experiment no: - 10

INTERFACING OF TRAFFIC LIGHT


CONTROLLER TO 8051

URCET Department of ECE


Microprocessors and Microcontrollers Lab

URCET Department of ECE


Microprocessors and Microcontrollers Lab

EXP.NO:10 DATE:-
TRAFFIC LIGHTS INTERFACE
1.0 INTRODUCTION
Electro Systems Associates Private Limited (ESA) manufactures trainers for
most of the popular microcomputers viz 8085, Z-80, 6502, 8086/8088 and 68000.
ESA offers a variety of modules which can be interfaced to these trainers. These
modules can be effectively used for teaching/training in the laboratories. The
present manual describes one such interface module traffic lights interface. The
interface simulates the control and operation of traffic lights at a junction of four
roads. The interface provides a set of 6 LED indicators at each of the four corners.
Each of these LEDs can be controlled by a port line. Thus the interface allows the
user to simulate a variety of traffic situations using appropriate software routines.
The sample programs provided in section 4 of this manual simulate some
interesting traffic movement sequences. This interface can be connected to any of
ESA trainers viz., MPS 85-3, ESA 85-2, ESA 80, ESA 65, ESA 68K, ESA 86/88-2,
ESA 31, ESA 51, ESA 86/88-3 & ESA 51E.
2.0 DESCRIPTION OF THE CIRCUIT
Please refer to the schematic diagram of this interface presented at the end
of this manual. As already mentioned, the interface provides a set of six LEDs at
each of the four corners of a four road junction. The organization of these LEDs is
identical at each of the four corners. Hence, for simplicity, the organization is
described below with reference to the LEDs at SOUTH-WEST corner only. The LEDs
at SOUTH-WEST corner are organized as follows:
The LEDs at SOUTH-WEST corner are organized as follows:
RED: Referred to as SOUTH RED henceforth
A: Referred to as SOUTH AMBER henceforth
L: Referred to as SOUTH LEFT henceforth
S: Referred to as SOUTH STRAIGHT henceforth
R: Referred to as SOUTH RIGHT henceforth
DL: Referred to as SOUTH PEDESTRIAN henceforth (Please note that DL
refers to a set of two LEDs, one on either side of the road).

URCET Department of ECE


Microprocessors and Microcontrollers Lab

Of these , the first five LEDs will be ON or OFF depending on the state of the
corresponding port line (LED is ON if the port line is Logic HIGH and LED is OFF if
the port line is Logic LOW). The last one marked as DL is a set of two dual - color
LEDs and they both will be either RED or GREEN depending on the state of the
corresponding port line (RED if the port line is Logic HIGH and GREEN if the port
line is Logic LOW)
There are four such sets of LEDs and these are controlled by 24 port lines.
Each port line is inverted and buffered using 7406 (open collector inverter buffers)
and is used to control an LED. Dual-colour LEDs are controlled by a port line and
its complement.
The 24 LEDs and their corresponding port lines are summarized below
LED PORT LINE
SOUTH EAST NORTH WEST
RED PA3 PA7 PB3 PB7
AMBER PA6 PA2 PB2 PB6
LEFT PA4 PA0 PB0 PB4
STRAIGHT PC2 PC3 PC1 PC0
RIGHT PA5 PA1 PB5 PB1
PEDISTRIAN PC7 PC6 PC4 PC5
User can assign any meaningful interpretation to these LEDs and then develop
software accordingly. Usually, the interpretation would be as follows:
Vehicles coming from one direction are controlled by the LEDs at the opposite
corner.
For example,
Vehicles coming from NORTH are controlled by the set of LEDs at the SOUTH WEST
corner, as shown below:
Vehicles coming from NORTH can
go left (i.e to EAST) if SOUTH LEFT LED is ON
go right (i.e to WEST) if SOUTH RIGHT LED is ON
go straight (i.e to SOUTH) if SOUTH STRAIGHT LED is ON
Further, the above movements are followed only if SOUTH RED LED is OFF. If
SOUTH RED LED is ON , no movement is allowed for vehicles from north.

URCET Department of ECE


Microprocessors and Microcontrollers Lab

Pedestrian crossing on SOUTH is allowed when SOUTH PEDESTRIAN is green and


disallowed when it is red. It is obvious that, logically some combinations can not be
allowed. For example, SOUTH RED = OFF, SOUTH STRAIGHT = ON and SOUTH
PEDESTRIAN = GREEN is not allowed (vehicles are allowed to go from NORTH to
SOUTH and pedestrians are allowed to cross on SOUTH). SOUTH AMBER can be
ON to indicate that SOUTH RED is about to change its status from OFF to ON.
The movement of vehicles and pedestrians on the roads can be controlled in a
similar way.
As already noted, user can assign a different interpretation if desired. However, the
sample programs presented in the next section are based on the above simple
interpretation
PROGRAM
The sequence shown below is simulated:
(Movements other than those listed are not allowed in a given situation)
 Vehicles from SOUTH can go NORTH, EAST and WEST
Vehicles from WEST can go NORTH
Vehicles from NORTH can go SOUTH
Pedestrians can cross on EAST.
 Vehicles from EAST can go WEST and SOUTH
Vehicles from WEST can go EAST
Vehicles from SOUTH can go WEST
Pedestrians can cross on NORTH
 Vehicles from EAST can go SOUTH
Vehicles from NORTH can go SOUTH and EAST
Vehicles from SOUTH can go NORTH
Pedestrians can cross on WEST
 Vehicles from EAST can go WEST
Vehicles from WEST can go EAST and NORTH
Vehicles from NORTH can go EAST
Pedestrians can cross on SOUTH

URCET Department of ECE


Microprocessors and Microcontrollers Lab

 No vehicle movement
Pedestrians can cross on all four roads
The system moves from one state to another state after fixed time delay. The state
transition is indicated by turning ON all the AMBER LEDs and all pedestrian red
LEDs for a fixed duration. The sequence of the above states are repeated again and
again. Hence you must press the RESET key to allow the monitor program to regain
control for this program.

URCET Department of ECE


Microprocessors and Microcontrollers Lab

PROGRAM:
The traffic system moves from one state to next state after a fixed delay.
# Include <reg52.h>
S BIT RE = P0ˆ0;
S BIT YE = P0ˆ1;
S BIT GE = P0ˆ2;
S BIT RW = P0ˆ3;
S BIT YW = P0ˆ4;
S BIT GW = P0ˆ5;
S BIT RS = P0ˆ6;
S BIT YS = P0ˆ7;
S BIT GS = P2ˆ0;
S BIT RN = P2ˆ1;
S BIT YN = P2ˆ2;
S BIT GN = P2ˆ3;
Void Delay (Void)
{
UNSIGNED INT I, J;
FOR (I=0; I<200; I++)
FOR (J=0; I<500; J++);
}
Void Super Delay ( )
{
UNSIGNED INT I;
FOR (I=0; I<25; I++)
DELAY ( );
}
Void Main ( )
{
P3 = 0;
WHILE (1)

URCET Department of ECE


Microprocessors and Microcontrollers Lab

}
RE = 0;
GE = 1;
YE = 0;
GW = 0;
YW = 0;
RW = 1;
RS = 1;
GS = 0;
YS = 0;
RN = 1;
YN = 0;
GN = 0;
Super Delay ( );
YE = 1;
GE = 0;
DELAY ( );
RE = 1;
YE = 0;
GE = 0;
RW = 0;
YW = 0;
GW = 1;
RS = 1;
YS = 0;
GS = 0;
RN = 1;
YN = 0;
GN = 0;
Super Delay ( );
YW = 1;

URCET Department of ECE


Microprocessors and Microcontrollers Lab

GW = 0;
Delay ( );
RE = 1;
YE = 1;
GE = 0;
RW = 1;
YW = 0;
GW = 0;
RS = 0;
YS = 0;
GS = 1;
RN = 1;
YN = 0;
GN = 0;
Super Delay ( );
YS = 1;
GS = 0;
Delay ( );
RE = 1;
GE = 0;
YE = 0;
RW = 1;
YW = 0;
GW = 0;
RS = 1;
YS = 0;
GS = 0;
RN = 0;
YN = 0;
GN = 1;
Super Delay ( );

URCET Department of ECE


Microprocessors and Microcontrollers Lab

YN = 1;
GN = 0;
Delay ( );
}
}

RESULT:

URCET Department of ECE


Microprocessors and Microcontrollers Lab

Experiment no: - 11

UART OPERATION IN 8051

URCET Department of ECE


Microprocessors and Microcontrollers Lab

URCET Department of ECE


Microprocessors and Microcontrollers Lab

EXP.NO:-11 DATE:-
UART OPERATION IN 8051
AIM: To verify the operation of UART operation
APPARATUS REQUIRED: Keil C Assembler
THEORY:
SERIAL COMMUNICATION:
The fastest way of transmitting data, within a microcomputer is parallel
data transfer. For transferring data over long distances, however, parallel data
transmission requires too many wires. For long distance transmission, data is
usually converted from parallel form to serial form so that it can be sent on a
single wire or pair of wires. Serial data received from a distant source is
converted to parallel form and it can be easily transferred on the microcomputer
buses. The types of communication systems are,
1. Simplex
2. Half-duplex
3. Full-duplex

SCON (Serial Port Control Register)


SMO – Serial port mode 0 shift register
SM1 – serial port mode 1 8 bit UAR + variable
SM2 – enable multiprocessor communication in mode 2/3
REN – set/ clear by software to enable/disable reception
TB8 – the 9th bit that will be transmitted in mode 2/3 set/clear by software.
RB8 – in mode 2/3 it is the 9th bit that was received in mode 1 if SM2 =0, RB8 is
the stop bit that was received in mode it is not used.
TI – transmit interrupt flag set by hardware at the end of 8 bit time in mode 0 at the
beginning of the stop bit in the other mode it must be cleared by software

URCET Department of ECE


Microprocessors and Microcontrollers Lab

RI – receive interrupt flag set by hardware and must be cleared by software.


PROGRAM:
#include<reg51.h>
Unsigned int I;
Char a[5]={„d‟,‟e‟,‟c‟,‟e‟,‟b‟};
Void main ( )
{
SCON=0X50;
TMOD=0X20;
TH1=0XFA;
TR1=1;
for(i=0;i<5;i++)
{
SBUF=a[i];
While(TI==0)
TI=0;
}
}
PROCEDURE:
 Start computer & open keil software.
 Create new micro vision project & click on file -> new.
 Write the code & save it.
 Add source file to the source group.
 Build target and rebuild the target.
 Observe the results in peripherals in the peripheral window.
RESULT: UART operation is verified.

URCET Department of ECE


Microprocessors and Microcontrollers Lab

Experiment no: -12


INTERFACING LCD TO 8051

URCET Department of ECE


Microprocessors and Microcontrollers Lab

URCET Department of ECE


Microprocessors and Microcontrollers Lab

EXP.NO:-12 DATE:-
INTERFACING OF LED TO 8051
AIM: TO write a c program to interface LCD with 8051.
APPARATUS: A personal computer with keil software.
PROGRAM:
#include< reg52.h >
#include < lcd.h >
S bit rs =p1^2;
S bit en =p1^3;
S bit d4 =p1^4;
S bit d5 =p1^5;
S bit d6 =p1^6;
S bit d7 =p1^7;
Void delay control
{
Int j;
Int i;
For (i=0; i<a; i++)
{
For (j=0; j<100; j++)
{
}
}
Void main ( )
{
Int I;
Lcd4_init ( );
While (1)
{
Lcd4_set_cursor (1, 1);
Lcd4_write_string (“electronics & communications”);

URCET Department of ECE


Microprocessors and Microcontrollers Lab

For (i=0; i<2; i++)


{
Delay (1000);
Lcd4_shift_left ( );
}
For (i=0; i<15; i++)
{
Delay (1000);
Lcd4_shift_right ( );
}
Lcd4_shift_right ( );
}
Lcd4_clear ();
Lcd4_set_cursor (2, 1);
Lcd4_write_char („e‟);
Lcd4_write_char („c‟);
Lcd4_write_char („e‟);
Delay (3000);
}
}
PROCEDURE:
 Start computer & open keil C software.
 Create new micro vision project & click on file -> new.
 Write the code & save it.
 Add source file to the source group.
 Build target and rebuild the target.
 Observe the results in peripherals in the peripheral window.
RESULT:

URCET Department of ECE


Microprocessors and Microcontrollers Lab

Experiment no: - 13
WRITE AN ASSEMBLY LANGUAGE
PROGRAM TO MULTIPLY OF TWO
16 – BIT BINARY NUMBERS

URCET Department of ECE


Microprocessors and Microcontrollers Lab

EXP.NO:-13 DATE:-

MULTIBYTE MULTIPLICATION
AIM: To perform multiplication of two words of signed and unsigned numbers and
observe the result after executions.
ALGORITHM:
1. Get 1st operand from memory that is pointed by source index [SI] register and
store it in AX register.
2. Get 2nd operand from memory and store it in BX register.
3. Multiply contents of AX and BX registers and the result will be in AX & DX
registers.
4. Store the result in memory location pointed by DI.
PROGRAM:
MOV AX,0000
MOV DX,0000
MOV SI,2100
MOV DI,2200
MOV AX,[SI]
INC SI
INC SI
MOV BX, [SI]
MUL BX
MOV [DI], AX
INC DI
INC DI
MOV [DI], DX
INT 03
PROCEDURE:
 Start computer & open keil C software.
 Create new micro vision project & click on file -> new.
 Write the code & save it.

URCET Department of ECE


Microprocessors and Microcontrollers Lab

 Add source file to the source group.


 Build target and rebuild the target.
 Observe the results in peripherals in the peripheral window.
RESULT:

URCET Department of ECE


Microprocessors and Microcontrollers Lab

Experiment no: - 14
WRITE AN ASSEMBLY LANGUAGE PROGRAM
TO FIND THE SUM OF FIRST 10 INTEGERS
NUMBERS

URCET Department of ECE


Microprocessors and Microcontrollers Lab

EXP.NO:- 14 DATE:-
FIND THE SUM OF FIRST 10 INTEGERS NUMBERS
AIM: To write an assembly program to find the sum of first 10 integers numbers.
APPARATUS: A Personal computer with keil C software.
PROCEDURE:
 Start computer & open keil C software.
 Create new micro vision project & click on file -> new.
 Write the code & save it.
 Add source file to the source group.
 Build target and rebuild the target.
 Observe the results in peripherals in the peripheral window.
PROGRAM:
Area addition, CODE, READONLY
ENTRY
START
MOV r0, #10
MOV r1, r0
ADDIT
SUBS r1, r1, #1
CMP r1, #0
BEQ STOP
ADD r3, r0, r1
MOV r0, r3
BNE ADDIT
STOP
NOP
NOP
NOP
END
RESULT:

URCET Department of ECE


Microprocessors and Microcontrollers Lab

URCET Department of ECE


Microprocessors and Microcontrollers Lab

Experiment no: - 15
WRITE A PROGRAM TO TOGGLE
LED EVERY SECOND USING TIMER
INTERRUPT

URCET Department of ECE


Microprocessors and Microcontrollers Lab

EXP.NO:-15 DATE:-
LED INTERFACING
AIM: To write a program to interface led with 8051.
APPARATUS: A personal computer with keil C software.
PROGRAM:

#include<reg52.h>
8 bit led_pin =P1^1;
8 bit switch pin=P1^0;
Void delay (int);
Void main (void);
{
Switch_pin=1;
Led_pin=1;
While (1)
{
If (switch_pin==0)
{
Led_pin=0;
Delay (100)
Led_pin=1;
}
}
}
Void delay (int t)
{
Int j;
Int I;
For (i=0;i<k;i++)
{
For (j=0;j<100;j++)

URCET Department of ECE


Microprocessors and Microcontrollers Lab

{
}
}
}
PROCEDURE:
 Start computer & open keil C software.
 Create new micro vision project & click on file -> new.
 Write the code & save it.
 Add source file to the source group.
 Build target and rebuild the target.
 Observe the results in peripherals in the peripheral window.
RESULT:

URCET Department of ECE

You might also like