-
Notifications
You must be signed in to change notification settings - Fork 0
/
8051car.asm
164 lines (138 loc) · 3.44 KB
/
8051car.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
ORG 0000H
LJMP START
ORG 23H
LJMP SERIAL
ORG 200H
START:
MOV TMOD,#20H ;TIMER 1 MODE 2
MOV TH1,#0FDH ;9600 BAUD RATE
MOV SCON,#50H ;8-BIT,1 STOP,REN ENABLED
MOV IE,#90H ;ENABLING SERIAL INTERRUPT
SETB TR1 ;START TIMER 1
ACALL DELAY1SEC
MOV P1,#00H ;CLEAR P1
MOV R1,#00H ;CLEAR R1
MAIN:JB P3.0,INITIAL_CHECK ;IF INPUT SIGNAL(COMMAND) IS RECEIVED
JMP MAIN ;RETURN TO MAIN TO CHECK SIGNAL
;INITIAL CHECK 38h
;FORWARD 31h
;BACKWARD 32h
;LEFT 33h
;RIGHT 34h
;REVERSE LEFT 35H
;REVERSE RIGHT 36H
;STOP 37h
INITIAL_CHECK:
CJNE R1,#38H,FORWARD_CMD ;IF R1!=38H JUMP TO FORWARD_CMD
MOV P1,#0FH ;BOTH LEFT WHEEL AND RIGHT WHEEL MOTORS CONNECTED TO P1 STAY STILL
MOV DPTR,#STRING8
JMP BACK
FORWARD_CMD:
CJNE R1,#31H,BACKWARD_CMD ;IF R1!=31H JUMP TO BACKWARD_CMD
MOV P1,#05H ;BOTH LEFT WHEEL AND RIGHT WHEEL MOTORS CONNECTED TO P1 ROTATE IN CLOCKWISE DIRECTION(FORWARD)
MOV DPTR,#STRING1
JMP BACK
BACKWARD_CMD:
CJNE R1,#32H,LEFT_CMD ;IF R1!=32H JUMP TO LEFT_CMD
MOV P1,#0AH ;BOTH LEFT WHEEL AND RIGHT WHEEL MOTORS CONNECTED TO P1 ROTATE IN ANTI-CLOCKWISE DIRECTION(BACKWARD)
MOV DPTR,#STRING2
JMP BACK
LEFT_CMD:
CJNE R1,#33H,RIGHT_CMD ;IF R1!=33H JUMP TO RIGHT_CMD
MOV P1,#06H ;LEFT WHEEL MOTOR ROTATES ANTI-CLOCKWISE AND RIGHT WHEEL MOTOR ROTATES IN CLOCKWISE DIRECTION(LEFT)
MOV DPTR,#STRING3
JMP BACK
RIGHT_CMD:
CJNE R1,#34H,R_LEFT_CMD ;IF R1!=34H JUMP TO R_LEFT_CMD
MOV P1,#09H ;RIGHT WHEEL MOTOR ROTATES ANTI-CLOCKWISE AND LEFT WHEEL MOTOR ROTATES IN CLOCKWISE DIRECTION(RIGHT)
MOV DPTR,#STRING4
JMP BACK
R_LEFT_CMD:
CJNE R1,#35H,R_RIGHT_CMD ;IF R1!=35H JUMP TO R_RIGHT_CMD
MOV P1,#08H ;LEFT WHEEL MOTOR STAYS STILL AND RIGHT WHEEL MOTOR ROTATES ANTI-CLOCKWISE(REVERSE LEFT)
MOV DPTR,#STRING5
JMP BACK
R_RIGHT_CMD:
CJNE R1,#36H,STOP_CMD ;IF R1!=36H JUMP TO STOP_CMD
MOV P1,#02H ; RIGHT WHEEL MOTOR STAYS STILL AND LEFT WHEEL MOTOR ROTATES ANTI-CLOCKWISE(REVERSE RIGHT)
MOV DPTR,#STRING6
JMP BACK
STOP_CMD:
CJNE R1,#37H,RETT ;IF R1!=37H JUMP TO MAIN
MOV P1,#00H ;BOTH RIGHT WHEEL AND LEFT WHEEL MOTORS STAY STILL
MOV DPTR,#STRING7
JMP BACK
RETT:
MOV P1,#00H
MOV DPTR,#STRING
JMP BACK
JMP MAIN
SERIAL:
JB RI,RX_SERVICE ;JUMP IF RI IS HIGH
JB TI,TX_SERVICE ;JUMP IF TI IS HIGH
RX_SERVICE:
CLR RI
MOV B,SBUF ;COPY SBUF DATA TO ACCUMULATOR
MOV R1,B ;COPY A TO R1(COMMAND FOR MOVEMENT)
SETB P3.0 ;ON RXD FOR COMMUNICATION
RETI
TX_SERVICE:CLR TI ;CLEAR TI
RETI
DELAY1SEC:
MOV R3,#10
L1:MOV R4,#200
L2:MOV R5,#250
L3:DJNZ R5,L3
DJNZ R4,L2
DJNZ R3,L1
RET
BACK:
MOV A,#38H ;16x2, 8 BIT, 5x7 DOTS
ACALL CMD ;ROUTINE FOR COMMAND WORD
MOV A,#0CH ; LCD ON, CURSOR OFF
ACALL CMD
MOV A,#06H ; SHIFT CURSOR RIGHT
ACALL CMD
MOV A,#01H ;CLEAR DISPLAY
ACALL CMD
MOV A,#80H ;CURSOR LINE 1, POSITION 1
ACALL CMD
STEM:MOV A,#00H
MOVC A,@A+DPTR
JZ EXIT
ACALL DISPLAY
INC DPTR
SJMP STEM
EXIT: JMP MAIN ;RETURN TO MAIN FOR INITIAL_CHECK
CMD:
ACALL DELAY
MOV P2,A
CLR P3.2 ; RS=0
CLR P3.3 ; RW=0
SETB P3.4 ; E=1
CLR P3.4 ; E=0
RET
DISPLAY:
ACALL DELAY
MOV P2,A
SETB P3.2 ; RS=1
CLR P3.3 ; RW=0
SETB P3.4 ; E=1
CLR P3.4 ; E=0
RET
DELAY:
MOV R6,#0FFH
L6:MOV R7,#60
L7:DJNZ R7,L7
DJNZ R6,L6
RET
STRING: DB 'GIVE AN INPUT',0
STRING1: DB 'GO FORWARD',0
STRING2: DB 'GO BACKWARD',0
STRING3:DB 'MOVE LEFT',0
STRING4: DB 'MOVE RIGHT',0
STRING5: DB 'REVERSE LEFT',0
STRING6: DB 'REVERSE RIGHT',0
STRING7: DB 'STOP THERE',0
STRING8: DB 'INITIALIZATION',0
END