EE8681 MPMC Lab

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 56

EE8681  

MICROPROCESSORS AND MICROCONTROLLERS LABORATORY

OBJECTIVES:

To provide training on programming of microprocessors and microcontrollers and understand


the interface requirements.

SYLLABUS:

1. Simple arithmetic operations: addition / subtraction / multiplication / division.

2. Programming with control instructions:


(i) Ascending / Descending order, Maximum / Minimum of numbers
(ii) Programs using Rotate instructions
(iii) Hex / ASCII / BCD code conversions.
3. Interface Experiments: with 8085
(i) A/D Interfacing. & D/A Interfacing.
4. Traffic light controller.
5. I/O Port / Serial communication
6. Programming Practices with Simulators/Emulators/open source
7. Read a key ,interface display
8. Demonstration of basic instructions with 8051 Micro controller execution, including:
(i) Conditional jumps, looping
(ii) Calling subroutines.
9.. Programming I/O Port 8051
(i) study on interface with A/D & D/A
(ii) study on interface with DC & AC motor .
10. Mini project development with processors.

1
S.NO DATE LIST OF EXPERIMENTS PAGE NO

1 1(a)Simple arithmetic operations: addition


1(b)1subtraction
1(c)multiplication
1(d)division
2 (i)2(a) Ascending order
2(b) Descending order
2( c) Largest of a given numbers
2(d) Smallest of a given numbers
(ii) Programs using Rotate instructions
(iii) (a)Code Conversion: ASCII to Hexadecimal
(b)Code Conversion: Hexadecimal to ASCII
(c)Code Conversion: Hexadecimal to Binary
(d)Code Conversion: Hexadecimal to BCD
3 3(a) Interfacing: ADC with 8085
3(b)Interfacing: DAC with 8085
4 Traffic light controller.
5 5. I/O Port / Serial communication
6 6. Programming Practices with
Simulators/Emulators/open source
7 7. Read a key ,interface display
8 Demonstration of basic instructions with 8051 Micro
controller execution, including:
8(a) Sum of elements in an array
8(b)Sum using Stack

8( c) Sum using call option


9 9. Programming I/O Port 8051
(a) study on interface with A/D & D/A
(b) study on interface with DC & AC motor .
10 Mini project development with processors.

2
Ex. No: 1 SIMPLE ARITHMETIC OPERATION

AIM:
To write an assembly language program to add, subtract, multiply and divide the given
data stored at two consecutive locations using 8085 microprocessor.
8 – BIT ADDITION
FLOW CHART:

START

GET FIRST OPERAND TO B

GET SECOND OPERAND TO B

A = A+B

STORE RESULT

STOP

ALGORITHM:
 Initialize the pointer to the memory for data and result.
 Load the data into A B.
 Add the two data of A and B registers.
 Store the result into Memory from A registers.

3
INPUT:

8500 13H 8501 14H

OUTPUT:

8502 27H.

PROGRAM:

ADDRESS OPCODE MNEMONICS COMMENTS

8100 3A 00 85 LDA 8500 Load 8100 address into

Accumulator

8103 47 MOV B,A Move Accumulator value

into B register

8104 3A 01 85 LDA 8501 Load 8101 address into

Accumulator

8107 80 ADD B Add B register with

Accumulator

8108 32 02 85 STA 8502 Store the content of

Accumulator into

810B CF RST 1 Break point( ACC VALUE

DISPLAY)

4
8 -BIT SUBTRACTION
FLOW CHART:

START

GET FIRST OPERAND TO A

SUBTRACT SECOND OPERAND FROM MEMORY

STORE RESULT MEMORY

STOP

ALGORITHM:
 Initialize the pointer to the memory for data and result.
 Load the data into A B.
 Subtract the two data of A and B registers.
 Store the result into Memory from A registers.

5
INPUT:

8500 45H 8501 13H

OUTPUT:

8502 32H.

PROGRAM:

ADDRESS OPCODE MNEMONICS COMMENTS

8100 21 00 85 LXI H,8500 Load 8100 address into

Accumulator

8103 7E MOV A,M Move Accumulator value into

A register

8104 23 INX H Increment H register value

8105 96 SUB M Subtract acc value

8106 23 INX H Increment H register value

8107 77 MOV M,A Second value move acc

8108 CF RST 1 Break point( ACC VALUE

DISPLAY)

6
8 BIT MULTIPLICATION

FLOWCHART: START

Transfer the multiplier and multiplier to 2 separate register

NO Is the YES
multiplier
is zero?

Transfer zero in result


register

Initialize the content of a temporary register to zero

Add the multiplicand with the temporary register and


store it in temporary register

Decrement the multiplier

NO
Is the multiplier
is zero?

YES

Transfer the temporary register value to result register

STOP

7
ALGORITHM:
 Initialize the pointer to the memory for data and result.
 Load the data into A and B register

Multiplication the two data of A and B registers.
 Store the result into Memory from A registers.

INPUT:

8500 06H 8501 02H

OUTPUT:

8502 0CH.

PROGRAM:

ADDRESS OPCODE MNEMONICS COMMENTS

8100 3A 00 85 LDA 8500 Load 8100 address into


Accumulator

8103 47 MOV B,A Move Accumulator value into B


register

8104 3A 01 85 LDA 8501 Load 8101 address into


Accumulator

8107 4F MOV C,A Move Accumulator value into C


register

8108 FE 00 CPI 00 If X2=0 then result is 0 and exit

810A CA 16 81 JZ LOOP If carry is zero then jump into


8116

810D AF XRA A Clear ACC and flags add the B as


many as the C

810E 80 LOOP1: ADD B Add B register with Accumulator

810F OD DCR C Decrement C register

8110 CA 16 81 JZ LOOP Store the result and exit

8113 C3 0E 81 JMP LOOP1 Multiply start address = 810E

8116 32 02 85 LOOP: STA Store the content of Accumulator


8502 into 8502

8119 CF RST 1 Break point( ACC VALUE


DISPLAY)
8 BIT DIVISION

FLOW CHART:

START

Transfer the dividend and divisor to separate register r1 and r2

Initialize the temporary register to ‘zero’

YES

If dividend is <
divisor

NO Store the dividend in


reminder register

Subtract (dividend – divisor)

Store the result in dividend register Store the temporary register

2 to quotient register

Increment temporary register 1


STOP

YE
NO S

If dividend is <
divisor

ALGORITHM:

 Initialize the pointer to the memory for data and result.


 Load the data into A and B register

Divided the two data of A and B registers.
 Store the result into Memory from A registers.
INPUT:

8500 0AH 8501 02H

OUTPUT:
8502 05H (Quotient). 850300H (Reminder).
PROGRAM:

ADDRESS OPCODE MNEMONICS COMMENTS

Load 8101 value into


8100 3A 01 85 LDA 8501 Accumulator

Move Accumulator value into


8103 47 MOV B,A Register B

Load 8100 value into


8104 3A 00 85 LDA 8500 Accumulator

8107 0E 00 MVI C,00 Count for quotient

8109 B8 LOOP: CMP B Check for A < B

810A DA 12 81 JC LOOP1 If A < B then go to store

Subtract the Register B with


810D 90 SUB B Accumulator

810E 0C INR C Increment the C register

810F C3 09 81 JMP LOOP Jump into 8109

LOOP1: STA Store Reminder value into


8112 32 03 85 8503 8103

Move Register C value into


8115 79 MOV A,C Accumulator

Store the Quotient value into


8116 32 02 85 STA 8502 8102

8119 CF RST 1 Break point

RESULT:
Thus the addition, subtraction, multiplication and division of two numbers was
performed using the 8085 microprocessor.
Ex. No: 2 SORTING OF AN ARRAY

AIM:
To write an assembly language program to arrange an array of data in ascending and
descending order and to find the smallest and largest data among the array.
A. ASCENDING ORDER
FLOW CHART:
START

Load the counter with the number of elements in the array

Move the first data into the temporary register

NO
If the temp.reg

data < next data

Swap the next data and the data


YE
S

Set the swap flag

Is the count is
zero?

NO
START YES

Decrement the swap flag

Is the swap flag is


START
zero?
YES

NO

STOP
ALGORITHM:
 Initialize the pointer to the memory for data and result.
 Load the data into M and C register
 Store the result into Memory from A registers.
INPUT:

8500 05H (COUNT VALUE)

8501 08H, 04H, 03H, 07H, 01H

OUTPUT:

8500 05H (COUNT VALUE)

8501 01H, 03H, 04H, 07H, 08H

PROGRAM:

ADDRESS OPCODE MNEMONICS COMMENTS

START: MVI
8100 06 00 B,00 Initialize 00 into B register

8102 21 00 85 LXI H,8500 Load 8100 value into H register

Load the count value into the C


8105 4E MOV C,M register

8106 0D DCR C If C=1 no process

8107 CA 20 81 JZ LOOP2 Jump into 8120(program end)

810A 23 INX H Increment the H register by one

LOOP: MOV Get the byte pointed by m


810B 7E A,M pointer

810C 23 INX H Move the m pointer to next byte

810D BE CMP M Compare with ACC

810E DA 18 81 JC LOOP1 If Acc < m then no swapping

8111 56 MOV D,M Else swap the bytes

Load Accumulator value into


8112 77 MOV M,A M

8113 2B DCX H Decrement H value by one


Load D register value into
8114 72 MOV M,D pointer

Now move m pointer to the


8115 23 INX H next byte

8116 06 01 MVI B,01 Set the swap flag

8118 0D LOOP1: DCR C Decrement the count

If C is not equal 0 then jump


8119 C2 0B 81 JNZ LOOP 810B

811C 5 DCR B After C=0 check the swap flag.

811D CA 00 81 JZ START Jump zero again call start

8120 76 LOOP2: HLT End


B. DESCENDING ORDER

FLOW CHART:

START

Load the counter with the number of elements in the array

Move the first data into the temporary register

NO If the temp.reg

data > next data

Swap the next data and the data

YES

Set the swap flag

Is the count is
START
zero?
NO

YES

Decrement the swap flag

YES
Is the swap flag is
START
zero?

NO

STOP
ALGORITHM:
 Initialize the pointer to the memory for data and result.
 Load the data into M and C register
 Store the result into Memory from A registers.
INPUT:

8500 05H (COUNT VALUE)

8501 01H, 03H, 04H, 07H, 08H

OUTPUT:

8500 05H (COUNT VALUE)

8501 08H, 07H, 04H, 03H, 01H

PROGRAM:

ADDRESS OPCODE MNEMONICS COMMENTS

START: MVI
8100 06 00 B,00 Initialize 00 into B register

8102 21 00 85 LXI H,8500 Load 8100 value into H register

Load the count value into the C


8105 4E MOV C,M register

8106 0D DCR C If C=1 no process

8107 CA 20 81 JZ LOOP2 Jump into 8120(program end)

810A 23 INX H Increment the H register by one

LOOP: MOV Get the byte pointed by m


810B 7E A,M pointer

810C 23 INX H Move the m pointer to next byte

810D BE CMP M Compare with ACC

810E D2 18 81 JNC LOOP1 If Acc > m then no swapping

8111 56 MOV D,M Else swap the bytes

Load Accumulator value into


8112 77 MOV M,A M

8113 2B DCX H Decrement H value by one

Load D register value into


8114 72 MOV M,D pointer

Now move m pointer to the


8115 23 INX H next byte

8116 06 01 MVI B,01 Set the swap flag

8118 0D LOOP1: DCR C Decrement the count

If C is not equal 0 then jump


8119 C2 0B 81 JNZ LOOP 810B

811C 05 DCR B After C=0 check the swap flag.

811D CA 00 81 JZ START Jump zero again call start

8120 76 LOOP2: HLT End

C. LARGEST ELEMENT IN AN ARRAY

ALGORITHM:
1. Place all the elements of an array in the consecutive memory locations.
2. Fetch the first element from the memory location and load it in the accumulator.
3. Initialize a counter (register) with the total number of elements in an array.
4. Decrement the counter by 1.
5. Increment the memory pointer to point to the next element.
6. Compare the accumulator content with the memory content (next
element).
7. If the accumulator content is smaller, then move the memory content
(largest element) to the accumulator. Else continue.
8. Decrement the counter by 1.
9. Repeat steps 5 to 8 until the counter reaches zero
10. Store the result (accumulator content) in the specified memory location.
D.SMALLEST ELEMENT IN AN ARRAY

ALGORITHM:
1. Place all the elements of an array in the consecutive memory locations.
2. Fetch the first element from the memory location and load it in the accumulator.
3. Initialize a counter (register) with the total number of elements in an array.
4. Decrement the counter by 1.
5. Increment the memory pointer to point to the next element.
6. Compare the accumulator content with the memory content (next
element).
7. If the accumulator content is smaller, then move the memory content
(largest element) to the accumulator. Else continue.
8. Decrement the counter by 1.
9. Repeat steps 5 to 8 until the counter reaches zero
10. Store the result (accumulator content) in the specified memory location.
STOP
RESULT:
Thus the sorting operations of arranging an array in ascending, descending order and
the largest and smallest element were found using the 8085 microprocessor.
Ex. No: 3 CODE CONVERSIONS

A. BCD TO BINARY (HEX) CONVERSATION

FLOW CHART:

START

Get the number from 8500 address

Mask upper nibble & store the number as A

Get the number again from Accumulator

Mask lower nibble, exchange nibble positions of


result and store it as B

Multiply B with 10 until B = 0 & decrement B by one

NO
Is multiplication
complete?

YES
Add B value with Accumulator

Store the result into address 8510

STOP
ALGORITHM:
 Initialize the pointer to the memory for data and result.
 BCD to Binary values the two data of A and B registers.
 Store the result into Memory from A registers.
INPUT:

8500 15H ( 0 to 09 value)

OUTPUT:

8510 0FH

PROGRAM:

ADDRESS OPCODE MNEMONICS COMMENTS

8100 Load8100valueinto
3A 00 85 LDA 8500 Accumulator

8103 Move Accumulator value into B


47 MOV B,A register

8104 Mask upper nibbles & store it


E6 0F ANI 0F into Accumulator

8106 Move Accumulator value into C


4F MOV C,A register

8107 Load Register B value into


78 MOV A,B Accumulator

8108 Mask lower nibbles & store it


E6 F0 LOOP: ANI F0 into Accumulator

810A Convert MSB into unpacked B


0F RRC register

810B 0F RRC
810C 0F RRC

810D 0F RRC

Move Accumulator value into B


810E 47 MOV B,A register

The content of ACC X-OR with


810F AF XRA A the content of register

Store multiplier 10 value into D


8110 16 0A MVI D,0A register

Add the 10 value with


8112 82 ADD D Accumulator

8113 05 DCR B Decrement the B register by one

If multiplication is not complete


8114 C2 08 81 JNZ LOOP jump into 8108

8117 81 ADD C Else Add with C register

Store Accumulator value into


8118 32 10 85 STA 8510 8510

811B CF RST 1 Break point


B. ASCII TO HEX CONVERSION

FLOW CHART:
START

To mask the higher nibble of the register 1

NO
If the
value > 9

YES
Add ‘07’

Add ‘30’

Move the data in temp register2 to temp register1

Mask the lower nibble of the temporary register

NO
If the

YES
Add ‘07’

Add ‘30’

STOP
ALGORITHM:
 Initialize the pointer to the memory for data and result.
 Load the data into D and E register
 ASCII to Hex code conversion the two data of M and B registers.
 Store the result into Memory from 8100H

INPUT:

8500 A1H

OUTPUT:

8501 41H

8502 31H

PROGRAM:

ADDRESS OPCODE MNEMONICS COMMENTS

8100 21 00 85 LXI H,8500 Load 8100 value into H register

8103 Move M register value into


7E MOV A,M Accumulator

8104 Move Accumulator value into B


47 MOV B,A register

8105 23 INX H Increment the H register by one

8106 Each binary bit of ACC is


0F RRC rotated right by one

8107 0F RRC

8108 0F RRC

8109 0F RRC
Now convert the lower nibble to
810A CD 15 81 CALL LOOP ASCII

810D 77 MOV M,A Store that ASCII at 8101

Now HL=8102, Increment H


810E 23 INX H register by one

810F Move Register B value into


78 MOV A,B Accumulator

Now convert the lower nibble to


8110 CD 15 81 CALL LOOP ASCII

8113 77 MOV M,A Store that ASCII at 8102

8114 CF RST 1 Break point

LOOP: ANI
8115 E6 0F 0F Mask the higher nibble

8117 FE 0A CPI 0A Check is it greater then 9

DA1E
8119 81 JC LOOP2 If A not > 9 then simply add 30

not > 9 then add 37 to get the


811C C6 07 ADI 07 ASCII value

811E C6 30 LOOP2: ADI 30

8120 76 HLT Return into Main

RESULT:
Thus the assembly language programs for various code conversions are executed using
8085 microprocessor
EX.No:4 4(a) INTERFACING A/D AND D/A CONVERTER WITH 8085

AIM:

To write an assembly language program to convert an analog signal into a digital


signal
and a digital signal into an analog signal using an ADC interfacing and DAC interfacing
respectively.

A. ADC INTERFACING WITH 8085


APPARATUS REQUIRED:

PROBLEM STATEMENT:

To program starts from memory location 4100H. The program is executed for various
values of analog voltage which are set with the help of a potentiometer. The LED display is
verified with the digital value that is stored in the memory location 4150H.

THEORY
An ADC usually has two additional control lines: the SOC input to tell the ADC when
to start the conversion and the EOC output to announce when the conversion is complete. The
following program initiates the conversion process, checks the EOC pin of ADC 0419 as to
whether the conversion is over and then inputs the data to the processor. It also instructs the
processor to store the converted digital data at RAM 4200H.

ALGORITHM:

1. Select the channel and latch the address.


2. Send the start conversion pulse.
3. Read EOC signal.
4. If EOC =1 continue else go to step (3)
5. Read the digital output.
6. Store it in a memory location.

PROGRAM:

ADDRESS OPCODE MNEMONICS

9100 3E 90 MVI A,90

9102 D3 33 OUT 33

9104 3E 01 MVI A,01

9106 D3 31 OUT 31

9108 3E 01 MVI A,01


910A D3 31 OUT 31

910C 3E 31 MVI A,31

910E D3 31 OUT 31

9110 3E 01 LOOP: MVI A,01

9112 D3 31 OUT 31

9114 E6 01 ANI 01

9116 CA 10 91 JZ LOOP

9119 3E 40 MVI A,40

911B D3 31 OUT 31

911D CD 23 91 CALL DELAY

9120 DB 30 IN 30

9122 CF RST 1

9123 FF 06 FF DELAY: MVI B,FF

9125 0E FF LOP1: MVI C,FF

9127 0D LOP2: DCR C

9128 C2 27 91 JNZ LOP2

912B 05 DCR B

912C C2 25 91 JNZ LOP1

912F C9 RET

PROCEDURE:

Connect a 20 Pin FRC cable between s J4 port (first port) or J1 port (second port) and
the ADC Interface card.

Place jumper JP2 of ADC Interface Card in ‘I’ position.

Connect USB/PS2 keyboard on 8085 Microprocessor. Type and execute the
program.

Vary the analog input (Trim pot) and view the corresponding digital value in the LED
(D0 –D7) and the corresponding hex value will be displayed in Trainer Kits LCD.
4(b) DAC INTERFACING WITH 8085
APPARATUS REQUIRED:

S
OFTWARE EXAMPLES
The following examples illustrate how to control the DAC using 8085 and generate
sine
wave, saw tooth wave by means of software.
(a) SQUARE WAVE GENERATION:
The basic idea behind the generation of waveforms is the continuous generation of
Analog output of DAC. With 00(HEX) as input to DAC2, the analog output is -5V.
Similarly, with FF (Hex) as input, the output is +5V. Outputting digital data 00 and FF at
regular intervals, to DAC2, results in a square wave of amplitude I5 Volts
ALGORITHM:
1. Load the initial value (00) to Accumulator and move it to DAC.
2. Call the delay program
3. Load the final value (FF) to accumulator and move it to DAC.
4. Call the delay program.
5. Repeat steps 2 to 5.

PROGRAM:

ADDRESS OPCODE MNEMONICS

9100 3E 80 MVI A,80

9102 D3 33 OUT 33

9104 3E 00 START: MVI A, 00

9106 D3 30 OUT 30

9108 CD 15 91 CALL DELAY

910B 3E FF MVI A,FF

910D D3 30 OUT 30

910F CD 15 91 CALL DELAY

9112 C3 04 91 JMP START

9115 06 05 DELAY : MVI B,05


9117 0E FF LOOP1 : MVI C,FF

9119 0D LOOP2 : DCR C

911A C2 19 91 JNZ LOOP2

911D 05 DCR B

911E C2 17 91 JNZ LOOP1

9121 C9 RET

AIM

To create a saw-tooth waveform at BI polar port in Micro processor 8085

PROGRAM:

ADDRESS OPCODE MNEMONICS

9100 3E 80 MVI A,80

9102 D3 33 OUT 33

9104 3E 00 START: MVI A, 00

9106 D3 30 LOOP1: OUT 30

9108 3C INR A

9109 C2 06 91 JNZ LOOP1

910C C3 04 91 JMP START

PROCEDURE:

 Connect a 20 Pin FRC Cable between 8085 Microprocessor J4 port (first port) or J1
port(second port) and the DAC interface card.
 Connect a 15v DC adapter with DAC interfacing board.
 Connect the jumper J2 in down position.
 Verify the sawtooth wave output using CRO. The CRO Probe must be connected
between BI polar (positive) and GND pin of J3 Header

Result:

Thus the conversion of an analog signal into a digital signal and a digital signal into an
analog signal was done using interfacing of ADC and DAC respectively with 8085.
EX.No:5 TRAFFIC LIGHT CONTROLLERS WITH 8085

AIM
To write an assembly language program to simulate the traffic light at an intersection
using a traffic light interface.
APPARATUS REQUIRED:

ALGORITHM:
1. Initialize the ports.
2. Initialize the memory content, with some address to the data.
3. Read data for each sequence from the memory and display it through the ports.
4. After completing all the sequences, repeat from step2.

PROCEDURE:

 Connect a 20pin FRC cable between 8085 Trainers J4 port (First port) or J1 port
(second port) and the Traffic light controller.
 Program can be tested with GPIO-II(8255) J4 or with GPIO I(8255) J1.
 Type the Program by using USB/ PS2 Key board.
Execute the Program. Now Traffic Light Led’s are blinking
PROGRAM:

ADDRESS OPCODE MNEMONICS

9100 21 00 92 START : LXI H, 9200

9103 0E 08 MVI C, 08

9105 7E MOV A, M

9106 D3 33 OUT 33

9108 23 INX H

9 109 7E LOOP1: MOV A,M

910A D3 30 OUT 30

910C 23 INX H

910D 7E MOV A,M

910E D3 31 OUT 31

9110 CD 1B 91 CALL DELAY

9113 23 INX H

9114 0D DCR C
9115 C2 09 91 JNZ LOOP1

9118 C3 00 91 JMP START

911B C5 DELAY: PUSH B

911C 0E 05 MVI C,05

911E 11 FF FF LOOP3 : LXI D, FFFF

9121 1B LOOP2 : DCX D

9122 7A MOV A,D

9123 B3 ORA E

9124 C2 21 91 JNZ LOOP2

9127 0D DCR C

9128 C2 1E 91 JNZ LOOP3

912B C1 POP B

912C C9 RET

ORG 9200H

9200 80 DB 80H

9201 21 09 31 09 DB 21H, 09H, 31H, 09H

9205 0C 09 8C 09 DB 0CH, 09H, 8CH, 09H

9209 64 08 64 0C DB 64H, 08H, 64H, 0CH

920D 24 03 26 03 DB 24H, 03H, 26H, 03H

END

RESULT:
Thus an assembly language program to simulate the traffic light at an intersection using a
traffic light interfaces was written and implemented.

EX.NO.6 I/O PORT/SERIAL COMMUNICATION


A. I/O PORT
AIM:

Interface LED & Switch card with 8085 using 8255


PROCEDURE:

 Connect a 20 Pin FRC Cable between 8085 Microprocessor J4 port(first port) or J1


port(second port) and the Led & Switch interface card.
 Connect USB/PS2 keyboard on 8051 Microcontroller JP2 port.
 Now Turn ON/OFF the switches in LED & Switch Interface card and the
corresponding output Led will be turned ON/OFF.

PROGRAM:

ADDRESS OPCODE MNEMONICS

9100 3E 90 MVI A, 90

9102 D3 23 OUT 23H

9104 D3 21 LOOP: OUT 21

9106 DB 20 IN 20

9108 C3 04 91 JMP LOOP

INPUT: give the input through Slide switch

OUTPUT: view the corresponding Digital output on LED


B. SERIAL COMMUNICATION

AIM:
To write a program to initiate 8251 and to check the transmission and reception of
character.

PROCEDURE:

 Place a jumper in J3 between middle and PCLK in 8251 And 8253 interface
card.
 Take two And Two 8251 & 8253 interface card. .
 Connect a 50Pin FRC Cable between 8085 and 8251 &8253 interface card.
 Connect a RS232 FEMALE to FEMALE (cross cable) between two 8251 & 8253
interface card.
 Enter the program,First Execute Receiver program
 Then Execute the transmitter program.
 Press the reset switch on both the .
 The received characters are stored at the memory location 9200.
PROGRAM IN TRANSMITTER

ADDRESS OPCODE LABEL MNEMONICS

9100 21 00 92 LXI H,9200

9103 3E B6 INIT TIMER MVI A,B6

9105 D3 23 OUT 23

9107 3E 40 MVI A,40

9109 D3 22 OUT 22

910B 3E 01 MVI A,01

910D D3 22 OUT 22

910F 3E 00 INIT 8251 MVI A,00

9111 D3 01 OUT 01

9113 D3 01 OUT 01

9115 D3 01 OUT 01

9117 3E 40 MVI A,40

9119 D3 01 OUT 01

911B 3E 4D MVI A,4D

911D D3 01 OUT 01
911F 3E 05 MVI A,05

9121 D3 01 OUT 01

9123 0E 05 MVI C,05

9125 7E SENDCHAR MOV A,M

9126 D3 00 OUT 00

9128 CD 31 91 CALL WAIT

912B 23 INX H

912C 0D DCR C

912D C2 25 91 JNZ SENDCHAR

9130 76 HLT

9131 06 A0 WAIT MVI B,A0H

9133 16 FF LP1 MVI D,FFH

9135 15 LP2 DCR D

9136 C2 35 91 JNZ LP2

9139 05 DCR B

913A C2 33 91 JNZ LP1

913D C9 RET

INPUT:

ADDRESS:

9200H 01H 02H 03H 04H 05H DB 01H, 02H,03H,04H 05H

PROGRAM IN RECEIVER:
ADDRESS OPCODE LABEL MNEMONICS

9100 3E B6 INIT TIMER MVI A,B6

9102 D3 23 OUT 23

9104 3E 40 MVI A,40

9106 D3 22 OUT 22

9108 3E 01 MVI A,01

910A D3 22 OUT 22

910C 3E 00 INIT 8251 MVI A,00

910E D3 01 OUT 01

9110 D3 01 OUT 01

9112 D3 01 OUT 01

9114 3E 40 MVI A,40

9116 D3 01 OUT 01

9118 3E 4D MVI A,4D

911A D3 01 OUT 01

911C 3E 05 MVI A,05

911E D3 01 OUT 01

9120 0E 05 MVI C,05

9122 21 00 92 LXI H, 9200

9125 CD 2F 91 REPEAT CALL WAIT

9128 DB 00 IN 00

912A 77 MOV M,A

912B 23 INX H

912C C3 25 91 JMP REPEAT

912F DB 01 WAIT IN 01
9131 E6 02 ANI 02

9133 FE 02 CPI 02

9135 C2 2F 91 JNZ WAIT

9138 C9 RET

OUTPUT:

ADDRESS:

9200 01H 02H 03H 04H 05H DB 01H,02H,03H,04H 05H

RESULT:
Thus an input/ output port/serial communication program to transfer the data for using 8051
interfaces was written and implemented.

EX.NO:7 READ A KEY /INTERFACE DISPLAY

AIM:
To interface 8279 Programable display controller to 8085 microprocessor.

APPARATUS REQUIRED:

8085 microprocesser tool kit.


8279 interface board.
Regulated dc power supply.
READ A KEY

AIM

To read a key and store the key code in memory location 9200. This code will
be entered into the FIFO whenever a key is pressed. Stored 9200 location (4x4Matrix
method)

PROCEDURE:

 Connect a 50 Pin FRC Cable between 8051 Trainer Kit and the 8279
Keyboard/Display Interface card.
 Connect USB/PS2 Keyboard on 8085 MicroprocessorJP1 port.
 Type and Execute the Program by using USB/PS2 Keyboard.
 Now press any key on 8279 keyboard/ display interface card the equal key value read
and stored in 9200H memory location in 4x4 matrix method.
PROGRAM:

ADDRESS OPCODE MNEMONICS

9100 DB 62 LOOP: IN 62

9102 E6 07 ANI 07
9104 CA 00 91 JZ LOOP

9107 3E 40 MVI A,40H

9109 D3 62 OUT 62

910B DB 60 IN 60

910D E6 0F ANI 0F

910F 32 00 92 STA 9200

9112 76 HLT

ROLLING DISPLAY

AIM:
To display the rolling message “HELLO “in the display.

PROCEDURE:

 Connect a 50 Pin FRC Cable between 8051 Trainer Kit and the 8279
Keyboard/Display Interface card.
 Connect USB/PS2 Keyboard on 8085 Microprocessor JP1 port.
 Type and Execute the Program by using USB/PS2 Keyboard.
 Now the Rolling Message “HELLO” would be display on 8279 keyboard/ display
interface card.
PROGRAM:

ADDRESS OPCODE MNEMONICS

9100 21 00 92 START: LXI H,9200H

9103 16 0F MVI D,0FH

9105 3E 10 MVI A,10H

9107 D3 62 OUT 62

9109 3E CC MVI A,0CCH

910B D3 62 OUT 62

910c 3E 90 MVI A,90H

910F D3 62 OUT 62

9111 7E LOP: MOV A,M

9112 D3 60 OUT 60

9114 CD 1F 91 CALL DELAY

9117 23 INX H

9118 15 DCR D

9119 C2 11 91 JNZ LOP

911C C3 00 91 JMP START

911F 06 A0 DELAY: MVI B,A0H

9121 0E FF LOP1: MVI C,FFH

9123 0D LOP2: DCR C

9124 C2 23 91 JNZ LOP 2


9127 05 DCR B

9128 C2 21 91 JNZ LOP1

912B C9 RET

ORG 9200H

9200 FF FF FF FF DB 0FFH,0FFH,0FFH,0FFH

9204 FF FF FF FF DB 0FFH,0FFH,0FFH,0FFH

9208 98 68 7C 7C DB 98H,68H,7CH,7CH

920C 0C FF FF FF DB 0CH,0FFH,0FFH,0FFH

END

RESULT:

thus 8279 controller was interfaced with 8085 and program for rolling display was
executed successfully.
MICROCONTROLLER

Ex.No:8(a) 8051 – BASIC SIMPLE PROGRAM

AIM:
To write an assembly language program to add, subtract, multiply and divide the given
data stored at two consecutive locations using 8051 microcontroller.

8- BIT ADDITION
ALGORITHM:

 Initialize the pointer to the memory for data and result.


 The ADD instruction writes the result in the accumulator.
 Store the result into Memory from A registers.
INPUT:
 MOV A,# 13
 ADD A,#14
OUTPUT:
 8600 27H

PROGRAM:

ADDRESS OPCODES MNEMONICS COMMENTS


8500 74 13 MOV A,#13 Give 8 bit first data in A register

8502 24 14 ADD A,#14 Give 8 bit second data in acc move

8504 90 86 00 MOVDPTR,#8600 Store in 8600 memory location

8507 F0 MOVX @DPTR,A Store the value acc move

8508 80 FE HERE: SJMP HERE End

8- BIT SUBTRACTION
ALGORITHM:
 Initialize the pointer to the memory for data and result.
 The SUBB instruction writes the result in the accumulator.
 Store the result into Memory from A registers.
INPUT:
 MOV A,# 20
 SUBB A,#10
OUTPUT:
 8600 10H

PROGRAM:
ADDRESS OPCODES MNEMONICS COMMENDS
8500 74 20 MOV A,#20 Give 8 bit first data in A register

8502 94 10 SUBB A,#10 Give 8 bit second data in acc move

8504 90 86 00 MOV DPTR,#8600 Store in 8600 memory location

8507 F0 MOVX @DPTR,A Store the value acc move

8508 80 FE HERE: SJMP HERE End

8-BIT MULTIPLICATIONS

THEORY:
 Using the accumulator, Multiplication is performed and the result is stored.
 Immediate addressing is employed.
 The MUL instruction writes the result in the accumulator

INPUT:
 MOV A,# 06H
 MOV F0,#02H
OUTPUT:
 8600 0CH

PROGRAM:
ADDRESS OPCODES MNEMONICS COMMENDS
8500 74 06 MOV A,#06
8502 75 F0 02 MOV F0,#02
8505 A4 MUL AB
8506 90 86 00 MOV DPTR,#8600
8509 F0 MOVX @DPTR,A
850A A3 INC DPTR
850B E5 F0 MOV A,F0
850D F0 MOVX @DPTR,A
850E 80 FE HERE: SJMP HERE

8-BIT DIVISION
THEORY:
 Using the accumulator, Division is performed and the result is stored.
 Immediate addressing is employed.
 The div instruction writes the result in the accumulator

INPUT:
 MOV A,# 08H
 MOV F0,#02H
OUTPUT:
 8600 04H
 8601 00H

PROGRAM:

ADDRESS OPCODES MNEMONICS COMMENDS


8500 74 08 MOV A,#08
8502 75 F0 02 MOV F0,#02
8505 84 DIV AB
8506 90 86 00 MOV DPTR,#8600
8509 F0 MOVX @DPTR,A
850A A3 INC DPTR
850B E5 F0 MOV A,F0
850D F0 MOVX @DPTR,A
850E 80 FE HERE: SJMP HERE

RESULT:
Thus the addition, subtraction, multiplication and division of two numbers was
performed using the 8051 microcontroller.

Ex N0. 9(A) SUM OF ELEMENTS IN AN ARRAY


AIM:
To find the sum of elements in an array.
ALGORITHM:
1. Load the array in the consecutive memory location and initialize the
memory pointer with the starting address.
2. Load the total number of elements in a separate register as a counter.
3. Clear the accumulator.
4. Load the other register with the value of the memory pointer.
5. Add the register with the accumulator.
6. Check for carry, if exist, increment the carry register by 1. otherwise,
continue
7. Decrement the counter and if it reaches 0, stop. Otherwise increment
the memory pointer by 1 and go to step 4.
PROGRAM:
Label Program Comments
MOV DPTR, #4200 Load 4200 to DPTR, get array size
MOVX A, @DPTR Copy array size value to A
MOV R0, A Move contents of A to R0
MOV B, #00
MOV R1, B
CLR C Clear B, R1 & Carry Flag
AGAIN INC DPTR Get value from data pointer
MOVX A, @DPTR
ADD A, B Sum of two numbers
MOV B, A
JNC NC If no carry jump to NC
INC R1 Else increment R1
NC DJNZ R0,AGAIN Decrement size of array, if not zero fetch data from
DPTR and add to the resultant value
MOV DPTR, #4500 Store the result in 4500 memory locations
MOV A, B
MOVX @DPTR, A
INC DPTR
MOV A, R1
MOVX @DPTR, A
HERE SJMP HERE
OBSERVATION:
INPUT OUTPUT
4200 4500
4201
4202
4203 4501

RESULT:
The sum of elements in an array is calculated.

Exp. No 9(B) 8051 – Check Odd or Even using Call Option


AIM:
To Check whether given number is Odd or Even using Call Option.

ALGORITHM:
1. Start
2. Move the data to DPTR
3. Move the data to accumulator
4. Call check function whether given number is odd or even
5. Increment DPTR
6. Resultant value stored in DPTR-4201
7. Halt Check Function
8. Rotate right through carry
9. If carry copy 00 to B reg (odd number)
10. Else copy EE to B reg (even number)
11. return

PROGRAM:
Label Program Comments
MOV DPTR, #4200 Load 4200 to DPTR, get a number
MOVX A, @DPTR Copy value to A
CALL CHECK_EV_OD Call check function whether given number is
odd or even
INC DPTR
MOV A,B
HERE MOVX @DPTR, A Resultant value stored in DPTR-4201
SJMP HERE

CHECK_EV_OD RRC A Rotate right through carry


JC L1 If carry copy 00 to B reg (odd number)
MOV B,#0EEH Else copy EE to B reg (even number)
L1 MOV B,#00H
RET

OBSERVATION:

INPUT OUTPUT
4200 4201

RESULT:

Thus the given number is either even or odd has been found using 8051
microcontroller.

Ex N0. 10. INTERFACING A/D & D/A CONVERTER WITH 8051


a. ADC INTERFACING WITH

8051 APPARATUS REQUIRED:

SL.NO ITEM SPECIFICATION QUANTITY


1 Microcontroller kit 8051,Vi Microsystems 1
2 Power supply +5 V dc 1
3 ADC Interface board Vi Microsystems 1

PROBLEM STATEMENT:

To program starts from memory location 4100H. The program is executed for
various values of analog voltage which are set with the help of a potentiometer. The LED
display is verified with the digital value that is stored in the memory location 4150H.

THEORY:
An ADC usually has two additional control lines: the SOC input to tell the ADC
when to start the conversion and the EOC output to announce when the conversion is
complete. The following program initiates the conversion process, checks the EOC pin of
ADC 0419 as to whether the conversion is over and then inputs the data to the processor. It
also instructs the processor to store the converted digital data at RAM 4200H.

ALGORITHM:
1. Select the channel and latch the address.
2. Send the start conversion pulse.
3. Read EOC signal.
4. If EOC =1 continue else go to step (3)
5. Read the digital output.
Store it in a memory location.

PROGRAM:

Label Program Comments


MOV DPTR, #FFC8
MOV A,#10 Select Channel 0 and make ALE Low
MOVX @DPTR, A
MOV A,#18 make ALE High
MOVX @DPTR, A
MOV DPTR, #FFD0
MOV A,#01 SOC signal High
MOVX @DPTR, A
MOV A,#00 SOC signal low
MOVX @DPTR, A
MOV DPTR, #FFD8
WAIT MOVX A,@DPTR
JNB E0,WAIT Check for EOC
MOV DPTR,#FFC0 Read ADC data
MOVX A,@DPTR
MOV DPTR,#4150 Store the data in memory location
MOVX @DPTR, A
HERE SJMP HERE

ADC- CIRCUIT:

SOC JUMPER SELECTION:

J2: SOC Jumper selection


J5: Channel selection
(b) INTERFACING D/A CONVERTER WITH 8051

APPARATUS REQUIRED:

SL.NO ITEM SPECIFICATION QUANTITY


1 Microprocessor kit 4185,Vi Microsystems 1
2 Power supply +5 V dc 1
3 DAC Interface board Vi Microsystems 1

THEORY:

SOFTWARE EXAMPLES

After going through the software examples you can learn how to control the
DAC using 8051 and generate sine wave, saw tooth wave etc by means of software.

ALGORITHM:

(a) SQUARE WAVE GENERATION:


1. Load the initial value (00) to Accumulator and move it to DAC.
2. Call the delay program
3. Load the final value (FF) to accumulator and move it to DAC.
4. Call the delay program.
5. Repeat steps 2 to 5.

DAC - CIRCUIT:
WAVEFORMS:

PROGRAM:
The basic idea behind the generation of waveforms is the continuous generation of
Analog output of DAC.
With 00(HEX) as input to DAC2, the analog output is -5V. Similarly, with FF
(Hex) as input, the output is +5V. Outputting digital data 00 and FF at regular intervals, to
DAC2, results in a square wave of amplitude I5 Volts.

ADDRESS LABEL MNEMON ICS OPCODE OPERAND COMMENT


MOV DPTR,#FFC8
START MOV A,#00
MOVX @DPTR,A
LCALL DELAY
MOV A,# FF
MOVX @DPTR,A
LCALL DELAY
LJMP START
DELAY MOV R1,#05
LOO[P MOV R2,#FF
DJNZ R2,HERE
DJNZ R1,LOOP
RET
SJMP START
Execute the program and using a CRO, verify that the waveform at the DAC2
output is a square-wave. Modify the frequency of the square-wave, by varying the time
delay.
(b) SAW TOOTH GENERATION
1. Load the initial value (00) to Accumulator
2. Move the accumulator content to DAC.
3. Increment the accumulator content by 1.
4. Repeat steps 3 and 4.
Output digital data from 00 to FF constant steps of 01 to DAC1 repeat this sequence again
and again. As a result a saw – tooth wave will be generated at DAC1 output.

PROGRAM:

ADDRESS LABEL MNEMON ICS OPCODE OPERAND COMMENT


MOV DPTR,#FFC0
MOV A,#00
LOOP MOVX @DPTR,A
INC A
SJMP LOOP

(c) TRIANGULAR WAVE GENERATION


1. Load the initial value (00) to Accumulator.
2. Move the accumulator content to DAC
3. Increment the accumulator content by 1.
4. If accumulator content is zero proceed to next step. Else go to step 3.
5. Load value (FF) to accumulator.
6. Move the accumulator content to DAC.
7. Decrement the accumulator content by 1.
8. If accumulator content is zero go to step 2. Else go to step 2.

The following program will generate a triangular wave at DAC2 output. The
program is self explanatory.

ADDRESS LABEL MNEMON ICS OPCODE OPERAND COMMENT


MOV DPTR,#FFC8
START MOV A,#00
LOOP1 MOVX @DPTR,A
INC A
JNZ LOOP1
MOV A,#FF
LOOP2 MOVX @DPTR,A
DEC A
JNZ LOOP2
LJMP START

Result:
Thus the square, triangular and saw tooth wave form were generated by interfacing
DAC with 8051 trainer kit.
Ex.No:10 STEPPER MOTOR INTERFACING WITH 8051

AIM:

To interface a stepper motor with 8051 microcontroller and operate it.

THEORY:

A motor in which the rotor is able to assume only discrete stationary angular position is
a stepper motor. The rotary motion occurs in a step-wise manner from one equilibrium position
to the next. Stepper Motors are used very wisely in position control systems like printers, disk
drives, process control machine tools, etc.
The basic two-phase stepper motor consists of two pairs of stator poles. Each of the
four poles has its own winding. The excitation of any one winding generates a North Pole. A
South Pole gets induced at the diametrically opposite side. The rotor magnetic system has two
end faces. It is a permanent magnet with one face as South Pole and the other as North Pole.
The Stepper Motor windings A1, A2, B1, B2 are cyclically excited with a DC current
to run the motor in clockwise direction. By reversing the phase sequence as A1, B2, A2, B1,
anticlockwise stepping can be obtained.
2-PHASE SWITCHING SCHEME:
In this scheme, any two adjacent stator windings are energized. The switching scheme
is shown in the table given below. This scheme produces more torque.

ADDRESS DECODING LOGIC:


The 74138 chip is used for generating the address decoding logic to generate the device
select pulses, CS1 & CS2 for selecting the IC 74175.The 74175 latches the data bus to the
stepper motor driving circuitry.
Stepper Motor requires logic signals of relatively high power. Therefore, the interface
circuitry that generates the driving pulses use silicon Darlington pair transistors. The inputs for
the interface circuit are TTL pulses generated under software control using the Microcontroller
Kit. The TTL levels of pulse sequence from the data bus are translated to high voltage output
pulses using a buffer 7407 with open collector.
PROGRAM:

ADDRESS OPCODE MNEMONICS

9100 3E 80 MVI A,80

9102 D3 33 OUT 33

START: LXI
9104 21 00 92
H,9200

9107 06 04 MVI B,04

REPET : MOV
9109 7E
A,M

910A D3 30 OUT 30

910C 11 02 02 LXI D,0202

910F 00 DELAY: NOP

9110 1B DCX D

9111 7B MOV A,E

9112 B2 ORA D

9113 C2 0F 91 JNZ DELAY

9116 23 INX H

9117 05 DCR B

9118 C2 09 91 JNZ REPET


911B C3 04 91 JMP START

ORG 9200H

9200 03060C09 DB 03H, 06H, 0CH, 09H

END

PROCEDURE:
1. Enter the above program starting from location 4100.and execute the same.
2. The stepper motor rotates.
3. Varying the count at R4 and R5 can vary the speed.
4. Entering the data in the look-up TABLE in the reverse order can vary direction of
rotation.

Result:
Thus a stepper motor was interfaced with 8051 and run in forward and reverse
directions at various speeds.

You might also like