-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.asm
320 lines (315 loc) · 4.13 KB
/
main.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
khoi_dong:
org 00h
;ro dung de gan data va lenh
mov A,#0ffh
mov P0,#000h
RS BIT P2.5
RW BIT P2.6
E BIT P2.7
DBUS EQU P0
new_digit bit P2.1
new_ans bit P2.2
mov r0, #00h
mov r1, #00h
mov r2, #00h
mov r3, #00h
mov r4, #00h
mov r5, #00h
mov r6, #00h
mov r7, #00h
;==========================
/*KHOI DONG LCD ? */
MOV r0, #38H /*CHON HIEN THI 8 BIT 2 DONG*/
ACALL lcd_command
mov r0, #0fh /* KHOI TAO HIEN THI LCD */
acall lcd_command
mov r0, #80h /* DICH TRO SANG trai */
acall lcd_command
mov r0, #01h /* clear man hinh */
acall lcd_command
mov r5,#0ah ;mac dinh chon Dec
checkkeypad:
mov P1,#0ffh
mov P3, #0ffh
clr P1.0
jb P3.3,next_1
mov r0,#'7'
acall savedigit
acall disp_000
next_1:
jb P3.4,next_2
mov r0,#'8'
acall savedigit
acall disp_000
next_2:
jb P3.5,next_3
mov r0,#'9'
acall savedigit
acall disp_000
next_3:
jb P3.6, next_4
mov r0,#'A'
acall savedigit
acall disp_000
next_4: setb P1.0
clr P1.1
jb P3.3,next_5
mov r0,#'4'
acall savedigit
acall disp_000
next_5:
jb P3.4,next_6
mov r0,#'5'
acall savedigit
acall disp_000
next_6:
jb P3.5,next_7
mov r0,#'6'
acall savedigit
acall disp_000
next_7:
jb P3.6, next_8
mov r0,#'B'
acall savedigit
acall disp_000
next_8: setb P1.1
clr P1.2
jb P3.3,next_9
mov r0,#'1'
acall savedigit
acall disp_000
next_9:
jb P3.4,next_10
mov r0,#'2'
acall savedigit
acall disp_000
next_10:
jb P3.5,next_11
mov r0,#'3'
acall savedigit
acall disp_000
next_11:
jb P3.6, next_12
mov r0,#'C'
acall savedigit
acall disp_000
next_12: setb P1.2
clr P1.3
jb P3.3,next_13
mov r5,#08h ;PHIM OTC
jmp checkkeypad
next_13:
jb P3.4,next_14
mov r5,#10h ;PHIM HEX
jmp checkkeypad
next_14:
jb P3.5,next_15
mov r0,#'0'
acall savedigit
acall disp_000
next_15:
jb P3.6, next_16
mov r0,#'D'
acall savedigit
acall disp_000
next_16:
jb P3.7, next_17
mov r0,#'=' ; dau =
acall line2
acall checkans
next_17:
setb P1.3
clr P1.4
jb P3.3, next_18
mov r5,#02h ;PHIM BIN
jmp checkkeypad
next_18:
jb P3.4, next_19
mov r5,#0ah ; PHIM DEX
jmp checkkeypad
next_19:
jb P3.5, next_20
mov r0,#'F'
acall savedigit
acall disp_000
next_20:
jb P3.6, next_21
mov r0,#'E'
acall savedigit
acall disp_000
next_21:
jb P3.7, long_checkkeypad ;PHIM AC
LJMP khoi_dong
long_checkkeypad: ljmp checkkeypad
checkans:
jb new_ans, trans
setb new_ans
ret
savedigit:
jb new_digit,checkdigit
mov a,r0
acall xuly
mov r1,a
setb new_digit
ret
checkdigit:
mov a,r0
mov b,r5
acall xuly
mov r7,a
mov a,r1
mul ab
add a,r7
mov r1,a
setb new_digit
ret
xuly:
CJNE A,#'0',KT1
jmp so
KT1:
CJNE A,#'1',KT2
jmp so
KT2:
CJNE A,#'2',KT3
jmp so
KT3:
CJNE A,#'3',KT4
jmp so
KT4:
CJNE A,#'4',KT5
jmp so
KT5:
CJNE A,#'5',KT6
jmp so
KT6:
CJNE A,#'6',KT7
jmp so
KT7:
CJNE A,#'7',KT8
jmp so
KT8:
CJNE A,#'8',KT9
jmp so
KT9:
CJNE A,#'9',chu
jmp so
ret
so: subb a,#30h
ret
chu: subb a,#37h
ret
trans:
MOV A,r1
MOV B,r5
MOV r3, #00h
acall oncode
ret
oncode:
div ab
xch a,b
acall xuly_out
mov r0, a
push 0
xch a,b
mov b, r5
inc r3
cjne r3,#08h,oncode
pop 0
acall disp_ans
pop 0
acall disp_ans
pop 0
acall disp_ans
pop 0
acall disp_ans
pop 0
acall disp_ans
pop 0
acall disp_ans
pop 0
acall disp_ans
pop 0
acall disp_ans
ret
xuly_out:
CJNE A,#00h,KTo1
jmp so_o
KTo1:
CJNE A,#01h,KTo2
jmp so_o
KTo2:
CJNE A,#02h,KTo3
jmp so_o
KTo3:
CJNE A,#03h,KTo4
jmp so_o
KTo4:
CJNE A,#04h,KTo5
jmp so_o
KTo5:
CJNE A,#05h,KTo6
jmp so_o
KTo6:
CJNE A,#06h,KTo7
jmp so_o
KTo7:
CJNE A,#07h,KTo8
jmp so_o
KTo8:
CJNE A,#08h,KTo9
jmp so_o
KTo9:
CJNE A,#09h,chu_o
jmp so_o
ret
so_o: add a,#30h
ret
chu_o: add a,#37h
ret
disp_ans:
mov p0,r0
setb RS
setb e
clr e
acall wait_lcd
Ret
disp_000:
Mov P0 ,r0
setb RS
setb e
clr e
acall wait_lcd
sjmp finish
Ret
line2:
mov r0,#0c0H
acall lcd_command
ret
lcd_command:
clr rs
mov dbus, r0 /* NHAN DU LIEU VA LENH */
setb e
clr e
acall wait_lcd /* CHO LCD LAM VIEC */
ret
WAIT_LCD:
mov r6, #10
lap:mov r7, #250
djnz r7,$
djnz r6, lap
ret
Delay:
mov r7,#0ffh
delay1:
mov r6,#0ffh
djnz r6,$
djnz r7,delay1
ret
finish:
jnb P3.3,finish
jnb P3.4,finish
jnb P3.5,finish
jnb P3.6,finish
jnb P3.7,finish
ljmp Checkkeypad
end