CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

transmit DMX

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
djprosound



Joined: 03 Aug 2010
Posts: 4

View user's profile Send private message

transmit DMX
PostPosted: Wed Aug 04, 2010 3:21 pm     Reply with quote

Hi , I have a problem with DMX sending. I want to transmit a DMX signal from a pic 18f2550. I use a 20MHz Crystal and the hardware EUSART.
I compiled this code but it doesn't work, the dmx equipment doesn't recognize it.

This is the code:

Code:

#include <18F2550.h>
#include <stdio.h>
#include <stdlib.h>

#fuses HS, WDT, NOPROTECT, PUT, BROWNOUT, LVP
#ZERO_RAM
#use delay(clock=20000000)
#use rs232( baud=250000,   xmit=PIN_C6)

#define MAX_LEVELS 512

#BYTE portc      =0x0F82
#BYTE portb      =0x0F81
#BYTE porta      =0x0F80
#byte SPBRG    = 0xFAF
#byte RCSTA    = 0xFAB   
#byte TXSTA    = 0xFAC
#byte RCREG    = 0xFAE
#byte PIR1     = 0xF9E
#byte PIE1     = 0xF9D
#byte INTCON   = 0xFF2
#byte TXREG    = 0xFAD
#byte BAUDCON  =0xFB8

#bit SPEN      = RCSTA.7   /* Serail port activado */
#bit RX9       = RCSTA.6   /* 9-bit activado */
#bit SREN      = RCSTA.5   /* En modo asyncrono no se tiene en cuenta */
#bit CREN      = RCSTA.4   /* Recepcion continua activada */
#bit ADDEN     = RCSTA.3
#bit FERR      = RCSTA.2   /* Frame error bit */
#bit OERR      = RCSTA.1   /* Overrun error bit */
#bit RX9D      = RCSTA.0   /* El noveno bit */

#bit TXIE      = PIE1.4
#bit RCIF      = PIR1.5
#bit RCIE      = PIE1.5

#bit GIE       = INTCON.7
#bit PEIE      = INTCON.6


#bit TXEN     = TXSTA.5
#bit TX9      = TXSTA.6
#bit TX9D     = TXSTA.0
#bit BRGH     = TXSTA.2
#bit SYNC     = TXSTA.4
#bit TRMT      =  TXSTA.1

BOOLEAN Send_Break = TRUE;       
BOOLEAN Send_Start_Code = FALSE;
 int8 c=0; /*just for test- all ch at 0 */

#INT_TBE
void Tx_Data(void)
{
  static unsigned int32 tx_index = 0;
 
  TXREG = c;
  tx_index++;   
  if (tx_index >= MAX_LEVELS)
  {
    /* Disable the interrupt if we are done transmitting */
    disable_interrupts(INT_TBE);
    tx_index = 0;
    Send_Break = TRUE;
    }
}

setup_oscillator(OSC_20MHZ);
void main(void)
{
 
   set_tris_c(0b10111111);
   
   /*Se setea la USART*/
   SPBRG=4;             /* SPBRG=0 implica que a 4Mhz el baudrate=250.000*/
   BRGH=1;                 /* BRGH=1 implica High speed*/
   SYNC=0;               
   SPEN=1;                 
   TXEN=0;
   TXIE=0; 
   CREN=1;
   RCIE=0;
   TX9D=1;
   TX9=1;
 
   /*Se setean las interrupciones*/
   GIE=1;            /*Activa todas las interrucpiones globales*/
   PEIE=1;           /*Activa las interrupciones de perifericos*/
   RCIE=1;           /*Activa las interrupciones de recepcion*/
   
    disable_interrupts(INT_TBE);
  while(1)
  {   
    if (Send_Break )
    {   
      disable_interrupts(INT_TBE);
      TXEN=0;   
      bit_clear(portc, 0x06);
   
      delay_us(88);
      Send_Break = FALSE;
      Send_Start_Code=TRUE;
    }
      else if(Send_Start_Code)
   {
      Send_Start_Code=FALSE;
      bit_set(portc, 0x06);
      delay_us(8);         
      enable_interrupts(INT_TBE);
      TXEN=1;
      set_tris_c(0b10111111);
    }
   
}

}
 


Thanks!

Emi
djprosound



Joined: 03 Aug 2010
Posts: 4

View user's profile Send private message

PostPosted: Wed Aug 04, 2010 9:14 pm     Reply with quote

Hi, I've been working on a DMX transmitter with a pic18f2550. Finally I could send the data correctly, I tested it with an OS and it looks very good. It's based on a Mark help-code, and I finished it. This is my tiny contribution.

Sorry for my bad english.
Code:

#include <18F2550.h>
#include <stdio.h>
#include <stdlib.h>

#fuses HS, WDT, NOPROTECT, PUT, BROWNOUT, LVP

#use delay(clock=20000000)
#use rs232( baud=250000,   xmit=PIN_C6,  rcv=PIN_C7)
setup_oscillator(OSC_20MHZ);
/*****************************************************************************/
/*                       ASIGNACION DE REGISTROS                             */
/*****************************************************************************/

/*Registro de Control y Estado del modulo de Transmision*/
#byte TXSTA    =     0xFAC
#bit  TX9D     =     TXSTA.0  /*Noveno bit de transmision*/
#bit  TRMT     =     TXSTA.1  /*Estado del TSR. Solo lectura. 1> VACIO 0>LLENO*/
#bit  BRGH     =     TXSTA.2  /*En modo ASYNC 1>HS Baud 0>LS Baud*/
#bit  SENDB    =     TXSTA.3  /*Envio de Break de 12bits - NO APTO DMX*/
#bit  SYNC     =     TXSTA.4  /*Modo de sincronismo 1>SYNC 0>ASYNC*/
#bit  TXEN     =     TXSTA.5  /*Transmision 1>ENABLE 0>DISABLE*/
#bit  TX9      =     TXSTA.6  /*Modo de transmision en 9-bits 1>9BITS 0>8BITS */
#bit  CSRC     =     TXSTA.7  /*Fuente de reloj. No importa en ASYNC*/
/*Registro de Control y Estado del modulo de Recepcion*/
#byte RCSTA    =     0xFAB
#bit  RX9D     =     RCSTA.0  /*Noveno bit de recepcion*/
#bit  OERR     =     RCSTA.1  /*Error de OVERRUM 1>ERROR 0>OK*/
#bit  FERR     =     RCSTA.2  /*Error de TRAMA  1>ERROR 0>OK*/
#bit  ADDNEN   =     RCSTA.3  /*Deteccion de direccion por 9-bit 1>ON 0>OFF*/
#bit  CREN     =     RCSTA.4  /*Recepcion Continua 1>ENABLE 0>DISABLE*/
#bit  SREN     =     RCSTA.5  /*Recepcion por bit 1>ENABLE 0>DISABLE*/
#bit  RX9      =     RCSTA.6  /*Recepcion de 9bits 1>9BITS 0>8BITS*/
#bit  SPEN     =     RCSTA.7  /*Activacion Puerto Serie 1>ON 0>OFF*/
/*Registro de control del Baud Rate*/
#byte BAUDCON  =     0xFB8
#bit  ABDEN    =     BAUDCON.0/*Auto Baud Rate 1>ON 0>OFF*/
#bit  WUE      =     BAUDCON.1/*WakeUP 1>ON 0>OFF*/
#bit  BRG16    =     BAUDCON.3/*BR16 Bits 1>1BITS 0>8BITS*/
#bit  SCKP     =     BAUDCON.4/*Polaridad de Reloj No usada en ASYNC*/
#bit  RCIDL    =     BAUDCON.6/*Recepcion IDLE  1>IDLE 0>ACTIVE*/
#bit  ABDOVF   =     BAUDCON.7/*Auto Baud Rate Status*/
/*Registro de interrupciones INTCON*/
#byte INTCON   =     0xFF2
#bit  RBIF     =     INTCON.0/**/
#bit  INT0IF   =     INTCON.1/**/
#bit  TMR0IF   =     INTCON.2/**/
#bit  RBIE     =     INTCON.3/**/
#bit  INT0IE   =     INTCON.4/**/
#bit  TMR0IE   =     INTCON.5/**/
#bit  PEIE     =     INTCON.6/*Int de perifericos 1>ENABLE 0>DISABLE*/
#bit  GIE      =     INTCON.7/*Int Globales 1>ENABLE 0>DISABLE*/
/*Registros (PIR1 - PIE1) de interrupcion de perifericos*/
#byte PIR1     =     0xF9E
#bit  TMR1IF   =     PIR1.0 /**/
#bit  TMR2IF   =     PIR1.1 /**/
#bit  CCP1IF   =     PIR1.2 /**/
#bit  SSPIF    =     PIR1.3 /*FLAG SSP 1>Tx/Rx completada 0>Esperando Tx/Rx (*) */
#bit  TXIF     =     PIR1.4 /*FLAG SSP 1>TXREG Vacio 0>TXREG Lleno (*) */
#bit  RCIF     =     PIR1.5 /*FLAG SSP 1>RCREG Vacio 0>RCREG Lleno (*) */
#bit  ADIF     =     PIR1.6 /**/
#bit  SPPIF    =     PIR1.7 /**/
#byte PIE1     =     0xF9D
#bit  SSPIE    =     PIE1.3 /*MSSP 1>ENABLE 0>DISABLE*/
#bit  TXIE     =     PIE1.4 /*Activacion de inter Tx 1>ENABLE 0>DISABLE*/
#bit  RCIE     =     PIE1.5 /*Activacion de inter Rx 1>ENABLE 0>DISABLE*/
#byte RCON     =     0xFD0
#bit  IPEN     =     RCON.7 /*Prioridad 1>ON 0>OFF*/
/* (*) Debe ser reseteado por SOFTWARE */
/*Funciones de Registro*/
#byte SPBRG    =     0xFAF  /*Generador del Baud Rate*/
#byte RXREG    =     0xFAE  /*Registro de Recepcion*/
#byte TXREG    =     0xFAD  /*Registro de Transmision*/
/*Registros asociados a los puertos*/
#byte portc=0x0F82

/*****************************************************************************/
/*                          VARIABLES GLOBALES                               */
/*****************************************************************************/
BOOLEAN Send_Break = TRUE;       
BOOLEAN Send_Start = FALSE;
/*Este es un ejemplo de un arrgelo con valroes DMX, pero tranquilamente podria ser
la lectura de un puerto ADC o lo que fuere*/
static unsigned int8 tx_DMX[512]={254,100,0,254,90,254,200,254,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                    0,0,0,0,0,0,0,0,0,0,0,0};

/*****************************************************************************/
/*                            INTERRUPCIONES                                 */
/*****************************************************************************/
#INT_TBE
void tx_DMX512(void)
{
      static unsigned int16 i=0;  /*Contador de elementos enviados*/
       
      TXREG=tx_DMX[i];    /*Envio de la informacion*/
      i++;                   
      /*Verifico si se enviaron los 512 camales. De ser asi desactivo la INT
      y activo el envio del Break*/
      if(i>=512)
      { 
        i=0;
        TXIE=0;    /*Apago la interrupcion de transmision*/
        Send_Break = TRUE;
      }
}
 
/*****************************************************************************/
/*                           FUNCION PRINCIPAL                               */
/*****************************************************************************/
void main(void)
{   
      /*SETEO DE LA EUSART*/
      /*Funciones de Registro Princiales*/
      SPBRG    =   19; /*Generador del Baud Rate*/
      BRGH     =    1; /*En modo ASYNC 1>HS Baud 0>LS Baud*/
      SYNC     =    0; /*Modo de sincronismo 1>SYNC 0>ASYNC*/
      BRG16    =    1; /*BR16 Bits 1>16BITS 0>8BITS*/
      SPEN     =    0; /*Activacion Puerto Serie 1>ON 0>OFF*/
      TXIE     =    0; /*Activacion de inter Tx 1>ENABLE 0>DISABLE*/
      TXEN     =    0; /*Transmision 1>ENABLE 0>DISABLE*/
      TX9      =    1; /*Modo de transmision en 9-bits 1>9BITS 0>8BITS */
      /*Control y Estado del modulo de Transmision*/
      TX9D     =    1; /*Noveno bit de transmision*/     
      SENDB    =    0; /*Envio de Break de 12bits - NO APTO DMX*/   
      /*Control y Estado del modulo de Recepcion*/
      RX9D     =    1; /*Noveno bit de recepcion*/     
      ADDNEN   =    0; /*Deteccion de direccion por 9-bit 1>ON 0>OFF*/
      CREN     =    1; /*Recepcion Continua 1>ENABLE 0>DISABLE*/
      SREN     =    0; /*Recepcion por bit 1>ENABLE 0>DISABLE*/
      RX9      =    1; /*Recepcion de 9bits 1>9BITS 0>8BITS*/
      /*Registro de control del Baud Rate*/
      ABDEN    =    0; /*Auto Baud Rate 1>ON 0>OFF*/
      WUE      =    0; /*WakeUP 1>ON 0>OFF*/
      SCKP     =    0; /*Polaridad de Reloj No usada en ASYNC*/
      RCIDL    =    0; /*Recepcion IDLE  1>IDLE 0>ACTIVE*/
      /*Registro de interrupciones INTCON*/
      PEIE     =    0; /*Int de perifericos 1>ENABLE 0>DISABLE*/
      GIE      =    0; /*Int Globales 1>ENABLE 0>DISABLE*/
      /*Registros (PIR1 - PIE1) de interrupcion de perifericos*/
      SSPIE    =     0; /*MSSP 1>ENABLE 0>DISABLE*/
      RCIE     =     0; /*Activacion de inter Rx 1>ENABLE 0>DISABLE*/
      IPEN     =     0; /*Prioridad 1>ON 0>OFF*/
     
      delay_ms(500); /*Retardo de arranque*/
      while(1)
      {
         if(Send_Break )
         {
           SPEN=0;              /*Desactivo el Puerto Serie*/
           PEIE=0;              /*Apago las interrupciones de perifericos*/
           GIE=0;               /*Apago las interrupciones globlaes*/
           TXIE=0;              /*Apago la interrupcion de transmision*/
           TXEN=0;
           /*Se genera el BREAK de 88us seguido del MAB*/
           bit_clear(portc,0x06);
           delay_us(88);         
           output_high(PIN_C6);
           delay_us(100);   
           
           Send_Break = FALSE;       
           Send_Start = TRUE;
         }
         else if(Send_Start)
         {               
           Send_Start = FALSE; 
           /*Enciendo nuevamente el puerto y activo las interrupciones*/
           SPEN=1;
           TXIE=1;             /*Enciendo la interrupcion de transmision*/
           TX9=1;              /*Transmision de 9 bits*/
           TXEN=1;             /*Habilito la transmision*/
           TX9D=1;             /*Seteo del noveno bit en 1. Lo uso como un uno de los dos bit de stop*/           
           /*Se transmite el Byte de inicio*/
           TXREG=0;            /*Cargo en el registro el valor 0. Es el Start Code*/
           PEIE=1;             /*Enciendo las interrupciones de perifericos*/
           GIE=1;              /*Enciendo las interrupciones globlaes*/                             
         }
      }
}


Emi
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group