Vistas de página en total

viernes, 15 de noviembre de 2013

Protocolo DH+ Network

    Debido a mi formación trabajo con  automática y a la necesidad de comunicar con autómatas concretos, el protocolo que implementé inicialmente para mis comunicaciones fue del DH+ de Allen- Bradley. Como este fue el primero que implementé, fue el que luego utilicé para mis desarrollos y el que ahora pongo.

    Es por esto, que cuando tuve que hacer cualquier comunicación entre robots y autómatas, robots y ordenadores, o ordenadores y placas con  procesadores, siempre usé este.
  
    Como no se trata de un protocolo x-modem literal, pongo un enlace en el que se explica este protocolo.
    En las librerías incorporo hasta el nivel de enlace al nivel de transporte. El resto de niveles, aunque se explican en el enlace para Allen-Bradeley, no los implementaré, pues se trata de ordenes específicas. Cada uno podrá usar los comandos que desee comunicar con sus tarjetas o equipos.




Comenzaré por lo tanto por colocar como siempre la cabecera para la llamada a las funciones.


DH.MAC
; Copyright (C) 2013  José Ángel Moneo Fernández

;    This program is free software: you can redistribute it and/or modify
;    it under the terms of the GNU General Public License as published by
;    the Free Software Foundation, either version 3 of the License, or
;   (at your option) any later version.

;    This program is distributed in the hope that it will be useful,
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;    GNU General Public License for more details.

;    You should have received a copy of the GNU General Public License
;    along with this program.  If not, see <http://www.gnu.org/licenses/>.

 ; CABECERA PROTOCOLO  Data Highway II (DH+) network

include rs232.mac

;caracteres de comunicacion
SOH EQU 1      ;ENCABEZAMIENTO
STX EQU 2      ;COMIENZO TEXTO
ETB EQU 17H    ;FINAL BLOQUE (QUEDAN MAS)
ETX EQU 3      ;FINAL DE MENSAJE
ACK EQU 6      ;RECONOCIMEINTO
NACK EQU 15H   ;NO RECONOCIDO
DLE EQU 10H    ;CONTROL
ENQ EQU 5      ;SOLICITUD DE RESPUESTA
EOT EQU 4      ;FIN TRANSMISION
SYN EQU 16H    ;ESPERA SINCRONICA
CAN EQU 1BH    ;CANCELAR, ESC

; envía una cadena de datos por puerto serie mediante
; protocolo DH+
Send_DH macro nodo,datos,longitud
ifndef _Send_DH
    extrn _Send_DH:near
endif
        mov ax,nodo
        push ax
        lea ax,datos
        push ax
        mov ax,longitud
        push ax
        call _Send_DH
       
 endm

; recibe una cadena de datos por puerto serie mediante
; protocolo DH+
; devuelve en el mensaje en el buffer  datos
; dh= logitud del mensaje
; dl= nodo;   el nodo que lo envía en dl   0-255
; al=estado   Si al=0ffh error, al=0 ok
Recive_DH macro datos
ifndef _Recive_DH
    extrn _Recive_DH:near
endif
        lea ax,datos
        push ax
        call _Recive_DH
   
 endm
 

miércoles, 13 de noviembre de 2013

COMUNICACIÓN RS232

 Hoy vamos a comenzar con los puertos de comunicación, y en particular con el puerto serie.
 No vamos a usar interrupciones, ni el dos. Vamos a programar el PIO directamente.
 Para ello usaremos las nuevas funciones de la entrada anterior peek y poke.

     Con esta cabecera rearemos unas funciones básicas para inicialización, lectura y escritura sobre el PIO 8050, que nos permitirán leer y escribir sobre el puerto serie. Se pueden  ampliar después convirtiéndolas en funciones, con gestión de errores, pero como la idea de este blog es estar al menor nivel, pero que sea operativo, lo dejaré así.
    La idea del blog, como dije desde el principio es que sea didáctico a bajo nivel, pero permitiendo al mismo tiempo hacer operativo el ensamblador.
     Ya sabemos que se puede hacer mejor... pero para hacerlo mejor usaríamos las librerías ya existentes. Sin embargo los ejemplos que existen a bajo nivel no son realmente operativos sin un debuger, pues les falta implementación.

     Como ya habréis visto es blog es algo intermedio, estando siempre en bajo nivel, como si el PC fuera un microordenador, estamos haciendo programas útiles y ejecutables por si solos, sin necesidad de debuger, para ver los resultados.

   

RS232.MAC 
; Copyright (C) 2013  José Ángel Moneo Fernández

;    This program is free software: you can redistribute it and/or modify
;    it under the terms of the GNU General Public License as published by
;    the Free Software Foundation, either version 3 of the License, or
;   (at your option) any later version.

;    This program is distributed in the hope that it will be useful,
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;    GNU General Public License for more details.

;    You should have received a copy of the GNU General Public License
;    along with this program.  If not, see <http://www.gnu.org/licenses/>.

include io.mac

;CABECERA Y MACROS COMUNICACIÓN SERIE

;velocidades de transmisión
v4800 equ 24
V9600 EQU 12
V19200 EQU 6

;direcciones PUERTO COM 1
rtd equ 3f8h  ; Transmitter Holding Register
lsb equ 3f8h  ; Receiver Data Register SI BIT 7=0 EN LC, Baud Rate Divisor SI BIT 7=1 EN LC
msb equ 3f9h  ;Baud Rate Divisor    SI bit 7=1 LC
ie equ  3f9h  ;Interrupt Enable Register
ii equ  3fah  ;Interrupt Identification  Register
lc equ  3fbh  ;Line Control Register   
mc equ  3fch   ;Modem Control Register
ls equ  3fdh   ;Line Status Register   
ms equ  3feh   ;Modem Status  Register




; LECTURA DE CARACTER POR PUETO SERIE
getcaux macro
local rs_bien
local espera1
espera1:
        peek ls      ;LECTURA REGISTRO DE ESTADO
        test al,1eh  ; VERIFICACIÓN DE ERRORES          
        jz rs_bien    ;SI NO HAY ERROR SEGUIMOS
        peek rtd      ;TOMAMOS EL ERROR.. nO VAMOS A TRATARLO RODAVÍA. AQUÍ PODRÍAMOS TRATARLO MEDIANTE UN MENSAJE
rs_bien:
        test al,1     ; VERIFICAMOS SI HAY DATO
        jz espera1    ; ESPERAMOS RECIBIRLO
        peek rtd       ; LO LEEMOS
        endm

;ENVÍO DE CARACTER POR PUERTO SERIE
putcaux macro dato
local espera
espera: peek ls            ; SE LEE EL REGISTRO DE LECTURA
        test al,100000b     ; REGISTRO DE SALIDA DISPONIBLE
        jz espera
        poke rtd,dato      ; ESCRIBE EL DATO
        endm
       
       
;INICIALIZCIÓN DEL PUERTO A UNA VELODIAD
rs232_ini macro velocidad
        poke lc,80h         ; ACCESO A CONFIGURACIÓN DE VELOCIDAD
        mov bx,velocidad     ;ALAMACENA LA VELOCIDAD
        poke lsb,bl
        poke msb,bh
        poke lc,3           ;CONFIUGURA 8 BITS DE TRANSMISIÓN- 1 BIT DE STOP. SIN PARIDAD
        poke mc,0          
        poke ie,0
        endm