Académique Documents
Professionnel Documents
Culture Documents
DMX protocol
Goto page Previous 1, 2
Author Message
Code:
/************************************************************************
* FUSES *
* NOPROTECT=Code not protected from reading *
* CCP2C1=CCP2 input/output multiplexed with RC1 *
* NODEBUG=No Debug mode for ICD *
* BORV20=Brownout reset at 2.0V *
* MCLR=Master Clear pin enabled *
* Habilitamos el pin de clear *
* NOWDT=No Watch Dog Timer *
* INTRC_IO=Internal RC Osc, no CLKOUT *
* NOIESO=Internal External Switch Over mode disabled *
* NOFCMEN=Fail-safe clock monitor disabled *
* Desabilitamos la opcion de deteccion de que cuando hay una perdida *
* de clock externo el clock interno proporciona los clock al sistema*
* NOBROWNOUT=Reset when brownout detected *
************************************************************************/
#include <16F767.h>
#fuses NOPROTECT,CCP2C1,NODEBUG,MCLR,NOWDT,HS,NOBROWNOUT
//#use delay(clock=4000000) #use delay(clock=16000000)
#include <string.h>
#include <stdio.h>
/************************************************************************
* Puertos I/O *
************************************************************************/
struct PA_pin_map {
boolean unusedRA0; //bit 0
1 от 6 01.3.2007 г. 11:05
CCS :: View topic - DMX protocol http://ccsinfo.com/forum/viewtopic.php?t=17513&postdays=0&p...
boolean unusedRA1;
boolean unusedRA2;
boolean unusedRA3;
boolean unusedRA4;
boolean unusedRA5; //bit 4
} Puerto_A;
#byte Puerto_A = 5
struct PB_pin_map {
boolean unusedRB0; //bit 0
boolean unusedRB1;
boolean unusedRB2;
boolean unusedRB3;
boolean unusedRB4;
boolean unusedRB5; //canal pwm
boolean unusedRB6;
boolean unusedRB7; //bit8
} Puerto_B;
#byte Puerto_B = 6
struct PC_pin_map {
boolean unusedRC0; //bit 0
boolean unusedRC1; //canal pwm
boolean PWM1; //canal pwm
boolean unusedRC3;
boolean unusedRC4;
boolean test_osc;
boolean unusedRC6;
boolean rx; //bit8
} Puerto_C;
#byte Puerto_C = 7
#CASE
#byte porta=0x05
#byte portb=0x06
#byte portc=0x07
/************************************************************************
* Registros USART *
************************************************************************/
/************************************************************************
* Variables globales *
************************************************************************/
int1 Check_levels=0;
2 от 6 01.3.2007 г. 11:05
CCS :: View topic - DMX protocol http://ccsinfo.com/forum/viewtopic.php?t=17513&postdays=0&p...
/************************************************************************
* Declaracion de funciones *
************************************************************************/
void Interrupt_USART_Rx(void);
#int_rda
void Interrupt_USART_Rx(void)
{
#define WAIT_FOR_NEXT_BYTE 0
#define WAIT_FOR_BREAK 1
#define WAIT_FOR_START 2
#define RECEIVE_DATA_INT 3
#define RECEIVE_DATA 4
union
{
unsigned char byte;
struct {
unsigned char RX9D:1; //bit0
unsigned char OERR:1;
unsigned char FERR:1;
unsigned char ADDEN:1;
unsigned char CREN:1;
unsigned char SREN:1;
unsigned char RX9:1;
unsigned char SPEN:1; //bit7
} bits ;
}rcsta;
while (RCIF) {
rcsta.byte = RCSTA;
data = RCREG;
switch (Rx_State)
{
case WAIT_FOR_NEXT_BYTE:
if (!rcsta.bits.FERR)
Rx_State = WAIT_FOR_BREAK;
break;
case WAIT_FOR_BREAK:
if (rcsta.bits.FERR) //Miramos si hay un error de trama
{
if (!data)
Rx_State = WAIT_FOR_START;
}
break;
case WAIT_FOR_START:
if (rcsta.bits.FERR)
Rx_State = WAIT_FOR_NEXT_BYTE;
3 от 6 01.3.2007 г. 11:05
CCS :: View topic - DMX protocol http://ccsinfo.com/forum/viewtopic.php?t=17513&postdays=0&p...
else
{
if (!data)
{
if(DMX_512_Offset==1)
{
ptr_Rx=Rx_Buffer;
Rx_State = RECEIVE_DATA;
}
else
{
Rx_State = RECEIVE_DATA_INT;
DMX_512_Count=1;
}
}
}
break;
case RECEIVE_DATA_INT:
if (rcsta.bits.FERR)
{
if (!data)
Rx_State = WAIT_FOR_START;
else
Rx_State = WAIT_FOR_NEXT_BYTE;
}
else
{
DMX_512_Count++;
if( DMX_512_Count == DMX_512_Offset)
{
ptr_Rx=Rx_Buffer;
Rx_State = RECEIVE_DATA;
}
}
break;
case RECEIVE_DATA:
if (rcsta.bits.FERR)
{
if (!data)
Rx_State = WAIT_FOR_START;
else
Rx_State = WAIT_FOR_NEXT_BYTE;
}
else
{
*ptr_Rx=data;
ptr_Rx++;
if( ptr_Rx > &Rx_Buffer[MAX_PWMS-1] )
{
Rx_State= WAIT_FOR_BREAK;
Check_levels=1;
}
}
break;
}
}
return;
}
/************************************************************************
* Programa Principal *
************************************************************************/
int8 i;
int1 exit; //var used para salir de bucles
//////////////////Configuramos los puertos ////////////////////////
set_tris_a(0x00);
set_tris_b(0x00);
set_tris_c(0b10000000);
4 от 6 01.3.2007 г. 11:05
CCS :: View topic - DMX protocol http://ccsinfo.com/forum/viewtopic.php?t=17513&postdays=0&p...
SPEN=1; // serial port enabled - rc7/rx/dt , rc6/tx/ck pins as serial port pins
*/
SPBRG=0x00; // SPBRG=0 implica que a 16Mhz el baudrate=250.000
BRGH=0; // BRGH=0 implica Low speed.
SYNC=0; // enable aSYNChronous reception
SPEN=1; // serial port enabled - rc7/rx/dt , rc6/tx/ck pins as serial port pins
/////////////////////////////////////////
setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);
setup_ccp3(CCP_PWM);
setup_timer_2(T2_DIV_BY_16,255,1); //1khz a 16Mhz
current_value1=valorpwm1[0] ;
current_value2=valorpwm1[0] ;
current_value3=valorpwm1[0] ;//Inicializamos con un valor de duty de 0 -> leds off
exit=0;
while (1)
{
if (Check_levels)
{
Check_levels=0;
level1=Rx_Buffer[DMX_512_Offset-1];
level2=Rx_Buffer[DMX_512_Offset];
level3=Rx_Buffer[DMX_512_Offset];
calcul_duty1(level1,current_value1);
calcul_duty2(level2,current_value2);
calcul_duty3(level3,current_value3);
}//cierra main
thanks!
What's the problem? What are you trying to do? It doesn't appear that you posted all the code.
Joined: 07 Sep 2003
Posts: 3511 But none of this looks right
Location: Atlanta, GA Code:
current_value1=valorpwm1[0] ;
current_value2=valorpwm1[0] ;
current_value3=valorpwm1[0] ;//Inicializamos con un valor de duty de 0 -> leds off
Code:
5 от 6 01.3.2007 г. 11:05
CCS :: View topic - DMX protocol http://ccsinfo.com/forum/viewtopic.php?t=17513&postdays=0&p...
exit=0;
while (1)
{
if (Check_levels)
{
Check_levels=0;
level1=Rx_Buffer[DMX_512_Offset-1];
level2=Rx_Buffer[DMX_512_Offset];
level3=Rx_Buffer[DMX_512_Offset];
What this about? DMX_512_Offset is the DMX channel to start with. With a value of 5, you will
not receive channels 1-4. So Rx_Buffer[0] will contain channel 5's level. Your code sets level1 =
channel 9 and level2 and level3 = channel 10? I don't think this is what you want.
Code:
calcul_duty1(level1,current_value1);
calcul_duty2(level2,current_value2);
calcul_duty3(level3,current_value3);
}//cierra main
Don't know what this is for nor to I have the code for it.
http://www.freeweb.com.tw/sd/upload/product/File/Product/DM118X%20_SD.pdf
http://www.skylinedynamics.com/
6 от 6 01.3.2007 г. 11:05