Microprocessor Lab Report
Microprocessor Lab Report
EEX4436
Microprocessor And Interfacing
Lab 02
Submitted to
at
on
0
EXPERMIMENTS 01: OBSERVING THE SWITCH BOUNCE
LEARNING OUTCOMES
INTRODUCTION
This laboratory session was focuses on interfacing 8051 microcontroller with components
like DC motors, Stepper motors, an LCD display while familiarizing the common
microcontroller operations like interrupts and counters.
For the 8051 microcontroller interfacing and programming purposes we use the AES-51
microcontroller board.
1
For interfacing motors with the board a motor controller should be connected and L293D
motor controller was used to as it provides ports two connect two DC motors or 1 Stepper
motor.
APPARATUS
PROCEDURE
A push button was connected to a parallel input port using jumper wires.
The program was implemented to toggle an LED when the switch is pressed and uploaded to
the board.
The oscilloscope DSO probe was connected to the microcontroller input pin where the switch
is connected and the switch bounce effect was observed.
2
EXPERIMENT 02: DC MOTOR CONTROL USING PWM SIGNALS
The code was uploaded to the board and the behavior of the DC motor was observed
An ALP to rotate the stepper motor using full step method was implemented and uploaded to
the board.
Next, an ALP was implemented to rotate the stepper motor using half step method.
The code was uploaded to the board and the motor behavior was observed.
Then ALP to rotate the stepper motor one cycle clockwise and one cycle counterclockwise
was implemented and uploaded to the board.
Then an ALP to rotate the stepper motor one cycle clockwise and one cycle counter
clockwise using full step method was implemented.
The code was uploaded to the board and the motor behavior was observed.
3
Finally, an ALP to rotate the stepper motor 120 degrees in clockwise direction and
counterclockwise direction was implemented.
The code was uploaded to the board and the motor behavior observed.
An ALP to display the letter “A” on the LCD was implemented and uploaded to the board.
The letter “A” which displayed in the LCD screen was observed.
An ALP was implemented to display my name on the LCD display and uploaded to the
board.
A push button was connected to the Pin 3.4 and an ALP was implemented to display 10
counts on the LCD when push button is pressed 10 times.
The code was uploaded to the board and output displayed on the LCD was observed.
Another push button was connected to Pin3.2 and the code was updated to reset the counting
value when the 2nd push button was pressed.
Finally a system was implemented to follow the following process and uploaded it to the
board,
Output displayed on the LCD with the push button inputs was observed.
4
CODES AND OBSERVATIONS
Assembly code
ORG 7000H
L1:
JNB P3_2, L1
CLR P1_4
ACALL DELAY
SETB P1_4
ACALL DELAY
SJMP L1
DELAY:
MOV R1,#50
DJNZ R1, $
RET
END
.Lst FIle
_SAMTAS^1
PAGE 1
5
7011 22 20 RET
21
22 END
23
24
25
26
27
28
29
30
31
32
.Hex file
:1070000030B1FDC294110DD294110D80F37932D9B3
:02701000FE225E
:00000001FF
b) Program to read the switch state and toggle an LED – With switch denouncing
ORG 7000H
Assembly code
6
.Lst file
.Hex file
:10700000111130B1FB1111D2941111C294111180E0
:06701000EF7932D9FE22E7
:00000001FF
7
EXPERMIMENTS 02: DC MOTOR CONTROL USING PWM SIGNALS
a) Rotate a DC motor at half of its rated speed, assuming a PWM frequency of 1 kHz.
Assembly code
ORG 7000H
MAIN:
SETB 96H ; PWM PIN 1
ACALL DELAY ;DELAY FOR 0.5 MS
CLR 96H ;PWM PIN 0
ACALL DELAY ;SELAY FOR 0.5 MS
SJMP MAIN
DELAY:
MOV R1, #231
DJNZ R1, $
RET
END
.Hex file
:107000007590C01116759060111675903011167537
:107010009090111680EA787879327A0ADAFED9FAF5
:03702000D8F6227D
:00000001FF
Assembly code
ORG 7000H
8
P1_4 BIT 94H ; DC MOTOR PIN 1
P1_5 BIT 95H ; DC MOTOR PIN 2
P1_6 BIT 96H ; PWM PIN / EN PIN
;100% - CW
;75% - CCW
;50% -CCW
9
CLR P1_4 ; MOTOR PIN 1=0
SETB P1_6 ; PWM PIN =1
MOV R0,#2
L2:
ACALL DELAY ; 0.5 MS
DJNZ R0,L2 ; 0.5MS*2=1MS
CLR 96H ;PWM PIN =0
MOV R0,#2
L3:
ACALL DELAY
DJNZ R0,L3 ;0.5MS*2=1MS
DJNZ R3,X5
DJNZ R2,X6
;25% - CW
.Lst file
_SAMT2B
PAGE 1
10
0095 4 P1_5 BIT 95H ; DC MOTOR PIN 2
0096 5 P1_6 BIT 96H ; PWM PIN / EN PIN
6
7
8 ;100% - CW
9
10
7000 7AFA 11 MOV R2,#250 ; FOR 5S = 250*40*0.5MS
7002 12 X2:
7002 7B28 13 MOV R3,#40
7004 14 X1:
7004 D294 15 SETB 94H ;MOTOR PIN 1 = 1
7006 C295 16 CLR 95H ;MOTOR PIN 2 = 0
7008 D296 17 SETB 96H ;PWM PIN =1
700A 115C 18 ACALL DELAY ; DELAY FOR 0.5MS
700C DBF6 19 DJNZ R3,X1
700E DAF2 20 DJNZ R2,X2
21
22 ;75% - CCW
23
7010 7AFA 24 MOV R2,#250 ; FOR 5S = 250*40*2MS
7012 25 X4:
7012 7B0A 26 MOV R3,#10
7014 27 X3:
7014 D295 28 SETB 95H ; MOTOR PIN 2=1
7016 C294 29 CLR 94H ; MOTOR PIN 1=0
7018 D296 30 SETB 96H ; PWM PIN =1
701A 7803 31 MOV R0,#3
701C 32 L1:
701C 115C 33 ACALL DELAY ; 0.5MS DELAY
701E D8FC 34 DJNZ R0,L1 ; 0.5*3 = 1.5MS FOR ON TIME
7020 C296 35 CLR 96H
7022 115C 36 ACALL DELAY ; 0.5 DELAY FOR OFF TIME
7024 DBEE 37 DJNZ R3,X3
7026 DAEA 38 DJNZ R2,X4
39
40 ;50% -CCW
41
7028 7AFA 42 MOV R2,#250 ; FOR 5S = 250*40*2MS
702A 43 X6:
702A 7B0A 44 MOV R3,#10
702C 45 X5:
702C D295 46 SETB 95H ; MOTOR PIN 2=1
702E C294 47 CLR 94H ; MOTOR PIN 1=0
7030 D296 48 SETB 96H ; PWM PIN =1
7032 7802 49 MOV R0,#2
7034 50 L2:
7034 115C 51 ACALL DELAY ; 0.5 MS
7036 D8FC 52 DJNZ R0,L2 ; 0.5MS*2=1MS
7038 C296 53 CLR 96H ;PWM PIN =0
703A 7802 54 MOV R0,#2
703C 55 L3:
703C 115C 56 ACALL DELAY
703E D8FC 57 DJNZ R0,L3 ;0.5MS*2=1MS
7040 DBEA 58 DJNZ R3,X5
_SAMT2B
PAGE 2
11
7046 64 X8:
7046 7B0A 65 MOV R3,#10
7048 66 X7:
7048 C295 67 CLR 95H ; MOTOR PIN 2=0
704A D294 68 SETB 94H ; MOTOR PIN 1=1
704C D296 69 SETB 96H ; PWM = 1
704E 115C 70 ACALL DELAY ; 0.5MS
7050 C296 71 CLR 96H ; PWM PIN =0
7052 7803 72 MOV R0,#3
7054 73 L4:
7054 115C 74 ACALL DELAY ; DELAY 0.5MS
7056 D8FC 75 DJNZ R0,L4 ; 0.5MS*3=1.5MS
7058 DBEE 76 DJNZ R3,X7
705A DAEA 77 DJNZ R2,X8
78
79
705C 80 DELAY: ; DELAY FOR 0.5 MS
705C 79E7 81 MOV R1,#231
705E D9FE 82 DJNZ R1,$
83
7060 22 84 RET
85
86 END
.Hex File
:107000007AFA7B28D294C295D296115CDBF6DAF23A
:107010007AFA7B0AD295C294D2967803115CD8FC96
:10702000C296115CDBEEDAEA7AFA7B0AD295C29458
:10703000D2967802115CD8FCC2967802115CD8FC1A
:10704000DBEADAE67AFA7B0AC295D294D296115C30
:10705000C2967803115CD8FCDBEEDAEA79E7D9FE58
:01706000220D
:00000001FF
12
EXPERMIMENTS 03: 4 WIRE STEPPER MOTOR PARALLEL PORT CONTROLLING
Assembly code
ORG 7000H
P1 DATA 90H
DELAY:
MOV R1,#250
MOV R2,#250
MOV R3,#250
DJNZ R1,$
DJNZ R2, $-2
DJNZ R3,$-4
RET
END
.Lst File
7000 1 ORG 7000H
2
0090 3 P1 DATA 90H
4
7000 7466 5 MOV A,#01100110B ; MOVE SEQUENCE TO
ACCU
7002 6 MAIN:
7002 F590 7 MOV P1,A ; MOV CONTENT OF A TO
P1
7004 03 8 RR A ; ROTATE THE SEQUNCE
TO RIGHT
7005 1109 9 ACALL DELAY ; DELAY 0.5MS
7007 80F9 10 SJMP MAIN
11
12
7009 13 DELAY:
14
7009 79FA 15 MOV R1,#250
13
700B 7AFA 16 MOV R2,#250
700D 7BFA 17 MOV R3,#250
700F D9FE 18 DJNZ R1,$
7011 DAFC 19 DJNZ R2, $-2
7013 DBFA 20 DJNZ R3,$-4
7015 22 21 RET
22
23 END
.Hex File
:107000007466F59003110980F979FA7AFA7BFAD956
:06701000FEDAFCDBFA22AF
:00000001FF
Assembly code
ORG 7000H
P1 DATA 90H
L1:
14
MOV A,#01100000B ; MOVE SEQ TO THE ACC
MOV P1,A ; MOVE THE CONETNT IN ACC TO P1
ACALL DELAY
SJMP L1
END
.Lst File
7000 1 ORG 7000H
2
0090 3 P1 DATA 90H
4
7000 5 L1:
6
7000 7480 7 MOV A,#10000000B ; MOVE SEQ TO THE ACC
7002 F590 8 MOV P1,A ; MOVE THE CONETNT IN
ACC TO P1
7004 1132 9 ACALL DELAY
10
11
15
7006 74C0 12 MOV A,#11000000B ; MOVE SEQ TO THE ACC
7008 F590 13 MOV P1,A ; MOVE THE CONETNT IN
ACC TO P1
700A 1132 14 ACALL DELAY
15
16
700C 7440 17 MOV A,#01000000B ; MOVE SEQ TO THE ACC
700E F590 18 MOV P1,A ; MOVE THE CONETNT IN
ACC TO P1
7010 1132 19 ACALL DELAY
20
21
7012 7460 22 MOV A,#01100000B ; MOVE SEQ TO THE ACC
7014 F590 23 MOV P1,A ; MOVE THE CONETNT IN
ACC TO P1
7016 1132 24 ACALL DELAY
25
26
7018 7420 27 MOV A,#00100000B ; MOVE SEQ TO THE ACC
701A F590 28 MOV P1,A ; MOVE THE CONETNT IN
ACC TO P1
701C 1132 29 ACALL DELAY
30
31
701E 7430 32 MOV A,#00110000B ; MOVE SEQ TO THE ACC
7020 F590 33 MOV P1,A ; MOVE THE CONETNT IN
ACC TO P1
7022 1132 34 ACALL DELAY
35
36
7024 7410 37 MOV A,#00010000B ; MOVE SEQ TO THE ACC
7026 F590 38 MOV P1,A ; MOVE THE CONETNT IN
ACC TO P1
7028 1132 39 ACALL DELAY
40
41
702A 7490 42 MOV A,#10010000B ; MOVE SEQ TO THE ACC
702C F590 43 MOV P1,A ; MOVE THE CONETNT IN
ACC TO P1
702E 1132 44 ACALL DELAY
45
7030 80CE 46 SJMP L1
47
48
7032 49 DELAY: ; DELAY FOR 0.5 MS
7032 79E7 50 MOV R1,#231
7034 D9FE 51 DJNZ R1,$
7036 22 52 RET
53
54 END
16
.Hex file
:107000007480F590113274C0F59011327440F5908F
:1070100011327460F59011327420F5901132743091
:10702000F59011327410F59011327490F590113280
:0770300080CE79E7D9FE22B2
:00000001FF
c) write an alp to rotate a stepper motor one cycle clockwise (cw) and one cycle
counterclockwise (ccw) using the full step method. the process must be repeated
continuously.
Assembly code
ORG 7000H
P1 DATA 90H
MAIN:
MOV R0,#4
MOV A,#01100110B ; MOVE SEQUENCE TO ACCU
L1:
MOV P1,A ; MOV CONTENT OF A TO P1
RR A ; ROTATE THE SEQUNCE TO RIGHT
ACALL DELAY ; DELAY 0.5MS
DJNZ R0,L1
MOV R0,#4
MOV A,#01100110B
L2: ;
MOV P1,A
RL A ;ROTATE THE SEQ TO LEFT
ACALL DELAY
DJNZ R0,L2
SJMP MAIN
END
17
.Lst File
.Hex File
:1070000078047466F590031118D8F978047466F55D
:0D70100090231118D8F980E879E7D9FE2205
:00000001FF
18
d) Rotate 120 degrees in cw and ccw directions, then repeat the process.
Assembly code
ORG 7000H
P1 DATA 90H
;CW
MOV R1,#15 ;
L2:
MOV R0,#4
MOV A,#01100110B ; MOVE SEQUENCE TO ACCU
L1:
MOV P1,A ; MOV CONTENT OF A TO P1
RR A ; ROTATE THE SEQUNCE TO RIGHT
ACALL DELAY ; DELAY 0.5MS
DJNZ R0,L1 ; LOOP THE PROCESS 4 TIMES TO COMPLE CYCLE
DJNZ R1,L2 ; LOOP 15 TIMES FOR COMPLETE 16 CYCLES
;CCW
MOV R1,#15
L4:
MOV R0,#4
MOV A,#01100110B ; MOVE SEQUENCE TO ACCUMULATOR
L3:
MOV P1,A
RL A ;ROTATE THE SEQ TO LEFT
19
ACALL DELAY ; O.5MS DELAY
DJNZ R0,L3 ; LOOP 4 TIMES
DJNZ R1,L4 ; LOOP 15 TIMES
END
.Lst File
7000 1 ORG 7000H
2
0090 3 P1 DATA 90H
4
7000 5 MAIN: ; MAIN PROGRAM
6
7 ;CW
8
7000 790F 9 MOV R1,#15 ;
7002 10 L2:
7002 7804 11 MOV R0,#4
7004 7466 12 MOV A,#01100110B ; MOVE SEQUENCE TO
ACCU
7006 13 L1:
7006 F590 14 MOV P1,A ; MOV CONTENT OF A TO
P1
7008 03 15 RR A ; ROTATE THE SEQUNCE
TO RIGHT
7009 1144 16 ACALL DELAY ; DELAY 0.5MS
700B D8F9 17 DJNZ R0,L1 ; LOOP THE PROCESS 4
TIMES TO COMPLE CYCLE
20
700D D9F3 18 DJNZ R1,L2 ; LOOP 15 TIMES FOR
COMPLETE 16 CYCLES
19
700F 7490 20 MOV A,#10010000B ; EXTRA STEP 1
7011 F590 21 MOV P1,A
7013 1144 22 ACALL DELAY
23
7015 7460 24 MOV A,#01100000B ; EXTRA STEP 2
7017 F590 25 MOV P1,A
7019 1144 26 ACALL DELAY
27
701B 7490 28 MOV A,#10010000B ; EXTRA STEP 3
701D F590 29 MOV P1,A
701F 1144 30 ACALL DELAY
31
32 ;CCW
33
7021 790F 34 MOV R1,#15
7023 35 L4:
7023 7804 36 MOV R0,#4
7025 7466 37 MOV A,#01100110B ; MOVE SEQUENCE TO
ACCUMULATOR
7027 38 L3:
7027 F590 39 MOV P1,A
7029 23 40 RL A ;ROTATE THE SEQ TO
LEFT
702A 1144 41 ACALL DELAY ; O.5MS DELAY
702C D8F9 42 DJNZ R0,L3 ; LOOP 4 TIMES
702E D9F3 43 DJNZ R1,L4 ; LOOP 15 TIMES
44
7030 7430 45 MOV A,#00110000B ; EXTRA STEP 1
7032 F590 46 MOV P1,A
7034 1144 47 ACALL DELAY
48
7036 7460 49 MOV A,#01100000B ; EXTRA STEP 2
7038 F590 50 MOV P1,A
703A 1144 51 ACALL DELAY
52
703C 74C0 53 MOV A,#11000000B ; EXTRA STEP 3
703E F590 54 MOV P1,A
7040 1144 55 ACALL DELAY
56
57
7042 80BC 58 SJMP MAIN ; return to main
program
_SAM3TD
PAGE 2
59
60
7044 61 DELAY: ; DELAY FOR 0.5 MS
7044 79E7 62 MOV R1,#231
7046 D9FE 63 DJNZ R1,$
7048 22 64 RET
65
66 END
21
L2 . . . . . . . . . . . . . . . C ADDR 7002H
L3 . . . . . . . . . . . . . . . C ADDR 7027H
L4 . . . . . . . . . . . . . . . C ADDR 7023H
MAIN . . . . . . . . . . . . . . C ADDR 7000H
P1 . . . . . . . . . . . . . . . D ADDR 0090H
.Hex File
:10700000790F78047466F590031144D8F9D9F374B4
:1070100090F59011447460F59011447490F59011BE
:1070200044790F78047466F590231144D8F9D9F3A4
:107030007430F59011447460F590114474C0F5906B
:09704000114480BC79E7D9FE225D
:00000001FF
Assembly code
ORG 7000H
MOV A,#83
ACALL L1
MOV A,#65
ACALL L1
MOV A,#77
ACALL L1
MOV A,#65
ACALL L1
MOV A,#68
ACALL L1
MOV A,#72
ACALL L1
MOV A,#73
ACALL L1
L1:
CLR 90H
MOV DPTR,#0FFF3H
MOVX @DPTR,A
22
MOV R0,#0
DJNZ R0,$
DJNZ R0,$
CLR 91H
SETB 91H
RET
END
.Lst file
L1 . . . . . . . . . . . . . . . C ADDR 701CH
.Hex File
:107000007453111C7441111C744D111C7441111CDA
:107010007444111C7448111C7449111CC29090FFD7
:0D702000F3F07800D8FED8FEC291D2912284
23
:00000001FF
b) Connect a push button (S1) to the T0 pin (P3.4) and utilize the 8051 counters to count 10
pulses. Display the counting value on the LCD.
Assembly code
ORG 7000H
BACK:
MOV R1,#49
ADD A,R1
SJMP BACK
24
DJNZ R0,$
DJNZ R0,$
CLR 91H
SETB 91H
RET
END
.Lst FIle
7000 1 ORG 7000H
2
0089 3 TMOD DATA 89H
00B4 4 P3_4 BIT 0B4H
008C 5 TH0 DATA 8CH
008C 6 TR0 BIT 8CH
008A 7 TL0 DATA 8AH
008D 8 TF0 BIT 8DH
9
10
11
7000 758906 12 MOV TMOD,#00000110B ; CONFIGURE TMOD
REGISTOR FOR COUNNTER 0 - MODE 2
13
7003 D2B4 14 SETB P3_4 ; P3.4 =1 TO MAKE IT
INPUT
15
16
7005 17 BACK:
18
7005 758C00 19 MOV TH0,#0 ; INITIAL VALUE TO TH0
= 0
20
7008 D28C 21 SETB TR0 ; TR0 =1 TO START THE
COUNTER
22
700A 7931 23 MOV R1,#49
24
700C 25 MAIN: ; MOV ASCII CODE OF 1 TO R1
26
700C E58A 27 MOV A,TL0 ; COPY THE VALUE IN
TL0 TO ACCUMULATOR
28
700E 29 29 ADD A,R1
30
700F B40BFA 31 CJNE A,#11,MAIN ; GO TO BACK IF THE
VALUE IN ACCU=11 IF NOT CALL DISPLAY SUB.
32
7012 1116 33 ACALL L1 ; CALL DISPLAY
SUBROUTINE
34
7014 80EF 35 SJMP BACK
36
37
7016 38 L1: ; DISPLAY SUB ROUTINE
7016 C290 39 CLR 90H
7018 90FFF3 40 MOV DPTR,#0FFF3H
701B F0 41 MOVX @DPTR,A
701C 7800 42 MOV R0,#0
25
701E D8FE 43 DJNZ R0,$
7020 D8FE 44 DJNZ R0,$
7022 C291 45 CLR 91H
7024 D291 46 SETB 91H
7026 22 47 RET
48
49 END
c) Interface push button (S2) to INT0 pin (P3.2). Create ALP to reset the counting value (in part
b) once you press the S2.
Assembly code
IE DATA 0A8H
ORG 4003H
CLR TF0
CLR TR0 ; INTTERUPT SERVICE ROUTINE BEGIN
LJMP L1 ; JUMP TO L1 TO RESET THE LED AND COUNTER
26
MOV TMOD,#00000110B ; CONFIGURE TMOD REGISTOR FOR COUNNTER 0 -
MODE 2
SETB TCON_0 ; TCON REGINTER 0 BIT = 1 FOR EDGE TRIGGER
L1:
CLR P1_7 ; OFF LED TO START COUNTING
SETB TR0 ; COUNTER START
X1:
MOV A,TL0 ; COPY THE VALUE IN TL0 TO ACCUMULATOR
L2:
SJMP L1
DELAY:
MOV R1,#231
DJNZ R1,$
RET
END
.Lst File
1
2
0089 3 TMOD DATA 89H ;
008C 4 TH0 DATA 8CH ;
008C 5 TR0 BIT 8CH
008A 6 TL0 DATA 8AH
008D 7 TF0 BIT 8DH
0097 8 P1_7 BIT 97H
0088 9 TCON_0 BIT 88H
10
00A8 11 IE DATA 0A8H
12
13
27
00B4 14 P3_4 BIT 0B4H ; PUSH BUTTON FOR
COUNTER
00B1 15 P3_2 BIT 0B1H ; PUSH BUTTON FOR
INTTERUPT - INT0
16
17
4003 18 ORG 4003H
4003 C28D 19 CLR TF0
4005 C28C 20 CLR TR0 ; INTTERUPT SERVICE ROUTINE
BEGIN
4007 02703B 21 LJMP L1 ; JUMP TO L1 TO RESET
THE LED AND COUNTER
22
23
24
7030 25 ORG 7030H ; MAIN PROGRAM STARTS
26
27
28
7030 758906 29 MOV TMOD,#00000110B ; CONFIGURE TMOD
REGISTOR FOR COUNNTER 0 - MODE 2
7033 D288 30 SETB TCON_0 ; TCON REGINTER 0 BIT
= 1 FOR EDGE TRIGGER
31
7035 75A881 32 MOV IE,#10000001B ; CONFIGURE INTERRUPT
ENABLE REGISTER FOR EXTERNAL INT. 0
33
7038 758CFA 34 MOV TH0,#250 ; MOVE CONTER THE
STARTING VALUE
35
703B 36 L1:
703B C297 37 CLR P1_7 ; OFF LED TO START
COUNTING
703D D28C 38 SETB TR0 ; COUNTER START
39
703F 40 X1:
703F E58A 41 MOV A,TL0 ; COPY THE VALUE IN
TL0 TO ACCUMULATOR
42
7041 B405FB 43 CJNE A,#5,X1 ; GO TO BACK IF THE
VALUE IN ACCU=11 IF NOT CALL DISPLAY SUB.
44
7044 D297 45 SETB P1_7 ; LED ON
46
7046 47 L2:
48
7046 C28D 49 CLR TF0 ; CLEAR TF0
7048 C28C 50 CLR TR0 ; CLEAR TR0
51
704A 80EF 52 SJMP L1
53
704C 54 DELAY:
704C 79E7 55 MOV R1,#231
704E D9FE 56 DJNZ R1,$
7050 22 57 RET
58
_S4C
PAGE 2
59 END
60
28
_S4C
PAGE 3
.Hex file
:07400300C28DC28C02703B6C
:10703000758906D28875A881758CFAC297D28CE5BD
:107040008AB405FBD297C28DC28C80EF79E7D9FE56
:01705000221D
:00000001FF
d) By using part a,b,c and previous task (task 2) knowledge Design a system with the following
specifications:
• Interface a push button (S1) to the microcontroller. When S1 is pressed 10 times (counts), the
stepper motor should rotate counterclockwise (CCW). If the button is pressed less than 10
times, the stepper motor should rotate clockwise (CW).
• The count value should be displayed on an LCD display while counting is in progress. When
the count reaches 11, the counter should reset, and the stepper motor should start rotating
clockwise (CW).
• Interface another push button (S2) to the microcontroller. Pressing S2 should immediately
stop the stepper motor's rotation.
• To initiate the system, interface a push button (S3) to pin P1.7. Pressing S3 should start the
entire process.
Assembly code
P1 DATA 90H
P3_4 BIT 0B4H ; PUSH BUTTON FOR COUNTER
P3_2 BIT 0B1H ; PUSH BUTTON FOR INTTERUPT - INT0
P1_7 BIT 97H ;PUSH BUTTON FOR REST PROGRAM
IE BIT 0A8H
29
TL0 DATA 8AH
TF0 BIT 8DH
TCON_0 BIT 88H
ORG 7000H
JNB P1_7,$
LABEL1: ; TO START THE PROCESS IF PUSH BUTTON 3 =1
ACALL MOTOR_CW
MOV A,TL0
ADD A,R1
ACALL DISPLAY
ACALL MOTOR_CCW
ACALL DELAY
AGAIN:
MOV A,TL0
ADD A,R1
30
CJNE A,#11,AGAIN ;CHECK AGAIN THE COUNT IF = 11 COUNTER RESET AND
MOTOR ROTATE CW
CLR TR0
MOV TH0,#0
ACALL MOTOR_CW
MOTOR_CW:
;CW
MOV R0,#4
MOV A,#01100110B ; MOVE SEQUENCE TO ACCU
L1:
MOV P1,A ; MOV CONTENT OF A TO P1
RR A ; ROTATE THE SEQUNCE TO RIGHT
ACALL DELAY ; DELAY 0.5MS
DJNZ R0,L1 ; LOOP 4 TIMES TO COMPLETE A CYCLE
RET
MOTOR_CCW:
;CCW
MOV R0,#4
MOV A,#01100110B ; MOVE SEQ TO ACCUMULATOR
L2: ;
MOV P1,A
RL A ;ROTATE THE SEQ TO LEFT
ACALL DELAY ; 0.5 MS DELAY
DJNZ R0,L2 ; LOOP 4 TIMES TO COMPLETE A CYCLE
RET
DELAY:
MOV R2,#250
MOV R1,#250
DJNZ R2,$
DJNZ R1,$-2
RET
31
CLR 91H
SETB 91H
RET
END
.Lst file
1
0090 2 P1 DATA 90H
00B4 3 P3_4 BIT 0B4H ; PUSH BUTTON FOR
COUNTER
00B1 4 P3_2 BIT 0B1H ; PUSH BUTTON FOR
INTTERUPT - INT0
0097 5 P1_7 BIT 97H ;PUSH BUTTON FOR REST
PROGRAM
00A8 6 IE BIT 0A8H
7
8
0089 9 TMOD DATA 89H
008C 10 TH0 DATA 8CH
008C 11 TR0 BIT 8CH
008A 12 TL0 DATA 8AH
008D 13 TF0 BIT 8DH
0088 14 TCON_0 BIT 88H
15
16
4003 17 ORG 4003H ; INT. SERVICE ROUTINE
4003 759000 18 MOV P1,#0 ; PORT 0 GOES ZERO TO
STOP THE MOTOR
19
20
7000 21 ORG 7000H
22
7000 3097FD 23 JNB P1_7,$
7003 24 LABEL1: ; TO START THE PROCESS IF PUSH
BUTTON 3 =1
25
7003 112E 26 ACALL MOTOR_CW
27
7005 758906 28 MOV TMOD,#00000110B ; CONFIGURE TMOD
REGISTOR FOR COUNNTER 0 - MODE 2
7008 D288 29 SETB TCON_0 ; TCON REGINTER 0 BIT
= 1 FOR EDGE TRIGGER
30
700A 92A8 31 MOV IE,#10000001B ; CONFIGURE INTERRUPT
ENABLE REGISTER FOR EXTERNAL INT.0
****--------------------------------^
****ERROR #20: Illegal operand
32
700C D2B4 33 SETB P3_4 ; INPUT
34
700E 758C00 35 MOV TH0,#0 ; STARTING VALUE FOR
THE COUNTER
36
7011 D28C 37 SETB TR0 ; START THE COUNTER
38
7013 7931 39 MOV R1,#49 ; FOR THE ACII CODE
40
7015 E58A 41 MOV A,TL0
42
32
7017 29 43 ADD A,R1
44
7018 114F 45 ACALL DISPLAY
46
701A B40AE6 47 CJNE A,#10,LABEL1 ; IF COUNT < 10 MOTOR-
CW AND IF COUNT = 10 -MOTOR CCW
48
701D 113A 49 ACALL MOTOR_CCW
50
701F 1146 51 ACALL DELAY
52
7021 53 AGAIN:
7021 E58A 54 MOV A,TL0
7023 29 55 ADD A,R1
7024 B40BFA 56 CJNE A,#11,AGAIN ;CHECK AGAIN THE COUNT IF =
11 COUNTER RESET AND MOTOR ROTATE CW
_S4D
PAGE 2
33
704E 22 94 RET
95
704F 96 DISPLAY: ; DISPLAY SUB
ROUTINE
704F C290 97 CLR 90H
7051 90FFF3 98 MOV DPTR,#0FFF3H
7054 F0 99 MOVX @DPTR,A
7055 7800 100 MOV R0,#0
7057 D8FE 101 DJNZ R0,$
7059 D8FE 102 DJNZ R0,$
705B C291 103 CLR 91H
705D D291 104 SETB 91H
705F 22 105 RET
106
107 END
ERROR SUMMARY:
Line #31, ERROR #20: Illegal operand
_S4D
PAGE 3
.Hex File
:03400300759000B5
:107000003097FD112E758906D28892A8D2B4758C5E
:1070100000D28C7931E58A29114FB40AE6113A1170
:1070200046E58A29B40BFAC28C758C00112E7804BF
:107030007466F590031146D8F92278047466F590C9
:10704000231146D8F9227AFA79FADAFED9FC22C25B
:107050009090FFF3F07800D8FED8FEC291D2912232
:00000001FF
34
RESULTS
35
DISCUSSION
This lab session was focused on interfacing the 8051 microcontroller with push buttons,
motors, LCD display and understanding the practical usage of microcontroller operations like
counters, interrupts, and LCD sub routines etc.
In the first experiment, the switch bounces effect that occurs when using mechanical switches
in a circuit was observed and denouncing using software techniques was tried. Clear and
successful observations were obtained and debouching using writing a delay in the program
after the switching part was also successful.
In the second experiment, DC motor control using 8051 microcontroller was observed but
due to the technical issues and malfunctions of the AES-51 controller board, the motors
rotation was not clearly observed.
The next practical was focused on the stepper motor controlling using both full and half step
methods and in the motor rotation was not observed in this experiment also. But, by
observing the LEDs which are connected to the I/O pins powering up sequence of the stepper
motor windings was observed.
In the last experiment, all the parts learned from the above experiments were used to
implement a system which is controlled by three push buttons and motor rotations as the
outputs. As the motor rotation was hard to observed due to the issues in the board, a LED is
used to observes the output.
36