-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.asm
195 lines (154 loc) · 3.36 KB
/
code.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
#make_bin#
#LOAD_SEGMENT=FFFFh#
#LOAD_OFFSET=0000h#
#CS=0000h#
#IP=0000h#
#DS=0000h#
#ES=0000h#
#SS=0000h#
#SP=FFFEh#
#AX=0000h#
#BX=0000h#
#CX=0000h#
#DX=0000h#
#SI=0000h#
#DI=0000h#
#BP=0000h#
JMP START
; DEFINED DATA
DB 6 DUP(0)
DW NMIS
DW 0000
PORTA1 EQU 00H
PORTB1 EQU 02H
PORTC1 EQU 04H
CREG1 EQU 06H
PORTA2 EQU 10H
PORTB2 EQU 12H
PORTC2 EQU 14H
CREG2 EQU 16H
MAXWEIGHT EQU 100
ANLG DB 00H, 01H, 02H
WEIGHTS DB 3 DUP(?)
START:
; KEEPING ALARM OFF INITIALLY
MOV AL, 10001000B
OUT CREG2, AL
MOV AL, 00H
OUT PORTC2, AL
READWEIGHT:
; PROPERLY INITIALIZING REGISTERS
MOV AX, 0
MOV BX, 0
MOV BP, 0
MOV SI, OFFSET ANLG
MOV DI, OFFSET WEIGHTS
WEIGHTLOOP:
; SETTING CONTROL REGISTER FOR 8255-1
MOV AL, 10001010B
OUT CREG1, AL
; SELECTING ANALOG I/P CORRESPONDING TO THE CURRENT ITERATION
MOV AL, [SI]
OUT PORTA1, AL
INC SI
; HANDLING THE ALE AND START PINS OF ADC
MOV AL, 02H
OUT PORTC1, AL
MOV AL, 01H
OUT PORTC1, AL
; WAITING FOR THE EOC OF ADC TO GO LOW INITIALLY
LEOC:
IN AL, PORTC1
AND AL, 10H
CMP AL, 10H
JZ LEOC
; HANDLING THE ALE AND START PINS OF ADC
MOV AL, 00H
OUT PORTC1, AL
; WATING FOR THE EOC OF ADC TO GO HIGH INDICATING CONVERSION COMPLETION
HEOC:
IN AL, PORTC1
AND AL, 10H
CMP AL, 10H
JNZ HEOC
; GETTING DIGITAL O/P FROM ADC
IN AL, PORTB1
; RECORDING WEIGHT CORRESPONDING TO THE CURRENT ITERATION
MOV [DI], AL
INC DI
INC BP
CMP BP, 3
JNZ WEIGHTLOOP
; TAKING THE AVERAGE OF THE 3 WEIGHTS RECORDED
MOV AX, 0
MOV BX, 0
MOV CX, 0
MOV DX, 0
MOV DI, OFFSET WEIGHTS
MOV BL, [DI]
ADD AX, BX
INC DI
MOV BL, [DI]
ADD AX, BX
INC DI
MOV BL, [DI]
ADD AX, BX
MOV CL, 3
DIV CL
MOV AH, 0
; CONVERTING DIGITAL O/P TO ACTUAL WEIGHT
; AND GETTING INTEGER AND DECIMAL PART OF THE DATA, I.E. AVG WEIGHT
MOV CL, MAXWEIGHT
MUL CL
MOV CX, 100
MUL CX
MOV CX, 256
DIV CX
MOV CL, 100
DIV CL
; NOW REGISTER AH HAS THE DECIMAL VAL AND REGISTER AL HAS THE VALUE FOR BEFORE DECIMAL
MOV BX, AX
; ALARM IF WEIGHT GREATER THAN 50
CMP AL, 50
JB DISPLAY
MOV AL, 01H
OUT PORTC2, AL
; DISPLAYING WEIGHT ON 7-SEG DISPLAY
DISPLAY:
; DISPLAYING INTEGER PART ON 7-SEG DISPLAY
MOV AX, 0
MOV AL, BL
MOV CL, 10
DIV CL
MOV DL, AL
MOV AL, AH
SHL AL, 4
ADD AL, DL
OUT PORTA2, AL
; DISPLAYING DECIMAL PART ON 7-SEG DISPLAY
MOV AX, 0
MOV AL, BH
MOV CL, 10
DIV CL
MOV DL, AL
MOV AL, AH
SHL AL, 4
ADD AL, DL
OUT PORTB2, AL
; WAITING FOR 'STOP ALARM' SWITCH TO BE PRESSED (POLLING)
READSTOPALARM:
MOV AX, 0
MOV BX, 0
IN AL, PORTC2
MOV BL, AL
AND BL, 10H
CMP BL, 10H
JNZ X
MOV AL, 00H
OUT PORTC2, AL
X:
JMP READSTOPALARM
; ISR OF NMI INTERRUPT - USED TO START READING WEIGHT
NMIS:
JMP START
ret