CNC

Anuncio
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
;--------------------------------------------------------------------- ----; Problema 1
; Examen 11 Febrero 2005
; Interprete HPGL modificado para máquina CNC ficticia
;--------------------------------------------------------------------- ----[BITS 16]
[SEGMENT Codigo]
;--------------------------------------------------------------------- ----; Rutina: EJECUTA_PD
;--------------------------------------------------------------------- ----EJECUTA_PD:
mov dx,378h
; Puerto de CONTROL
mov al,000000b
@Esp1:
out dx,al
;
Bits 0..1 = 00 : No se mueve en X
;
Bits 2..3 = 00 : No se mueve en Y
;
Bit 4
= 0 : Posición del taladro: ABAJO
;
Bit 5
= 0 : Para dar el flanco lo bajo
; Escribo en el Puerto de CONTROL
mov al,100000b
out dx,al
;
Bit 5
= 1 : Doy el flanco
; Escribo en el Puerto de CONTROL
inc dx
; Apunto al Puerto de ESTADO
in al,dx
bt ax,3
jc @Esp1
; Leo ESTADO
; Compruebo si esta ocupado
; Si es así, espero
bt ax,4
jc @PD_OK
; Terminó, compruebo si correcto
mov eax,1
ret
; Indico ERROR
@PD_OK: xor eax,eax
ret
; Indico correcto
;--------------------------------------------------------------------- ----; Rutina: EJECUTA_PU
;--------------------------------------------------------------------- ----EJECUTA_PU:
mov dx,378h
; Puerto de CONTROL
mov al,010000b
@Esp2:
out dx,al
;
Bits 0..1 = 00 : No se mueve en X
;
Bits 2..3 = 00 : No se mueve en Y
;
Bit 4
= 1 : Posición del taladro: ARRIBA
;
Bit 5
= 0 : Para dar el flanco lo bajo
; Escribo en el Puerto de CONTROL
mov al,110000b
out dx,al
;
Bit 5
= 1 : Doy el flanco
; Escribo en el Puerto de CONTROL
inc dx
; Apunto al Puerto de ESTADO
in al,dx
bt ax,3
jc @Esp2
; Leo ESTADO
; Compruebo si esta ocupado
; Si es así, espero
bt ax,4
jc @PU_OK
; Terminó, compruebo si correcto
mov eax,1
ret
; Indico ERROR
@PU_OK: xor eax,eax
ret
; Indico correcto
;--------------------------------------------------------------------- ----; Rutina: EJECUTA_PA
;--------------------------------------------------------------------- ----EJECUTA_PA:
; Las variables en memoria
; X
: Coordenada X destino
; Y
: Coordenada Y destino
; CoordX
: Coordenada X origen
; CoordY
: Coordenada Y origen
call EJECUTA_PU
cmp eax,1
; Me aseguro
; Compruebo error
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
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
jz
near
@ERROR_PA
; No piden optimizar la trayectoria. Los sencillo: primero desplazo
; en un eje y luego en el otro.
mov ax,Datos
mov ds,ax
; Me aseguro
; Muevo en el eje X ----------------------------------------------mov ecx,[X]
sub ecx,[CoordX]
jns @MOV_X_POS
; Eje X en negativo
neg ecx
; ecx = Nº de pasos (positivo)
@MOV_X_NEG:
mov dx,378h
mov al,010010b
@Esp3:
out dx,al
; Puerto de CONTROL
;
Bits 0..1 = 10 : Decrementa X
;
Bits 2..3 = 00 : No se mueve en Y
;
Bit 4
= 1 : Posición del taladro: ARRIBA
;
Bit 5
= 0 : Para dar el flanco lo bajo
; Escribe en puerto de CONTROL
mov al,110010b
out dx,al
;
Bit 5
= 1 : Doy el flanco
; Escribo en el puerto de CONTROL
inc dx
; Apunto al puerto de ESTADO
in al,dx
bt ax,3
jc @Esp3
; Si ocupado, espero
bt ax,4
jnc near @ERROR_PA
; Veo si hubo error
dec dword [CoordX]
loop @MOV_X_NEG
; Decremento coordenada origen
jmp @EJE_Y
@MOV_X_POS:
mov dx,378h
mov al,010001b
@Esp4:
out dx,al
; Puerto de CONTROL
;
Bits 0..1 = 01 : Incrementa X
;
Bits 2..3 = 00 : No se mueve en Y
;
Bit 4
= 1 : Posición del taladro: ARRIBA
;
Bit 5
= 0 : Para dar el flanco lo bajo
; Escribe en puerto de CONTROL
mov al,110001b
out dx,al
;
Bit 5
= 1 : Doy el flanco
; Escribo en el puerto de CONTROL
inc dx
; Apunto al puerto de ESTADO
in al,dx
bt ax,3
jc @Esp4
; Si ocupado, espero
bt ax,4
jnc @ERROR_PA
; Veo si hubo error
inc dword [CoordX]
loop @MOV_X_POS
; Incremento coordenada origen
; Muevo en el eje X ----------------------------------------------@EJE_Y:
mov ecx,[Y]
sub ecx,[CoordY]
jns @MOV_Y_POS
; Eje y en negativo
neg ecx
; ecx = Nº de pasos (positivo)
@MOV_Y_NEG:
mov dx,378h
mov al,011000b
out dx,al
; Puerto de CONTROL
;
Bits 0..1 = 00 : No se mueve en X
;
Bits 2..3 = 10 : Decrementa Y
;
Bit 4
= 1 : Posición del taladro: ARRIBA
;
Bit 5
= 0 : Para dar el flanco lo bajo
; Escribe en puerto de CONTROL
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
@Esp5:
mov al,111000b
out dx,al
;
Bit 5
= 1 : Doy el flanco
; Escribo en el puerto de CONTROL
inc dx
; Apunto al puerto de ESTADO
in al,dx
bt ax,3
jc @Esp5
; Si ocupado, espero
bt ax,4
jnc @ERROR_PA
; Veo si hubo error
dec dword [CoordY]
loop @MOV_Y_NEG
; Decremento coordenada origen
jmp @FIN_PA
@MOV_Y_POS:
mov dx,378h
mov al,010100b
@Esp6:
out dx,al
; Puerto de CONTROL
;
Bits 0..1 = 00 : No se mueve en X
;
Bits 2..3 = 01 : Incrementa Y
;
Bit 4
= 1 : Posición del taladro: ARRIBA
;
Bit 5
= 0 : Para dar el flanco lo bajo
; Escribe en puerto de CONTROL
mov al,110100b
out dx,al
;
Bit 5
= 1 : Doy el flanco
; Escribo en el puerto de CONTROL
inc dx
; Apunto al puerto de ESTADO
in al,dx
bt ax,3
jc @Esp6
; Si ocupado, espero
bt ax,4
jnc @ERROR_PA
; Veo si hubo error
inc dword [CoordY]
loop @MOV_Y_POS
; Incremento coordenada origen
@FIN_PA:
mov eax,0
ret
; Retorna sin error
@ERROR_PA:
mov eax,1
ret
; Retorna con error
;--------------------------------------------------------------------- ----; Rutina HPGL
;--------------------------------------------------------------------- ----HPGL:
; Entrada:
; DS:ESI apunta a código HPGL (ASCII) en memoria
; ECX
longitud en bytes del código
mov ax,ds
mov es,ax
; Apunto a los datos con otro segmento
mov ax,Datos
mov ds,ax
xor eax,eax
mov [CoordX],eax
mov [CoordY],eax
@Esp7:
mov dx,379h
in al,dx
bt ax,3
jc @Esp7
; Inicialmente en las coordenadas (0,0)
; Puerto de ESTADO
; Compruebo si está ocupado
@Interpreta:
mov al,[es:esi]
; Tomo primer carácter
cmp al,'P'
jnz near @ERROR_HPGL
mov al,[es:esi+1]
cmp al,'D'
jnz @BuscaOtro
; Es el comando 'PD'
; Tomo segundo carácter
244
call EJECUTA_PD
;
245
246
cmp eax,1
247
jz near @ERROR_HPGL
248
249
mov al,[es:esi+2]
;
250
cmp al,';'
251
jnz near @ERROR_HPGL
252
253
add esi,3
254
sub ecx,3
255
cmp ecx,0
256
257
ja @Interpreta
258
jmp @FIN_HPGL
259
260 @BuscaOtro:
261
cmp al,'U'
262
jnz @BuscaOtro2
263
264
; Es el comando 'PU'
265
266
call EJECUTA_PU
;
267
268
cmp eax,1
269
jz near @ERROR_HPGL
270
271
mov al,[es:esi+2]
;
272
cmp al,';'
273
jnz near @ERROR_HPGL
274
275
add esi,3
276
sub ecx,3
277
cmp ecx,0
278
279
ja @Interpreta
280
jmp @FIN_HPGL
281
282 @BuscaOtro2:
283
cmp al,'A'
284
jnz @ERROR_HPGL
;
285
286
; Es el comando 'PA'
287
288
mov edi,esi
289
add edi,2
;
290
call Convierte5
;
291
;
292
293
mov [X],eax
294
295
mov al,[es:esi+7]
296
cmp al,','
;
297
jnz @ERROR_HPGL
298
299
mov edi,esi
300
add esi,8
301
call Convierte5
;
302
303
mov [Y],eax
304
305
push ecx
306
call EJECUTA_PA
;
307
pop ecx
308
309
cmp eax,1
310
jnz @ERROR_HPGL
311
312
mov al,[es:esi+13]
313
cmp al,';'
;
314
jnz @ERROR_HPGL
315
316
add esi,14
317
sub ecx,14
318
cmp ecx,0
319
ja @Interpreta
320
321 @FIN_HPGL:
322
mov eax,0
323
ret
;
324
Lo hago
Tomo tercer carácter
Lo hago
Tomo tercer carácter
No es ninguno de los tres comandos
Apunto a xxxxx
A la vuelta en EAX está al valor binario
del dato ASCII apuntado por ES:EDI
Compruebo la ','
Obtengo yyyyy
Lo hago
Compruebo el ';'
Salir sin error
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
@ERROR_HPGL:
mov eax,1
ret
; Salir con error
;--------------------------------------------------------------------- ----; Rutina: Convierte5
;--------------------------------------------------------------------- ----; Entrada ES:EDI apunta a 5 dígitos numéricos en ASCII
; Salida: EAX el valor binario que representan
Convierte5:
mov al,[es:edi]
sub al,30h
mov edx,10000
movzx eax,al
mul edx
; Decenas de millar
mov ebx,eax
; Acumulador
mov al,[es:edi+1]
sub al,30h
mov edx,1000
movzx eax,al
mul edx
; Unidades de millar
add ebx,eax
mov al,[es:edi+2]
sub al,30h
mov edx,100
movzx eax,al
mul edx
; Centenas
add ebx,eax
mov al,[es:edi+3]
sub al,30h
mov edx,10
movzx eax,al
mul edx
; Decenas
add ebx,eax
mov al,[es:edi+1]
sub al,30h
movzx eax,al
; Unidades
add eax,ebx
ret
;--------------------------------------------------------------------- ----;--------------------------------------------------------------------- ----[SEGMENT Datos]
X
Y
CoordX
CoordY
resd
resd
resd
resd
1
1
1
1
;--------------------------------------------------------------------- -----
Descargar