-
Notifications
You must be signed in to change notification settings - Fork 0
/
Project.asm
146 lines (136 loc) · 3.08 KB
/
Project.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
ORG 0000h
LJMP START
ORG 0100h
START: NOP
RS EQU P3.2
RW EQU P3.3
EN EQU P3.4
Dat EQU P2
CLR EN
ACALL INITDISP
MOV R1, #'P'
ACALL DISPCHAR
MOV R1, #'U'
ACALL DISPCHAR
MOV R1, #'T'
ACALL DISPCHAR
MOV R1, #' '
ACALL DISPCHAR
MOV R1, #'Y'
ACALL DISPCHAR
MOV R1, #'O'
ACALL DISPCHAR
MOV R1, #'U'
ACALL DISPCHAR
MOV R1, #'R'
ACALL DISPCHAR
MOV R1, #' '
ACALL DISPCHAR
MOV R1, #'H'
ACALL DISPCHAR
MOV R1, #'A'
ACALL DISPCHAR
MOV R1, #'N'
ACALL DISPCHAR
MOV R1, #'D'
ACALL DISPCHAR
CHECK:
MOV A, P1 ; Read the input from port P1
JZ MOTOR_ON ; If any bit in P1 is 0, turn on the motor
ACALL MOTOR_OFF ; If any bit in P1 is 1, turn off the motor
MOTOR_ON:
SETB P0.0 ; Set terminal 1 to high
CLR P0.1 ; Clear terminal 12 to low
SETB P0.2 ; Set enable terminal to high
ACALL INITDISP
MOV R1, #'T'
ACALL DISPCHAR
MOV R1, #'A'
ACALL DISPCHAR
MOV R1, #'P'
ACALL DISPCHAR
MOV R1, #' '
ACALL DISPCHAR
MOV R1, #'I'
ACALL DISPCHAR
MOV R1, #'S'
ACALL DISPCHAR
MOV R1, #' '
ACALL DISPCHAR
MOV R1, #'O'
ACALL DISPCHAR
MOV R1, #'N'
ACALL DISPCHAR
ACALL DELAY_1S ; Run the motor for 1 second (adjust as needed)
MOV P0, #0; Disable the motor
;ACALL INITDISP
JMP CHECK ; Run the motor continuously
MOTOR_OFF:
MOV P0, #0 ; Disable the motor
JMP START ; Run the motor continuously
; LCD initialize (to line 1)
INITDISP: NOP
MOV R1, #38H ; 00111000
ACALL SENDCMD
MOV R1, #0EH ; 0000 1110
ACALL SENDCMD
MOV R1, #06H ; 0000 0110
ACALL SENDCMD
MOV R1, #01H ; 0000 0001
ACALL SENDCMD
MOV R1, #80H ; 1000 0000
ACALL SENDCMD
RET
; Useful subroutines...
DISPCHAR: ACALL DELAY_50MS ; BusyCheck ; The letter to be displayed should
be placed in R1
SETB EN
SETB RS
CLR RW
MOV Dat, R1
ACALL CLEAREN
RET
SENDCMD: ACALL DELAY_50MS ; BusyCheck ; The letter to be displayed should
be placed in R1
SETB EN
CLR RS
CLR RW
MOV Dat, R1
ACALL CLEAREN
RET
BUSYCHECK: CLR RS
SETB RW
JBC Dat.7, BUSYCHECK
RET
CLEAREN: ACALL DELAY_50MS
CLR EN
RET
DELAY: NOP
RET
DELAY_CJNE: INC R0
MOV 51H, @R0
MOV R2, #00H
LOOP_H: MOV A, #00H
LOOP_L: INC A
CJNE A, #0FFH, LOOP_L
INC R2
MOV A, R2
CJNE A, 51H, LOOP_H
DEC R0
MOV 51H, @R0
MOV A, #00H
LAST_LOOP: INC A
CJNE A, 51H, LAST_LOOP
RET
DELAY_50MS: MOV R0, #40H
MOV @R0, #012H
INC R0
MOV @R0, #058H
DEC R0
ACALL DELAY_CJNE
RET
DELAY_1S: MOV 60H, #14H
LOOP: ACALL DELAY_50MS
DJNZ 60H, LOOP
RET
END