mc lab manual

36
1 | Page LABORATORY MANUAL ECE 322 MICRO CONTROLLER AND APPLICATIONS LABORATORY

Upload: harish-usurupati

Post on 30-Dec-2014

240 views

Category:

Documents


11 download

TRANSCRIPT

Page 1: Mc Lab Manual

1 | P a g e

LABORATORY MANUAL

ECE 322 MICRO CONTROLLER AND APPLICATIONS

LABORATORY

Page 2: Mc Lab Manual

2 | P a g e

TABLE OF CONTENTS

S. No. Title of the Experiment Page No.

1 8085 Basic Program on simulator 3

2 Perform the basic programs using 8085 Microprocessor kit in

assembly language.

7

3 Interfacing of Seven segment displays with 8085 microprocessor. 11

4 Interfacing and control of stepper motor using 8085

microprocessor.

13

5 Design a 8085 Microprocessor based Traffic light control 15

6 8051 Assembly language programming using Keil compiler. (At

least 5 programs.).

18

7 Interfacing of LCD with8051 Microcontroller 24

8 Interfacing of ADC with 8051 Microcontroller 29

9 Interfacing of DAC with 8051 Microcontroller 30

10 Interfacing of keyboard with 8051 Microcontroller 33

Page 3: Mc Lab Manual

3 | P a g e

Experiment 1

Aim: 8085 Basic Program on simulator.

i. Write a program to add two 8-bit numbers.

ii. Write a program to subtract two 8-bit numbers.

iii. Write a program to multiply two 8 bit numbers by repetitive addition method.

iv. Write a program to generate Fibonacci series.

Requirements: 8085 Simulator

Learning Objectives: Use of 8085 simulator to perform basic assembly programs.

Outline of the Procedure:

1. Open simulator on your laptop.

2. Write the given code.

3. Save the file.

4. Assemble the code and check error, if error remove it and again assemble it.

5. Execute the code and verify the results.

Program (i):

Address Machine

Code / Data

Label Mnemonics Operands Comments

2000 21 LXI H,3000h

2001 00

2002 30

2003 7E MOV A,M

2004 23 INX H

2005 86 ADD M

2006 23 INX H

2007 77 MOV M,A

2008 EF RST5

Page 4: Mc Lab Manual

4 | P a g e

Program (ii):

Address Machine

Code / Data

Label Mnemonics Operands Comments

2000 21 LXI H,3000h

2001 00

2002 30

2003 7E MOV A,M

2004 23 INX H

2005 96 SUB M

2006 23 INX H

2007 77 MOV M,A

2008 EF RST5

Program (iii):

Address Machine

Code / Data

Label Mnemonics Operands Comments

2000 3A LDA 3000h

2001 00

2002 30

2003 5F MOV E, A

2004 16 MVI D, 00h

2005 00

2006 3A LDA 3001h

2007 01

2008 30

2009 4F MOV C,A

200A 21 LXI H, 0000h

200B 00

Page 5: Mc Lab Manual

5 | P a g e

200C 00

200D 19 KK DAD D

200E 0D DCR C

200F C2 JNZ KK

2010 0D

2011 20

2012 22 SHLD 3002h

2013 02

2014 30

2015 EF RST5

Program (iv):

Address Machine

Code / Data

Label Mnemonics Operands Comments

2000 21 LXI H, 2501h

2001 00

2002 25

2003 3E MVI A, 00h

2004 00

2005 0E MVI C, 0Ah

2006 0A

2007 77 MOV M, A

2008 06 MVI B,01h

2009 01

200A 0D DCR C

200B 23 KK INX H

200C 80 ADD B

200D 70 MOV M, B

200E 57 MOV D, A

200F 78 MOV A, B

Page 6: Mc Lab Manual

6 | P a g e

2010 42 MOV B, D

2011 0D DCR C

2012 C2 JNZ KK

2013 0B

2014 20

2015 EF RST5

Learning outcomes: to be written by the students in 50-70 words.

Page 7: Mc Lab Manual

7 | P a g e

Experiment 2

Aim: Perform the following using 8085 Microprocessor kit in assembly language.

i. Write a program to add two 16-bit numbers.

ii. Write a program to subtract two 16-bit numbers.

iii. Write a program to multiply two 8 bit numbers by rotation method.

Requirements: 8085 Microprocessor kit

Learning Objectives: Use of 8085 Kit to perform basic assembly programs.

Outline of the Procedure:

1. Turn of the kit

2. Enter the code in assembly language.

3. Execute the code and verify the results.

Program (i):

Address Machine

Code / Data

Label Mnemonics Operands Comments

2007 2A LHLD 2000h

2008 00

2009 20

200A EB XCHG

200B 2A LHLD 2002h

200C 02

200D 20

200E 0E MVI C,00h

200F 00

2010 19 DAD D

2011 D2 JNC KK

Page 8: Mc Lab Manual

8 | P a g e

2012 15

2013 20

2014 0C INR C

2015 22 KK SHLD 2004h

2016 04

2017 20

2018 79 MOV A,C

2019 32 STA 2006h

201A 06

201B 20

201C EF RST5

Program (ii):

Address Machine

Code / Data

Label Mnemonics Operands Comments

2007 21 LXI H, 2000h

2008 00

2009 20

200A 7E MOV A,M

200B 23 INX H

200C 96 SUB M

200D 32 STA 2004h

200E 04

200F 20

2010 23 INX H

2011 7E MOV A,M

2012 23 INX H

2013 9E SBB M

2014 32 STA 2005h

2015 05

Page 9: Mc Lab Manual

9 | P a g e

2016 20

2017 3E MVI A, 00h

2018 00

2019 17 RAL

201A 32 STA 2006h

201B 06

201C 20

201D EF RST5

Program (iii):

Address Machine

Code / Data

Label Mnemonics Operands Comments

2000 21 LXI H, 2501h

2001 01

2002 25

2003 5E MOV E, M

2004 16 MVI D, 00h

2005 00

2006 23 INX H

2007 7E MOV A, M

2008 21 LXI H, 0000h

2009 00

200A 00

200B 06 MVI B, 08h

200C 08

200D 29 YY DAD H

200E 13 RAL

200F D2 JNC KK

2010 13

2011 20

Page 10: Mc Lab Manual

10 | P a g e

2012 19 DAD D

2013 05 KK DCR B

2014 C2 JNZ YY

2015 0D

2016 20

2017 22 SHLD 2503h

2018 03

2019 25

201A EF RST5

Learning outcomes: to be written by the students in 50-70 words.

Page 11: Mc Lab Manual

11 | P a g e

Experiment 3

Aim: Interfacing of Seven segment display with 8085 microprocessor.

Requirements: 8085 Microprocessor kit, Seven Segment LED & wires.

Learning Objectives: Interfacing of seen segment using 8255.

Outline of the Procedure:

1. Connect the circuit as shown in the below diagram

2. Turn on the kit.

3. Write the given code.

4. Execute the code and verify the results on seven segment display.

Circuit Diagram:

Program:

MVI A, 80H

OUT CR

K: LXI H, 2000H

MVI B, 10H

Page 12: Mc Lab Manual

12 | P a g e

KK: MOV A, M

OUT PA

JMP DELAY

INX H

JNZ KK

JMP K

HLT

Delay: LXI D, Count

Back: DCX D

MOV A, D

ORA E

JNZ Back

RET

Inputs:

2000: 40H, 79H, 24H, 30H, 19H, 12H, 02H, 78H, 00H, 18H, 08H, 03H, 46H, 21H, 06H,

0EH

Result:

On the Seven segment LED we can see all the Hexadecimal no’s displayed with some

delay as mentioned.

Learning outcomes: to be written by the students in 50-70 words.

Page 13: Mc Lab Manual

13 | P a g e

Experiment 4

Aim: Interfacing and control of stepper motor using 8085 microprocessor.

Requirements: 8085 Microprocessor kit, Stepper Motor, Motor driver circuit

(ULN2003) & wires.

Learning Objectives: Interfacing of stepper motor using 8255.

Outline of the Procedure:

1. Connect the interfacing circuit of stepper motor to 8085 kit.

2. Turn on the kit.

3. Write the given code.

4. Execute the code and verify the results.

Program:

i) To rotate in Clock Wise direction

MVI A, 80H

OUT CR

MVI A, 44H

KK: OUT PA

CALL DELAY

RRLC

JMP KK

RST 5

ii) To rotate in Anti-Clock Wise direction

MVI A, 80H

OUT CR

MVI A, 44H

KK: OUT PA

CALL DELAY

RLC

JMP KK

Page 14: Mc Lab Manual

14 | P a g e

RST 5

Delay: LXI D, Count

Back: DCX D

MOV A, D

ORA E

JNZ Back

RET

Result: Stepper motor rotates in Clock wise & Anti-clock wise direction.

Learning outcomes: to be written by the students in 50-70 words.

Page 15: Mc Lab Manual

15 | P a g e

Experiment 5

Aim: Design a 8085 Microprocessor based Traffic light control for

figure shown below with the following conditions:

Allow traffic to flow from N to S & S to N for 1sec

Glow all Yellow lights for 0.2sec

Allow traffic to flow from W to E & E to W for 1sec

Glow all Yellow lights for 0.2sec

Make this process continues.

Requirements: 8085 Microprocessor Kit, 9 LED’s, 5K resistors (9)

Learning Objectives: Design of traffic light control using 8085 microprocessor

Outline of the Procedure:

1. Connect the circuit as shown in the below diagram

2. Turn on the kit.

3. Write the given code.

4. Execute the code and verify the results on leds.

Circuit Diagram:

Page 16: Mc Lab Manual

16 | P a g e

Program:

MVI A, 80H : Initialize 8255, port A and port B

OUT CR ;(CR) : in output mode

START: MVI A, 09H

OUT PA; (PA) : Send data on PA to glow R1 and R2

MVI A, 24H

OUT PB; (PB) : Send data on PB to glow G3 and G4

MVI C, 28H : Load multiplier count (40ıο) for delay

CALL DELAY : Call delay subroutine

MVI A, 12H

OUT PA; PA : Send data on Port A to glow Y1 and Y2

OUT 81H ;PB : Send data on port B to glow Y3 and Y4

MVI C, 0AH : Load multiplier count (10ıο) for delay

CALL: DELAY : Call delay subroutine

MVI A, 24H

OUT 80H ;PA : Send data on port A to glow G1 and G2

MVI A, 09H

OUT 81H; PB : Send data on port B to glow R3 and R4

MVI C, 28H : Load multiplier count (40ıο) for delay

CALL DELAY : Call delay subroutine

MVI A, 12H

OUT 80H : Send data on port A to glow Y1 and Y2

OUT 81H : Send data on port B to glow Y3 and Y4

MVI C, 0AH : Load multiplier count (10ıο) for delay

CALL DELAY : Call delay subroutine

Page 17: Mc Lab Manual

17 | P a g e

JMP START

Delay Subroutine:

DELAY: LXI D, Count : Load count to give 0.5 sec delay

BACK: DCX D : Decrement counter

MOV A, D

ORA E : Check whether count is 0

JNZ BACK : If not zero, repeat

DCR C : Check if multiplier zero, otherwise repeat

JNZ DELAY

RET : Return to main program

Learning outcomes: to be written by the students in 50-70 words.

Page 18: Mc Lab Manual

18 | P a g e

Experiment 6

Aim: 8051 Assembly language programming using Keil compiler.

a. Find the sum of the values 79H, F5H, E2H. Put the sum in register R0 (low byte)

and R5 (high byte).

b. Write a program to copy the values 55H into RAM memory locations 40H to 45H

using

i) Direct addressing mode

ii) Register indirect addressing mode without using loop

iii) With a loop

c. Write a program to toggle all the bits of P1 after some delay

d. Write a program to generate square wave of 50% duty cycle on bit 0 of port 1

e. Write a program to

i) Make P1 as input port.

ii) To get hex data from P1 and convert it into decimal and save the digits in

R7, R6, R5.

f. Write a program to add two 16 – bit numbers 3CE7H and 3B8DH. Place the sum

in R7 and R6 (Lower Byte).

g. A switch is connected to P1.7. Write a program to check the status of SW and

perform the following:

i) If SW=0, send letter „N. to P2.

ii) If SW=1, send letter „Y. to P2.

h. Write a program for Hex to ASCII conversion

i. Write a program to generate square wave using timer

Requirements: Keil software

Learning Objectives: Use of Keil software to perform basic assembly programs

Outline of the Procedure:

1. Open Keil software on your laptop.

2. Write the given code.

Page 19: Mc Lab Manual

19 | P a g e

3. Save the file.

4. Assemble the code and check error, if error remove it and again assemble it.

5. Execute the code and verify the results.

Program (a):

Org 0000h

mov a,#79h

mov r5,#00h

add a,#0f5h

jnc here

inc r5

here: add a,#0e2h

jnc go

inc r5

go: mov r0,a

end

Program (b):

i) Direct addressing mode

MOV A,#55

MOV 40H,A

MOV 41H,A

MOV 42H,A

MOV 43H,A

MOV 44H,A

MOV 45H,A

ii) Register indirect addressing mode without using loop

MOV R0,#40H

MOV A,#55H

MOV @R0,A //copy a to ram location r0 points to

INC R0

MOV @R0,A

Page 20: Mc Lab Manual

20 | P a g e

INC R0

MOV @R0,A

INC R0

MOV @R0,A

INC R0

MOV @R0,A

INC R0

END

iii) With a loop.

MOV R0,#40H

MOV A,#55H

GO:MOV @R0,A

INC R0

CJNE R0,#46H, GO

END

Program (c):

org 0000h

again:

mov p1,#55h

acall delay

mov p1,#0aah

acall delay

sjmp again

delay:mov r0,#04h

go3:mov r1,#0ffh

go2:mov r2,#0ffh

go1:djnz r2,go1

djnz r1,go2

djnz r0,go3

ret

end

Program (d):

org 0000h

Page 21: Mc Lab Manual

21 | P a g e

again:cpl p1.0

sjmp again

end

Program (e):

Org 0000h

mov a,#0ffh

mov p1,a

mov a,p1

mov b,#10

div ab

mov r7,b

mov b,#10

div ab

mov r6,b

mov r5,a

end

Program (f):

org 0000h

mov r5,#00h

mov a,#0e7h

add a,#8dh

mov r6,a

mov a,#3ch

addc a,#3bh

jnc go

inc r5

go: mov r7,a

end

Program (g):

org 0000h

setb p1.7

again:mov c,p1.7

jnc go

Page 22: Mc Lab Manual

22 | P a g e

mov p2,#'Y'

go:mov p2,#'N'

sjmp again

end

Program (h):

org 0000h

mov a,#2dh

mov r1,a

anl a,#0fh

acall char

mov r2,a

mov a,r1

swap a

anl a,#0fh //mov the lower nibble to r2

acall char

mov r3,a

here:sjmp here

char:

cjne a,#0ah,out1

mov a,#41h //to get 41

sjmp go

out1:cjne a,#0bh,out2

mov a,#42h //to get 42

sjmp go

out2:cjne a,#0ch,out3

mov a,#43h //to get 43

sjmp go

sjmp code1

code1:

out3:cjne a,#0dh,out4

mov a,#44h //to get 44

sjmp go

out4:cjne a,#0eh,out5

Page 23: Mc Lab Manual

23 | P a g e

mov a,#45h //to get 45

sjmp go

out5:cjne a,#0fh,out

mov a,#46h //to get 46

sjmp go

out:

orl a,#30h

go:

ret

end

Program (i):

org 0000h

again:mov tmod,#01h

mov th0,#01h

mov tl0,#00h

cpl p1.1

setb tr0

here: jnb tf0,here

clr tr0

clr tf0

sjmp again

end

Learning outcomes: to be written by the students in 50-70 words.

Page 24: Mc Lab Manual

24 | P a g e

Experiment 7

Aim: Interfacing of ADC with 8051 Microcontroller

Requirements: 8051, 11.0592MHz Crystal, 33pF (2), 10uF, 10K, push button, 1K (10),

Analog to Digital Convertor (ADC0808), Bread Board, Connecting wires, 5V power

supply

Circuit Diagram:

Program :

ORG 0000H

LJMP MAIN ;jump to main progam

ORG 000B ;address of Timer 0 interrupt

CPL P2.3 ;generation of less than 100MHz frequency

RETI

MAIN:

ORG 0300H

LCALL LCD ;Initialisaiton of LCD

ACALL DISPLAY

Page 25: Mc Lab Manual

25 | P a g e

MOV TMOD,#02H ;initialisation of timer 0

MOV TH0,0D8H ;delay for more than 100MHz frequency

MOV IE,#82H ;Enable Timer interrut 0

SETB TR0 ;Start timer

MOV P0,#0FFH ;Make P0 as input port

SETB P2.7 ;make EOC an input port

CLR P2.4 ;clear ALE

CLR P2.6 ;clear WR i.e. start of conversion

CLR P2.5 ;clear RD i.e. out enable

CLR P3.7 ;For the selection of data bus for 3.

SETB P3.6

SETB P3.5

BACK:ACALL DELAY

SETB P2.4 ;ALE

ACALL DELAY

SETB P2.6 ;SC

ACALL DELAY

CLR P2.4 ;ALE

CLR P2.6 ;SC

HERE:JB P2.7,HERE ;wait untill done

SETB P2.5

ACALL DELAY_1

MOV A,P0

CLR P2.5

ACALL CONVERSION

ACALL DISPLAY

SJMP BACK

CONVERSION: ;conversion from HEX to BCD

MOV B,#0AH

DIV AB

MOV R0,B

MOV B,#10

DIV AB

Page 26: Mc Lab Manual

26 | P a g e

MOV R1,B

MOV R2,A

MOV A,R0

ADD A,#30H

MOV R0,A

MOV A,R1

ADD A,#30H

MOV R1,A

MOV A,R2

ADD A,#30H

MOV R2,A

RET

LCD: ;Initialization of LCD

MOV A,#38H

ACALL COMM

ACALL DELAY_1

MOV A,#0EH

ACALL COMM

ACALL DELAY_1

MOV A,#01H

ACALL COMM

ACALL DELAY_1

MOV A,#06H

ACALL COMM

ACALL DELAY_1

MOV A,#80H

ACALL COMM

ACALL DELAY_1

RET

DISPLAY:

MOV A,#'T'

ACALL WRITE

MOV A,#'E'

Page 27: Mc Lab Manual

27 | P a g e

ACALL WRITE

MOV A,#'M'

ACALL WRITE

MOV A,#'P'

ACALL WRITE

MOV A,#'.'

ACALL WRITE

MOV A,#' '

ACALL WRITE

MOV A,R2

ACALL WRITE

MOV A,R1

ACALL WRITE

MOV A,R0

ACALL WRITE

MOV A,#'`'

ACALL WRITE

MOV A,#'C'

ACALL WRITE

ACALL DELAY_1

MOV A,#80H

ACALL COMM

RET

COMM:

MOV P1,A

CLR P2.0

CLR P2.1

SETB P2.2

ACALL DELAY_1

CLR P2.2

RET

WRITE:

MOV P1,A

Page 28: Mc Lab Manual

28 | P a g e

SETB P2.0

CLR P2.1

SETB P2.2

ACALL DELAY_1

CLR P2.2

RET

DELAY_1:

MOV R4,#01H

HERE11:MOV R5,#0FFH

HEREE:DJNZ R5,HEREE

DJNZ R4,HERE11

RET

DELAY:

MOV R6,#50

HERE55:DJNZ R6,HERE55

RET

END

Learning outcomes: to be written by the students in 50-70 words.

Page 29: Mc Lab Manual

29 | P a g e

Experiment 8

Aim: Interfacing of DAC with 8051 Microcontroller

Requirements: 8051, 11.0592MHz Crystal, 33pF (2),100nF(2), 10uF, 10K, push button,

10K resistor(1),1k resistor(1), DAC0808, Op-Amp 741, Bread Board, Connecting wires,

5V & 12V split power supply,

Circuit Diagram:

Program:

;Generation of Triangle wave

org 0000h

again:mov a,#00h ;minimum magnitude

back:mov p2,a ;mag. copy to p2

cjne a,#0ffh,next ;max. mag.

sjmp triangle

next:

inc a

sjmp back

triangle: ;for slope down

mov r0,a

djnz r0,again

mov p2,r0

sjmp triangle

end

Page 30: Mc Lab Manual

30 | P a g e

Experiment 9

Aim: Interfacing of LCD with8051 Microcontroller

Requirements: 8051, 11.0592MHz Crystal, 33pF (2), 10uF, 10K, push button, 1K (10),

LCD (Liquid Crystal Display), Bread Board, Connecting wires, 5V power supply.

Circuit Diagram:

Program:

ORG 0000H

MOV A,#38H

ACALL COM

MOV A,#0EH

ACALL COM

MOV A,#01H

ACALL COM

MOV A,#10H

ACALL COM

MOV A,#80H

ACALL COM

Page 31: Mc Lab Manual

31 | P a g e

AGAIN: ACALL DISPLAY

MOV A,#01H

ACALL COM

SJMP AGAIN

COM: ACALL DELAY

CLR P2.0

CLR P2.1

SETB P2.2

MOV P1,A

ACALL DELAY

CLR P2.2

ACALL DELAY

RET

DATA1: ACALL DELAY

SETB P2.0

CLR P2.1

SETB P2.2

MOV P1,A

ACALL DELAY

CLR P2.2

ACALL DELAY

RET

DELAY: MOV R0,#15H

GO: MOV TMOD,#01H

MOV TL0,#0FFH

MOV TH0,#0DBH

SETB TR0

BACK: JNB TF0,BACK

CLR TR0

CLR TF0

DJNZ R0,GO

RET

DISPLAY: MOV R1,#14D

Page 32: Mc Lab Manual

32 | P a g e

MOV A,#00H

MOV DPTR,#MYDATA

NEXT: CLR A

MOVC A,@A+DPTR

JZ OUT

ACALL DATA1

INC DPTR

CLR A

DJNZ R1,NEXT

OUT: RET

MYDATA:DB "*I LOVE INDIA*"

END

Learning outcomes: to be written by the students in 50-70 words.

Page 33: Mc Lab Manual

33 | P a g e

Experiment 10

Aim: Interfacing of keyboard with 8051 Microcontroller

Requirements: 8051, 11.0592MHz Crystal, 33pF (2), 10uF, 10K, push button

(5 piece for Key-Board),4k7 resistor,10k resistor, 1K (10), LCD, Bread Board,

Connecting wires, 5V power supply

Circuit Diagram:

Program:

//Interfacing of keyboard with lcd

org 0000h

acall lcd

acall keyboard

lcd:

mov a,#38h //2*16 matrix lcd

acall command

Page 34: Mc Lab Manual

34 | P a g e

mov a,#0eh //dispaly on cursor on

acall command

mov a,#01h

acall command

mov a,#06h

acall command

mov a,#80h

acall command

ljmp code2

code2:

ret

command:

acall delay

mov p1,a

clr p3.0

clr p3.1

setb p3.2

acall delay

clr p3.2

ret

data1:

acall delay

mov p1,a

setb p3.0

clr p3.1

setb p3.2

acall delay

clr p3.2

acall delay

ret

delay:

mov r0,#15h

go:mov tmod,#01h

Page 35: Mc Lab Manual

35 | P a g e

mov tl0,#0ffh

mov th0,#0dbh

setb tr0

back:jnb tf0,back

clr tr0

clr tf0

djnz r0,go

ret

keyboard:

mov p2,#0ffh

k1:mov p0,#00h //checking of keyboard's

mov a,p2

anl a,#03h

cjne a,#03h,k1

k2:

acall delay

mov a,p2

anl a,#03h

cjne a,#03h,over

sjmp k2

over:acall delay //checking for row

mov a,p2

anl a,#03h

cjne a,#03h,over1

sjmp k2

over1:

mov p0,#0feh

mov a,p2

anl a,#03h

cjne a,#03h,row0

mov p0,#0fdh

mov a,p2

anl a,#03h

Page 36: Mc Lab Manual

36 | P a g e

cjne a,#03h,row1

ljmp k2

row0:

mov dptr,#code0

sjmp find

row1:

mov dptr,#code1

sjmp find

find:

rrc a

jnc match

inc dptr

sjmp find

match:

clr a

movc a,@a+dptr

acall data1

ljmp k1

code0:

db '1','2'

code1:

db '3','4'

end

Learning outcomes: to be written by the students in 50-70 words.