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 CCS Technical Support

Problems about programming DMX in PIC in C

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



Joined: 17 Oct 2007
Posts: 1

View user's profile Send private message

Problems about programming DMX in PIC in C
PostPosted: Wed Oct 17, 2007 10:43 am     Reply with quote

I'm using a PIC18F2420 using MPLAB IDE with C18 C compiler.
What I want to do, is receiving the information of DMX. I made a code like the others that you can find in this forum, following the same ideas, but it doesn't work. The first problem is that the usart never generates a FERR error to detect the break. if you have enough time, have a look and tell me what is wrong. If you want to modify it, do it!

Thanks for your attention!

The code is:

Code:
#include <p18f2420.h>
#include <stdio.h>
#include <string.h>
#include <delays.h>
//-------------------------Confiurations-----------------------------------
#pragma config OSC = HS
#pragma config WDT = OFF
#pragma config LVP = OFF
#pragma config PWRT= OFF
//-------------------------Inicializacion----------------------
#define NUM_CH 2
#define ESPERA_BREAK 0
#define ESPERA_START 1
#define REBRE_DATA 2
char rx_status;
char DMX_DIR;
char DMX_VAL;
char CH_DIR[NUM_CH];
char CH_VAL[NUM_CH];
int j;
//-------------------------declarations of functions-----------------------------------
void isr_high(void);

//-------------------------Funtions-------------------------------------------------

void actualitza_valors(char DMX_DIR, char DMX_VAL, char CH_DIR[], char CH_VAL[])
 {
 int i=0;
 for (i=0;i<NUM_CH> 12)
       {
       rx_status=ESPERA_BREAK;
       }
      }
     else
      {
      rx_status=ESPERA_BREAK;
      }
     }
   break;
   }
  RCSTAbits.CREN = 0;   
  RCSTAbits.CREN = 1;   
  PIR1bits.RCIF=0;   
  }
 INTCONbits.GIEH=1;     
 }
//------------------------Programa Principal-----------------------------------------
void main(void)
{
//------------------------Configuració de les interrupcions---------------------------
RCONbits.IPEN=1;       // Habilitem les prioritats de les interrupcions
INTCONbits.GIEH=1;       // Habilitem les interrupcions de prioritat alta     
INTCONbits.GIEL=0;      // DesHabilitem les interrupcions de prioritat baixa
//------------------------Configuració de la USART ------------------------------------
BAUDCONbits.ABDEN=0;     // Baud rate measurement disabled or completed
TXSTAbits.BRGH=1;      // High speed Baud Rate Select
BAUDCONbits.BRG16=0;     // 8-bit Baud Rate Generator (només SPBRG)
SPBRG=4;        // Càlcul per a un Baud Rate de 250000 bps -> Fosc/[16(n+1)]
RCSTAbits.SPEN=1;       // Habilitem RX com a serial port
TXSTAbits.SYNC=0;      // Usart a Asynchronous mode   
IPR1bits.RCIP=1;      // Donem high priority interrupt a la Usart
PIR1bits.RCIF=0;      // Netegem la bandera de la interrupció de la Usart
PIE1bits.RCIE=1;      // Habilitem la interrupció de recepció
RCSTAbits.RX9=1;      // Habilitem el nové bit en recepció
RCSTAbits.ADDEN=0;      // Deshabilitem la detecció d'adreces en el RX9

TXSTAbits.TXEN=0;      // Deshabilitem la transmissió
RCSTAbits.CREN = 0;      // DesHabilitem la recepció i netegem els errors
RCSTAbits.CREN = 1;      // Habilitem la recepció
//------------------------Configuració dels ports--------------------------------------
PORTA=0x00;
TRISA=0b11000000;
//------------------------Final de la configuració, rutina principal-------------------
rx_status=ESPERA_BREAK;
CH_DIR[0]=1;
CH_DIR[1]=2;
CH_VAL[0]=255;
CH_VAL[1]=0;
 

do {

 }while(1);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 17, 2007 10:54 am     Reply with quote

Quote:
with C18 C compiler.

Please ask your question in the Microchip C18 forum:
http://forum.microchip.com/tt.aspx?forumid=3
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