Dear Friends im new in this forum , im a DJ and i interested with pic programming ,
İ want to make my own device for light intensty (PWM) controls at home but i have some problem on my programs i use pbp 2,47 and mcs2300 and PIC16F877

.Before i writte my problem i have looked this forum but couldt find it …

İ want to make a device to make control lights by the dmx512 signal , i found a code in this forum

But my device must have 4 chanel and 4 out ? i want to contlrol 4 lights intensty between
0-255 brightness…
and when it is 4 output it means that i cant use HPWM it must be normaly pwm between 0-255 .
Can you help me or if you have any example code like this to get dmx512 signals

This Code i have found in this forum…



DEFINE OSC 20
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_SPBRG 4 ' 25000 Baud @ 20MHz, 0,0%
DEFINE HSER_BAUD 250000
DEFINE HSER_CLROERR 1 ' Clear overflow automatically



counter VAR word ' Variable de travail WORD
idleflag VAR WORD
dummy VAR WORD
RCIF VAR byte
startcode VAR WORD
aminus VAR WORD
adresse_grada VAR WORD
x VAR WORD
newlevel1 VAR WORD
ADCON0=0
ADCON1=7
adresse_grada = 2


checkdmx:

counter = 1
pulsin portc.7,0,counter 'the break signal

if counter = 0 then
idleflag = 1 'either no dmx, or break was too long to count
'return
endif


if counter < 40 then checkdmx 'watching for 'break
'if you get here, an active low pulse was detected, but it was too short.

'probably just part of the datastream. So go back and look again.

'otherwise, a valid break was found and it's time to read the start code

dummy = RCREG 'clear out any garbage which may be in the USART
dummy = RCREG
SPBRG = 0
TXSTA.2 = 0 'brgh = 0
TXSTA.4 = 0
RCSTA.7 = 1
RCSTA.6 = 0 'setting 8 bit receive mode, no parity, etc
RCSTA.4 = 0 'check the datasheet to see what all these bits do
RCSTA.4 = 1 'now, the USART is on and ready to receive

while RCIF = 0:wend 'hover here after break, before start code

startcode = RCREG 'This is the first byte received after the break

if startcode <> 0 then checkdmx 'do your own stuff here on a non-zero code

aminus = adresse_grada - 1 'address1 is my target address

for x = 1 to aminus 'set up a loop to count almost to the address
while RCIF = 0:WEND 'sit here until a byte is received
dummy = RCREG 'stash the byte somewhere unimportant
next x

newlevel1 = RCREG 'This is your target channel data
pwm portc.2, newlevel1 ,100 'i want dimming a LED on PORTC.5
RCSTA.7 = 0 'turn off the USART

goto checkdmx
return

================================================== =====
============== AND OTHER CODE FOR INTERUPT I THİNK==========
================================================== =====

DimmerCount VAR WORD ; Location in DMX string
DMXStartAddr VAR WORD ; DMX start address
DMXStartCode VAR BYTE ; DMX Start code (Dimmer=0)
Dummy VAR BYTE
DMX_State VAR BYTE ; Stage of DMX reception

Valid_Break CON 1
Valid_SC CON 2
Valid_Data CON 3

Disable

INTERRUPT_SUB:
IF OERR Then
CREN = 0
CREN = 1 ; Clear Overrun Errors
High Err_LED ; Notify user of overrun error
DMX_State=0
EndIF

IF FERR Then
FERR = 0
DMX_State=Valid_Break
Else
GoSub RX_DMX_Data
EndIF

Dummy=RCREG ; Empty UART of junk data
Resume

RX_DMX_Data:
IF DMX_State=Valid_Break Then
HSerin 20,NoData,[DMXStartCode] ; Start code of 0 = dimmer data

IF DMXStartCode=0 Then
DMX_State=Valid_SC
Else
High Err_LED ; Notify user of Error in Start Code
DMX_State=0
EndIF
EndIF

IF DMX_State=Valid_SC Then
For DimmerCount=0 TO DMXStartAddr; Count incoming data bytes (frames)
Dummy=RCREG ; Read unwanted values
Next DimmerCount
DMX_State=Valid_Data
EndIF

IF DMX_State=Valid_Data Then
HSerin 20,NoData,[STR DataBuffer\Number_Of_Channels]
DMX_State=0
EndIF

IF DMX_State=0 Then
Resume
EndIF

GoTo RX_DMX_Data

NoData:
DMX_State=0
Resume

Enable
End