-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfinalcode.asm
309 lines (252 loc) · 5.06 KB
/
finalcode.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
.MODEL TINY
.DATA
;8253 USED TO GENERATE CLOCK FOR ADC
CNT0 EQU 20H
CREG EQU 26H
;8255(1) INITIALISE
PORT1A EQU 00H ;CONTROLLING THE LCD
PORT1B EQU 02H ;INPUT TO LCD
PORT1C EQU 04H ;UPPER - ROW
;LOWER - COLUMN
CREG1 EQU 06H
;8255(2) USED FOR ADC, ALARM
PORT2A EQU 10H ;INPUT TO DI DEVICE
PORT2B EQU 12H ;ADC
PORT2C EQU 14H ;PC1 - SOC OF ADC
;PC2 - ALARM
;PC3 - ADD A OF ADC (USED FOR SELECTING THE ;FIRST INPUT CHANNEL OF ADC)
;PC5 - EOC OF ADC
CREG2 EQU 16H
DAT2 DB 3 DUP(" ");
.CODE
.STARTUP
MOV AL,00010110B ;INITIALIZING 8253
OUT CREG,AL
MOV AL,5
OUT CNT0,AL
MOV AL,10001000B ;INITIALIZING 8255(1)
OUT CREG1,AL
CALL DELAY_2MS
MOV AL,10001010B ;INITIALIZING 8255(2)
OUT CREG2,AL
CALL DELAY_2MS
;check for switch --if closed. then proceed otherwise wait
KX1: IN AL,PORT1C
AND AL,80H
CMP AL,80H
JNZ KX1
;MOV AL,20H ;
;OUT PORT2A, AL
MOV AL,06H ;GIVE ADC
OUT CREG2,AL ;configured 8255-2 in bsr mode and set pc3 to 0
;check-----------------------------------
MOV AL,00H ;SET ALE' to 0
OUT CREG2,AL
MOV AL,02H ;GIVE SOC' to 0
OUT CREG2,AL
MOV AL,01H
OUT CREG2,AL
MOV AL,03H
OUT CREG2,AL
MOV AL,02H ;GIVE SOC
OUT CREG2,AL
MOV AL,00H ;GIVE ALE
OUT CREG2,AL
;-----------------------------------------
;POLLING FOR EOC
LOOP2:
IN AL,PORT2C
CALL DELAY_2MS
AND AL,20H ;MASKING FOR EOC-PC5
CMP AL,20H ;CHECK FOR EOC
JNZ LOOP2
MOV AL,10001010B ;INITIALIZING 8255(2)
OUT CREG2,AL
IN AL,PORT2B ; Al contains the voltage value at an end of 2200 ohm resistor
;NOTE that ADC gives us the integer x as output if the read voltage is x * least count
;least count here is (5-0)/256 = 19.5312
NOT AL ;To get the voltage drop we subtract Al from 256 (equivalent to doing NOT AL)
;AL HAS THE VOLTAGE DROP ACROSS THE RESISTOR
MOV BL,AL
;--------------------------------------------------------------------------------
MOV AL,07H ;GIVE ADC
OUT CREG2,AL ;configured 8255-2 in bsr mode and set pc3 to 1
;check-----------------------------------
MOV AL,00H ;SET ALE' to 0
OUT CREG2,AL
MOV AL,02H ;GIVE SOC' to 0
OUT CREG2,AL
MOV AL,01H
OUT CREG2,AL
MOV AL,03H
OUT CREG2,AL
MOV AL,02H ;GIVE SOC
OUT CREG2,AL
MOV AL,00H ;GIVE ALE
OUT CREG2,AL
;-----------------------------------------
;POLLING FOR EOC
LOOP2_:
IN AL,PORT2C
CALL DELAY_2MS
AND AL,20H ;MASKING FOR EOC-PC5
CMP AL,20H ;CHECK FOR EOC
JNZ LOOP2_
MOV AL,10001010B ;INITIALIZING 8255(2)
OUT CREG2,AL
IN AL,PORT2B ; Al contains the voltage value at an end of 2200 ohm resistor
;NOTE that ADC gives us the integer x as output if the read voltage is x * least count
;least count here is (5-0)/256 = 19.5312
; ------------------------------------------------------------------------------------
CALL HFE
CALL FUNC
CALL ALARM
.EXIT
ALARM PROC NEAR
CMP AL,50
JNB Z2
MOV AL,05H
OUT CREG2,AL
CALL DELAY_2S
MOV AL,04H
OUT CREG2,AL
Z2: RET
ALARM ENDP
HFE PROC NEAR USES CX DX ; hfe is AL * 19.5312 *10^-3/ (2200 * 0.1*10^-4) which is approx. AL * 39/44
; CH*50/(CL*11)
MOV CH,BL
PUSH BX
MOV CL,AL
MOV AL,CH
MOV DL,50D
MUL DL
MOV BH,0
MOV BL, CL
MOV DL,00H
MOV DH,00H
DIV BX
MOV DL,00H
MOV DH,00H
MOV BX,11D
DIV BX
POP BX
RET
HFE ENDP
; ----------FUNC DEF----------------
FUNC PROC NEAR
PUSH AX
MOV AL,38H
CALL COMNDWRT
CALL DELAY
CALL DELAY
CALL DELAY
MOV AL,0EH
CALL COMNDWRT
MOV AL, 01 ;CLEAR LCD
CALL COMNDWRT
CALL DELAY
CALL DELAY
POP AX
PUSH AX
LEA DI,DAT2
MOV BX,100D
MOV DX,0
DIV BX
ADD AL,30H
CALL DATWRIT ;ISSUE IT TO LCD
CALL DELAY
CALL DELAY
MOV AX,DX
MOV BX,10D
MOV DX,0
DIV BX
ADD AL,30H
CALL DATWRIT
CALL DELAY
CALL DELAY
MOV AX,DX
MOV DX,0
ADD AL,30H
CALL DATWRIT
CALL DELAY
CALL DELAY
POP AX
RET
FUNC ENDP
;--------------END FUNC------------
COMNDWRT PROC ;THIS PROCEDURE WRITES COMMANDS TO LCD
OUT PORT1B, AL ;SEND THE CODE TO PORT A
MOV AL, 00000100B ;RS=0,R/W=0,E=1 FOR H-TO-L PULSE
OUT PORT1A, AL
NOP
NOP
MOV AL, 00000000B ;RS=0,R/W=0,E=0 FOR H-TO-L PULSE
OUT PORT1A, AL
RET
COMNDWRT ENDP
DATWRIT PROC NEAR
PUSH DX ;SAVE DX
MOV DX,PORT1B ;DX=PORT A ADDRESS
OUT DX, AL ;ISSUE THE CHAR TO LCD
MOV AL, 00000101B ;RS=1, R/W=0, E=1 FOR H-TO-L PULSE
MOV DX, PORT1A ;PORT B ADDRESS
OUT DX, AL ;MAKE ENABLE HIGH
MOV AL, 00000001B ;RS=1,R/W=0 AND E=0 FOR H-TO-L PULSE
OUT DX, AL
POP DX
RET
DATWRIT ENDP ;WRITING ON THE LCD ENDS
DELAY_2MS PROC NEAR
MOV CX,100
HER: NOP
LOOP HER
RET
DELAY_2MS ENDP
;DELAY IN THE CIRCUIT HERE THE DELAY OF 20 MILLISECOND IS PRODUCED
DELAY PROC
MOV CX, 1325 ;1325*15.085 USEC = 20 MSEC
W1:
NOP
NOP
NOP
NOP
NOP
LOOP W1
RET
DELAY ENDP
DELAY_2S PROC
MOV CX, 33125D
W2:
NOP
NOP
NOP
NOP
NOP
LOOP W2
MOV CX, 33125D
W3:
NOP
NOP
NOP
NOP
NOP
LOOP W3
MOV CX, 33125D
W4:
NOP
NOP
NOP
NOP
NOP
LOOP W4
MOV CX, 33125D
W5:
NOP
NOP
NOP
NOP
NOP
LOOP W5
RET
DELAY_2S ENDP
END