You are on page 1of 8

LAB REPORT 02

MICROPROCESSORS AND INTERFACING

ECX4236

NAME: Y.M.L.KUMARA

REG NO: 50864636

DATE: 22,23/09/2010

GROUP: CL05
Experiment 01

Write an ALP to generate the PWM signal having 25% duty cycle with 40Hz.

Step 01

Write an ALP to light a LED with above PMW signal

Calculation
Required frequency=40Hz
Then time period =1/40 = 25000 micro seconds
Required time for delay loop= 25000/100=250 Micro seconds
Let’s find the time value= 65536-250=65286 dec
=ff06H
Then TL0=06H and TH0=ffH

Then ALP for above case

TH0 EQU 08CH


TL0 EQU 08AH
TR0 BIT 08CH
TF0 BIT 08DH
TMOD EQU 089H
P1_0 BIT 090H
P1_6 BIT 096H

ORG 0H

MAIN: SETB P1_6


MONITOR:
CLR P1_6
MOV R5,#25
ACALL DELAY
SETB P1_6
MOV R5,#75
ACALL DELAY
SJMP MONITOR

DELAY:
MOV TMOD ,#01H

HERE: MOV TL0,#06H


MOV TH0,#0FFH
SETB TR0
AGAIN: JNB TF0,AGAIN
CLR TR0
CLR TF0
DJNZ R5,HERE
RET
END
Step 02

Write an ALP to automatic two LED with above signal.

TH0 EQU 08CH


TL0 EQU 08AH
TR0 BIT 08CH
TF0 BIT 08DH
TMOD EQU 089H
P1_4 BIT 094H
P1_6 BIT 096H

ORG 7000H

MAIN:CLR P1_6

MONITOR:
CLR P1_6
MOV R5,#25
ACALL DELAY
SETB P1_6

CLR P1_4
MOV R5,#75
ACALL DELAY
SETB P1_4

SJMP MONITOR

DELAY:
MOV TMOD ,#01H

HERE: MOV TL0,#06H


MOV TH0,#0FFH
SETB TR0
AGAIN: JNB TF0,AGAIN
CLR TR0
CLR TF0
DJNZ R5,HERE
RET
END

Finally check the result with Oscilloscope and it gives 38.461Hz signal because of this deviation is
due to instructions delay that omitted in the programme.

Volts

2.5

2 1 1234 time
OBSERVATION

Time period according to the graph = (1.4+3.8)*5 ms

= 26ms

Then frequency = 1/0.026

= 38.46Hz

Experiment 02
Write a ALP to display character “A” on LCD display

ORG 7000H
MOV A,65
CLR 90H
MOV DPTR, #0FFF3H
MOVX @DPTR,A
MOV R0,#0
DJNZ R0,$
DJNZ R0,$
CLR 91H
SETB 91H
END

Experiment 03
Figure below depicts the waveform of quadrature outputs of the quadrature encoder of a DC
motor. Channel “A” connected to T0 pin and channel “B” connected to T1 pin of the 8051
microcontroller. Table 3.1 and table 3.2 depict gray coding of quadrature outputs as follows.
Write an assembly language program to identify the speed and rotational direction (whether the
clockwise or counter‐clockwise) of the encoder using 8051 counters.

Step 01
Write a ALP to light a LED when it’s clockwise and light an another LED when anticlockwise.
Assume above A & B signals are connected to I3 and I2 respectively.

ALP for above case

P3_4 BIT 0B4H ; I3


P3_5 BIT 0B5H ; I2`
P1_4 BIT 094H
P1_5 BIT 095H
P1_6 BIT 096H
TMOD EQU 089H
TH0 DATA 08CH
TL0 DATA 08AH
TR0 BIT 08CH
TF0 BIT 08DH

ORG 7000H
CLR TF0
SETB P3_4
SETB P3_5
MOV TMOD,#6H
MOV TL0,#0FEH
SETB TR0 ; START TIMER 0

HERE: JNB TF0,HERE


ACALL FOLLINGEDGE
CLR TF0

FOLLINGEDGE:
JNB P3_5,CLOCKWISE
CLR P1_6
RET

CLOCKWISE:
CLR P1_4
RET
END

Step 02
Write a ALP to display “C” on LCD when clockwise and “A” when anticlockwise. Assume above A
& B signals are connected to I3 and I2 respectively.

ORG 7000H
CLR TF0
SETB P3_4
SETB P3_5
MOV TMOD,#6H
MOV TL0,#0FEH
SETB TR0 ;START TIMER 0

HERE: JNB TF0,HERE


ACALL FOLLINGEDGE
CLR TF0
FOLLINGEDGE:
LCALL 4100H
JNB P3_5,CLOCKWISE
MOV R5,#65
LCALL LCD
RET

CLOCKWISE:
MOV R5,#67
LCALL LCD
RET
LCD:
MOV A,R5
CLR 90H
MOV DPTR,#0FFF3H
MOVX @DPTR,A
MOV R0,#0
DJNZ R0,$
DJNZ R0,$
CLR 91H
SETB 91H
RET
END

Step 03
Write an ALP to make delay 1minutes.

ALP for above case

ORG 7000H
CLR P1_5
CLR TF1
MOV TMOD,#10H
ACALL DELAY
SETB P1_5

DELAY:
H1: MOV R2,#0AH
H2: MOV R3,#64H
H3: MOV TL1,#0A0H
MOV TH1,#15H
SETB TR1

BACK: JNB TF1,BACK


CLR TF1
CLR TR1
DJNZ R3,H3
DJNZ R2,H2
RET
END
Step 04

Write an assembly language program to identify the speed and rotational direction (whether the
clockwise or counter‐clockwise). Display “C” on LCD when clockwise and “A” when anticlockwise
and speed in RPM.

P3_4 BIT 0B4H ; I3


P3_5 BIT 0B5H ; I2`
P1_4 BIT 094H
P1_5 BIT 095H
P1_6 BIT 096H
TMOD EQU 089H
TH0 DATA 08CH
TL0 DATA 08AH
TR0 BIT 08CH
TF0 BIT 08DH
TH1 DATA 08DH
TL1 DATA 08BH
TR1 BIT 08EH
TF1 BIT 08FH

ORG 7000H
CLR TF0
SETB P3_4
SETB P3_5
MOV TMOD,#6H
MOV TL0,#0FEH
SETB TR0 ;START TIMER 0

HERE: JNB TF0,HERE


ACALL FOLLINGEDGE
CLR TF0
LCALL RPM

FOLLINGEDGE:
LCALL 4100H
JNB P3_5,CLOCKWISE
MOV R5,#65
LCALL LCD
RET

CLOCKWISE:
MOV R5,#67
LCALL LCD
RET

LCD:
MOV A,R5
CLR 90H
MOV DPTR,#0FFF3H
MOVX @DPTR,A
MOV R0,#0
DJNZ R0,$
DJNZ R0,$
CLR 91H
SETB 91H
RET

RPM: MOV TH0,#0


MOV TL0,#0
SETB TR0
CLR TF1
MOV TMOD,#10H

ACALL DELAY

MOV R5,TH0
LCALL LCD
MOV R5,TL0
LCALL LCD

DELAY:
H1: MOV R2,#0AH
H2: MOV R3,#64H
H3: MOV TL1,#0A0H
MOV TH1,#15H
SETB TR1

BACK: JNB TF1,BACK


CLR TF1
CLR TR1
DJNZ R3,H3
DJNZ R2,H2
RET
RET
END

You might also like