News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Dmx512 250K Baud Transmitter Demo Code

Started by dnaci, Apr 21, 2024, 09:21 AM

Previous topic - Next topic

dnaci

This code sends the portb and portd statuses to the 4th and 5th channels of the DMX512 receiver, respectively. It is a code open to development. Tested with the this receiver dmx512 and several dmx devices.

'proton basic dmx512 transmitter demo code

Device = 18F46K22
;-------------------------------------------------------------------------------
;**** Added by Fuse Configurator ****
; Use the Fuse Configurator plug-in to change these settings
Config_Start
  FOSC = HSHP    ;HS oscillator (high power > 16 MHz)
  PLLCFG = OFF    ;Oscillator used directly
  PRICLKEN = On    ;Primary clock is always enabled
  FCMEN = OFF    ;Fail-Safe Clock Monitor disabled
  IESO = OFF    ;Oscillator Switchover mode disabled
  PWRTEN = OFF    ;Power up timer disabled
  BOREN = SBORDIS    ;Brown-out Reset enabled in hardware only (SBOREN is disabled)
  BORV = 190    ;VBOR set to 1.90 V nominal
  WDTEN = OFF    ;Watch dog timer is always disabled. SWDTEN has no effect.
  WDTPS = 32768    ;1:32768
  CCP2MX = PORTC1    ;CCP2 input/output is multiplexed with RC1
  PBADEN = On    ;PORTB<5:0> pins are configured as analog input channels on Reset
  CCP3MX = PORTB5    ;P3A/CCP3 input/output is multiplexed with RB5
  HFOFST = On    ;HFINTOSC output and ready status are not delayed by the oscillator stable status
  T3CMX = PORTC0    ;T3CKI is on RC0
  P2BMX = PORTD2    ;P2B is on RD2
  MCLRE = EXTMCLR    ;MCLR pin enabled, RE3 input pin disabled
  STVREN = On    ;Stack full/underflow will cause Reset
  LVP = On    ;Single-Supply ICSP enabled if MCLRE is also 1
  XINST = OFF    ;Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
  Debug = OFF    ;Disabled
  Cp0 = OFF    ;Block 0 (000800-003FFFh) not code-protected
  CP1 = OFF    ;Block 1 (004000-007FFFh) not code-protected
  CP2 = OFF    ;Block 2 (008000-00BFFFh) not code-protected
  CP3 = OFF    ;Block 3 (00C000-00FFFFh) not code-protected
  CPB = OFF    ;Boot block (000000-0007FFh) not code-protected
  CPD = OFF    ;Data EEPROM not code-protected
  WRT0 = OFF    ;Block 0 (000800-003FFFh) not write-protected
  WRT1 = OFF    ;Block 1 (004000-007FFFh) not write-protected
  WRT2 = OFF    ;Block 2 (008000-00BFFFh) not write-protected
  WRT3 = OFF    ;Block 3 (00C000-00FFFFh) not write-protected
  WRTC = OFF    ;Configuration registers (300000-3000FFh) not write-protected
  WRTB = OFF    ;Boot Block (000000-0007FFh) not write-protected
  WRTD = OFF    ;Data EEPROM not write-protected
  EBTR0 = OFF    ;Block 0 (000800-003FFFh) not protected from table reads executed in other blocks
  EBTR1 = OFF    ;Block 1 (004000-007FFFh) not protected from table reads executed in other blocks
  EBTR2 = OFF    ;Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks
  EBTR3 = OFF    ;Block 3 (00C000-00FFFFh) not protected from table reads executed in other blocks
  EBTRB = OFF    ;Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
Config_End

;**** End of Fuse Configurator Settings ****
;-------------------------------------------------------------------------------

Declare Xtal = 20
Declare All_Digital = true
Declare Hserial_Baud = 250000      ' Set baud rate to 250000
Declare Hserial_RCSTA = %10010000  ' Enable serial port and continuous receive
Declare Hserial_TXSTA = %01100101  ' Enable transmit and asynchronous mode
Declare Hserial_SPBRG  = 4

TRISA=%11111111
TRISB=%00000000
TRISC=%10000011
TRISD=%00000000
TRISE=%00000011
PORTA=0
PORTB=0
PORTC=0
PORTD=0
PORTE=0
ADCON0 = 0x3c
ADCON1 = 0x0f
ADCON2 = %10001111
ANSELC=0

Dim tt As Byte
Dim ch[16] As Byte
PORTB.2=1
PORTD=254

main:
ch[0]=1
ch[1]=2
ch[2]=3
ch[3]=PORTD
ch[4]=PORTB
ch[5]=4

RCSTA.7= 0   'disable UART
Low PORTB.1  'low for frame start sync, Break
DelayUS 120  '88us min required, 120us is safer.
High PORTB.1 'high for mark after break
DelayUS 8    '8usec min required
RCSTA.7= 1   'Enable UART

HSerOut [0] 'DMX512 Start Code. Already includes the start bit.
DelayUS 36  'let the serial data finish
RCSTA.7= 0
High PORTB.1 'high for two stop bits and MTBF
DelayUS 4

RCSTA.7= 1
HSerOut [ch[0],ch[1],ch[2],ch[3],ch[4],ch[5],ch[6],ch[7]] 'Channels
DelayUS 36 'let the serial data finish
RCSTA.7= 0
High PORTB.1 'high for two stop bits and MTBF
DelayUS 4

DelayMS 500

ch[0]=6
ch[1]=7
ch[2]=8
ch[3]=PORTB
ch[4]=PORTD
ch[5]=9

RCSTA.7= 0   'disable UART
Low PORTB.1  'low for frame start sync, Break
DelayUS 120  '88us min required, 120us is safer.
High PORTB.1 'high for mark after break
DelayUS 8    '8usec min required
RCSTA.7= 1   'Enable UART

HSerOut [0] 'Start Code. Already includes the start bit.
DelayUS 36  'let the serial data finish
RCSTA.7= 0
High PORTB.1 'high for two stop bits and MTBF
DelayUS 4

RCSTA.7= 1
HSerOut [ch[0],ch[1],ch[2],ch[3],ch[4],ch[5],ch[6],ch[7]] 'Channels
DelayUS 36 'let the serial data finish
RCSTA.7= 0
High PORTB.1 'high for two stop bits and MTBF
DelayUS 4

DelayMS 500
GoTo main

Pepe

Demo Proteus and sources

positron  dmx512 transmitter


Device = 18F46K22

Declare Xtal = 8

Declare Optimiser_Level = 3
Declare Watchdog off

Declare HPWM1_Pin = PORTC.2

Declare Create_Coff On
Declare Hserial_Baud = 250000       ' Set baud rate to 250000
Declare Hserial_RCSTA = %10010000   ' Enable serial port and continuous receive
Declare Hserial_TXSTA = %01100101   ' Enable transmit and asynchronous mode

Declare HRSOut_Pin = PORTC.6
Declare Adin_Res 10
Declare Adin_Tad cFRC
Declare Adin_Stime 50

Symbol TotalCanales 100  ' Total canales
Symbol ADFM = ADCON2.7   ' A/D Result Format Select bit

ADFM = 1
ANSELA=1
ANSELB=0
ANSELC=0
ANSELD=0
ANSELE=0
TRISA=%11111111
TRISB=%11111111
TRISC=%10000011
TRISD=%11111111
TRISE=%00000011
PORTA=0
PORTB=0
PORTC=0
PORTD=0
PORTE=0
ADCON0 = 0x3c
ADCON1 = 0x0f
ADCON2 = %10001111

PinPullup Enable, PORTB

Dim i As Word
Dim ch[TotalCanales] As Byte
Dim an As Word
Clear ch

Do

ch[0]= an
ch[1]= PORTB
ch[2]= PORTD
ch[3]= 20
ch[4]= 30
ch[5]= 40
ch[6]= 50
ch[7]= 60
ch[8]= 70
ch[99]= 99

RCSTA.7 = 0   'disable UART
Low PORTC.6   'low for frame start sync, Break
DelayUS 120   '88us min required, 120us is safer.
High PORTC.6  'high for mark after break
DelayUS 8     '8usec min required
RCSTA.7= 1    'Enable UART

HSerOut [0]   'DMX512 Start Code. Already includes the start bit.
DelayUS 36    'let the serial data finish
RCSTA.7= 0
High PORTC.6  'high for two stop bits and MTBF
DelayUS 4

RCSTA.7= 1
For i=0 To TotalCanales-1
HSerOut [ch[i]]
Next
HSerOut [0]

DelayUS 36   'let the serial data finish
RCSTA.7= 0
High PORTC.6 'high for two stop bits and MTBF
DelayUS 4

an = (ADIn 0 )>>2
DelayMS 300

Loop

tester dmx


Device = 18F2550

Declare Xtal 8

Declare HPWM1_Pin = PORTC.2

Declare Hserial_Baud = 250000       ' Set baud rate to 250000
Declare Hserial_RCSTA = %10010000   ' Enable serial port and continuous receive
Declare Hserial_TXSTA = %01100101   ' Enable transmit and asynchronous mode


''************************************************************************
'*                    Registros USART                                    *
'************************************************************************/

Symbol SPEN                RCSTA.7      ' Bit activación puerto serie
Symbol RX9                 RCSTA.6      ' Activación de recepción de 9 bits
Symbol SREN                RCSTA.5      ' Se activa para recibir un sólo Byte
Symbol CREN                RCSTA.4      ' Se activa para recepción continua
Symbol ADDEN               RCSTA.3      ' Autodetección de dirección
Symbol FERR                RCSTA.2      ' Error de Frame
Symbol OERR                RCSTA.1      ' Error de Overrun
Symbol RX9D                RCSTA.0      ' El noveno Bit
Symbol BRGH                TXSTA.2      ' Selección de alta velocidad
Symbol BRG16               BAUDCON.3    ' Uso de un valor baudrate de 16 bits
Symbol SYNC                TXSTA.4      ' Selección de modo síncrono o Asíncrono
Symbol RCIF                PIR1.5       ' Señalizador de Byte recibido en USART
Symbol RCIE                PIE1.5       ' Activación de la interrupción USART

Symbol    PERIOD       8000.0       ' 8 ms
Symbol    Xtl          8000000    ' crystal frequency - 8MHz
Symbol    ICLK         (Xtl/4)     ' crystal is divided by four
Symbol    SCALE        64           ' prescale by 8 - check for overflow!

Symbol    PRELOAD         255-(PERIOD*ICLK/SCALE)/1000000
'************************************************************************
'*                    Pinout                                             *
'************************************************************************/

Symbol      DISP0 =      PORTA.6      ' 1er dígito de Display
Symbol      DISP1 =      PORTC.0     ' 2º dígito de Display
Symbol      DISP2 =      PORTC.1     ' 3º dígito de Display
Symbol      Display =    PORTB       ' Contenido del Display

Symbol        COL1 =       PORTA.1     ' Columnas del teclado matricial
Symbol        COL2 =       PORTA.0
Symbol        COL3 =       PORTE.3
Symbol        FILA1 =      PORTA.2     ' Filas del teclado matricial
Symbol        FILA2 =      PORTA.3
Symbol        FILA3 =      PORTA.4
Symbol        FILA4 =      PORTA.5

Symbol        DMXRX =      PORTC.7     ' Entrada RX desde el MAX485
Symbol        LED =        PORTC.2     ' LED Señalizador

'************************************************************************
'*                    Estados protocolo DMX                              *
'************************************************************************/

Symbol       DMX_ESPERA_BYTE         0
Symbol       DMX_ESPERA_BREAK        1
Symbol       DMX_ESPERA_START        2
Symbol       DMX_ESPERA_DATO         3
Symbol       DMX_RECEPCION_DATOS     4

Symbol GIEL = INTCON.6   ' Peripheral Interrupt Enable
Symbol GIEH = INTCON.7   ' Global Interrupt Enable

Symbol TMR0IE = INTCON.5 ' TMR0 Overflow Interrupt Enable
Symbol TMR0IF = INTCON.2 ' TMR0 Overflow Interrupt Flag
Symbol TMR0ON = T0CON.7  ' Timer0 On/Off Control bit
Symbol IPEN = RCON.7     ' Interrupt Priority Enable bit
Symbol USBEN = UCON.3    ' USB Module Enable bit
Symbol UTRDIS = UCFG.3   ' On-Chip Transceiver Disable bit
Symbol TMR0IP = INTCON2.2' TMR0 Overflow Interrupt Priority bit

'************************************************************************
'*                    Variables globales y constantes                    *
'************************************************************************/

Dim  SEGM[36]=  63,6,91,79,102,109,125,7,127,111, _ ' Esta Variable tiene la representación gráfica de cada dígito en 7-seg           
                119,124,57,94,121,113,125,118,6,30,118,56,84,84,63,115,103,80,109,120,62,28,28,119,110,91
'* Números       0 1  2  3  4   5   6  7  8   9                                                                             
'* LETRAS         A  B   C  D  E   F   G   H  I  J  K  L  M  N  O  P    Q  R   S   T  U  V  W   X   Y  Z

Dim DisplayActivo As Byte = 0           ' Índice del multiplexor de displays 7-seg
Dim Digito1, Digito2, Digito3 As Byte ' Valor de cada dígito del Display
Dim MarcarDigito As Byte              ' Contador de tiempo para parpadeo de puntos decimales

Dim TeclaLeida As Byte                ' Valor de 0 a 12 que indica la tecla pulsada (0=ninguna)
Dim TeclaAnterior As Byte             ' Valor de la última tecla que Se pulsó
Dim Activado As Bit                   ' Indica si el circuito está Activado o no
Dim Retardo As Byte =0                ' Sirve para establecer el retraso tras pulsar tecla

Dim CanalDMX As Word                  ' Canal DMX seleccionado para visualizar, de 1 a 512
Dim DatoDMX As Byte                   ' Dato que contiene el canal seleccionado
Dim DMX_Estado As Byte = DMX_ESPERA_BREAK ' Estado de la máquina de estados
Dim DatoRX As Byte                    '   Dato genérico recibido en USART
Dim DMX_Indice As Word = 0            ' Apuntador a una posición de la trama DMX
Dim coerr As Bit
Dim cferr As Bit
Symbol TotalCanales 512 ' Total canales a almacenar
Dim TramaDMX[TotalCanales] As Byte     ' Trama completa de valores DMX


'************************************************************************
'*          Interrupción Timer 0: refresco de displays 7-seg             *
'************************************************************************/
 On_Hardware_Interrupt GoTo Isr

   ' Configuración de Entradas / Salidas

   ' Puerto A: los pines A0 y A1 son entradas desde teclado matricial. El resto salidas
   TRISA = 3
   ' Puerto B: conectado al ULN2003 para gestionar displays. Todo salidas
   TRISB = 0x0
   ' Puerto C: conectado a displays y LED. Todo salidas. El Pin RX de la usart Se pone
   ' como entrada al configurar la USART.
   TRISC = 0x80

   ' Configuración del micro:
   ' - oscilador interno a 8 MHz
   ' - entradas analógicas desactivadas y Vref desactivada
   ' - CCP1 activo para PWM
   ' - comparador desactivado
   ' - Timer0: interno, con prescaler 64 y a 8 bits
   ' - Timer1, 2 y 3: desactivados
   ' - Watchdog Activado
   ' - Sin detección de bajo voltaje

   OSCCON=$72
   ' Configuración de la USART
   BRGH=1           ' Alta velocidad seleccionada.
   BRG16=1          ' Baudrate de 16 bits
   SYNC=0           ' Seleccionamos transmisión Asíncrona
   SPBRG=7          ' A 8MHz representa Baudios = 250KHz
   SPBRGH=0
   RX9=1            ' Activada la recepción a 9 bits
   SREN=0           ' Desactivada la recepción de un sólo Byte
   ADDEN=0          ' Desactivada la autodetección de dirección
   FERR=0           ' No hay error de frame
   OERR=0           ' No hay error de overrun
   SPEN=1           ' USART activada
   CREN=1           ' Recepción activada
 
   ' Activamos las interrupciones de recepción de la USART y del Timer0 (displays)
   
  RCIE = 1         ' interrupcion usart activada     
  TMR0L = PRELOAD   
  T0CON = 0xC5       'div 64
  TMR0IE = 1
  GIEL = 1  ' Peripheral Interrupt Enable
  GIEH = 1   ' Global Interrupt Enable

   CanalDMX = 1       ' Por defecto, el canal seleccionado es el primero

   Digito1=SEGM[24]+128 ' O
   Digito2=SEGM[15]+128 ' F
   Digito3=SEGM[15]+128 ' F
 

   Activado = 0  ' Estará en OFF hasta que Se pulse una tecla

   Do
      TeclaLeida = LeeTeclado()      ' exploramos el teclado matricial
      If TeclaLeida<> 0 Then                              ' si Se ha pulsado tecla
                            Activado=1                 ' activamos el display
                            If TeclaLeida = 10 Then       ' el código 10 es la tecla "0"
                                                 TeclaLeida = 0
                            EndIf                     
                            If TeclaLeida <> 11 Then      ' el código 11  muestra el canal, pero no lo cambia
                                                          ' si no Se ha pulsado la tecla *, hay que modificar canal
                                                    If Retardo = 0 Then            ' si ha pasado un rato desde la última tecla
                                                                        CanalDMX=0          ' empezamos a escribir de nuevo
                                                    EndIf
                                                    CanalDMX = CanalDMX * 10    ' en caso contrario la tecla se acumula al canal
                                                    CanalDMX = CanalDMX + TeclaLeida
                           EndIf
                           Retardo = 80                ' contador de tiempo desde última tecla pulsada
      EndIf
     
      If TeclaLeida = 12 Then         ' la tecla 12 (#) borra el canal seleccionado
                              CanalDMX = 0
      EndIf
      If Retardo <> 0 Then           ' en cada ciclo disminuimos el contador de Retardo
                           Dec Retardo                ' hasta llegar a 0
      EndIf
     
      DatoDMX = TramaDMX[CanalDMX-1]  ' Se extrae el dato desde el array capturado
       
      HPWM 1,DatoDMX,1000    ' se ilumina el led con el duty cicle que corresponda

      If Activado <> 0 Then                           ' si el Display está activo
         If Retardo <> 0 Then                         ' si estamos cambiando de canal DMX
                            Imprime (CanalDMX)        ' mostramos el canal
                            Inc MarcarDigito          ' y acumulamos en el contador para parpadeo
                            If MarcarDigito > 20 Then ' de los puntos decimales del Display
                                                      MarcarDigito=1
                            EndIf
                         Else                         ' si no estamos cambiando de canal DMX
                            Imprime (DatoDMX)         ' mostramos la lectura del canal
                            MarcarDigito=0
        EndIf
       
      EndIf   
      DelayMS 25                 ' pequeña espera
Loop

'************************************************************************
'* Imprime: esta función recibe una Variable y obtiene su representación *
'*          decimal en tres dígitos.                                     *
'************************************************************************/

Proc Imprime( valor As Word)
   Dim  Cadena As String * 3 
   Dim aux As Byte
   Cadena = Str$(Dec3 valor)
   If Valor<100 Then
      Digito1=128
     Else
     aux = Cadena[0]-48
      Digito1=SEGM[aux]+128
   EndIf
   If Valor<10 Then
      Digito2=128
     Else
      aux = Cadena[1]-48
      Digito2=SEGM[aux]+128
   EndIf
   aux = Cadena[2]-48
   Digito3=SEGM[aux]+128

   ' Según el tiempo transcurrido (MarcarDigito), encendemos o apagamos
   ' el punto decimal (Bit más significativo de PORTB)
   If MarcarDigito>10 Then
      Digito1=Digito1-128
      Digito2=Digito2-128
      Digito3=Digito3-128
   EndIf
EndProc


'************************************************************************
'* LeeTeclado: esta función explora el teclado matricial y devuelve      *
'*        0:       Ninguna tecla pulsada                                 *
'*        1 a 9:   Teclas 1 a 9                                          *
'*        10:      Tecla 0                                               *
'*        11:      Tecla *                                               *
'*        12:      Tecla #                                               *
'************************************************************************/

Proc LeeTeclado(),Byte
   Dim Tecla As Byte

   Tecla=0
   FILA1=1
   FILA2=0
   FILA3=0
   FILA4=0
   If COL1 <> 0 Then
      Tecla = 1
   EndIf   
   If COL2 <> 0 Then
      Tecla = 2
   EndIf   
   If COL3 <> 0 Then
      Tecla = 3
   EndIf
   FILA1=0
   FILA2=1
   FILA3=0
   FILA4=0
   If COL1 <> 0 Then
      Tecla = 4
   EndIf   
   If COL2 <> 0 Then
      Tecla = 5
   EndIf   
   If COL3<> 0 Then
      Tecla = 6
   EndIf   
   FILA1 = 0
   FILA2 = 0
   FILA3 = 1
   FILA4 = 0
   If COL1 <> 0 Then
      Tecla = 7
    EndIf 
   If COL2 <> 0 Then
      Tecla = 8
    EndIf 
   If COL3 <> 0 Then
      Tecla = 9
   EndIf
   FILA1 = 0
   FILA2 = 0
   FILA3 = 0
   FILA4 = 1
   If COL1 <> 0 Then
      Tecla = 11
   EndIf
   If COL2 <> 0 Then
      Tecla = 10
   EndIf   
   If COL3 <> 0 Then
      Tecla = 12
   EndIf 
   If Tecla = TeclaAnterior Then
                                 Tecla = 0
                            Else
                                 TeclaAnterior = Tecla
   EndIf                             
   Result=Tecla
EndProc

Isr:
Context Save

If TMR0IF = 1 Then
                  TMR0L = PRELOAD
   Select Case DisplayActivo
      Case 0
         DISP2=0
         Display=Digito1
         DISP0=1
         DisplayActivo=1
       
      Case 1         
         DISP0=0
         Display=Digito2
         DISP1=1
         DisplayActivo=2
       
      Case 2
         DISP1=0
         Display=Digito3
         DISP2=1
         DisplayActivo=0
   End Select
   TMR0IF = 0       
EndIf
'************************************************************************
'*  Interrupción RDA: dato recibido por la USART                         *
'*  Esta interrupción Se activa cada vez que Se recibe un dato en la     *
'*  USART. Mediante el control de una máquina de estados Se determina    *
'*  la validez y el significado del dato recibido, y Se obra en          *
'*  consecuencia.                                                        *
'************************************************************************/

While RCIF <> 0 ' ejecutamos mientras haya un dato pendiente de procesar
 
    ' Hacemos una copia del registro RCSTA porque sus bits cambian de valor
    ' al leer RCREG y modificar CREN
    coerr = RCSTA.1
    cferr = RCSTA.2
    ' En RCREG está el dato que acaba de recibir la USART
    DatoRX = RCREG

    ' Si Se reciben más de 3 bytes Sin haberlos procesado, Se produce un error
    ' de Overrun. En este caso, Se borra el error reiniciando CREN y dejamos
    ' la interrupción preparada para procesar la siguiente trama DMX
    If coerr <> 0 Then
                     CREN=0
                     CREN=1
                     DMX_Estado = DMX_ESPERA_BYTE
                     GoTo salir
    EndIf

    ' Máquina de estados
    Select Case DMX_Estado
   
      Case DMX_ESPERA_BYTE   ' si estamos en este estado y hay error FRAME
                             ' es que nos ha pillado en medio de un Byte. Hay que seguir esperando
                             ' hasta que desaparezca el error.
        If cferr = 0 Then
                             ' Ha llegado un Byte. Ahora esperaremos la Señal Break
                          DMX_Estado = DMX_ESPERA_BREAK
        EndIf
       
      Case DMX_ESPERA_BREAK   ' estamos esperando la Señal Break
                              ' Esta Señal Se identifica porque aparece el error de Frame
        If cferr = 0 Then     ' <>
                              ' Tras recibir el error de Break, hay que esperar un Byte de valor 0
                          If DatoRX = 0 Then
                                             DMX_Estado = DMX_ESPERA_START
                          EndIf 
        EndIf
       
      Case DMX_ESPERA_START ' ya hemos recibido el Break y ahora hay que
                            ' esperar un Byte con valor 0, que será la Señal de Start
                            ' Mientras tanto, si recibimos un error de Frame, hay que volver a
                            ' empezar para recibir la Señal de comienzo de trama.
        If cferr <> 0 Then
                          DMX_Estado = DMX_ESPERA_BYTE
                     Else
                          If DatoRX = 0 Then
                                             ' Llegados a este punto, ya hemos recibido el Byte Start=0
                                             ' y comenzamos la trama de valores DMX.
                                              DMX_Indice = 0
                                              DMX_Estado = DMX_RECEPCION_DATOS
                                        Else
                                              ' Si el dato recibido no es 0, volvemos a empezar
                                              DMX_Estado = DMX_ESPERA_BREAK
                          EndIf
        EndIf
       
      Case DMX_RECEPCION_DATOS
                            ' En este estado estamos recibiendo la trama de datos DMX
                            ' Si Se detecta un error de Frame es que ha habido un error y estamos
                            ' al principio
        If cferr <> 0 Then
                         If DatoRX = 0 Then
                                           DMX_Estado = DMX_ESPERA_START
                                       Else
                                           DMX_Estado = DMX_ESPERA_BYTE
                         EndIf 
                     Else
       
                         ' Almacenamos el dato recibido en nuestro array
                         TramaDMX[DMX_Indice] = DatoRX
                         
                         ' Si ha llegado al final de la capacidad, cambiamos al estado de espera
                         ' de nueva trama
                         If DMX_Indice >= TotalCanales Then
                                                           DMX_Estado = DMX_ESPERA_BREAK
                         EndIf
                          Inc DMX_Indice
                           
        EndIf
    End Select   
  Wend
salir: 
Context Restore