'DMX Controller 'Version: 0.1 'Creation Date: 1/14/07 'Modified Date: 1/14/07 'Revisions: ' 0.1 1/14/07 Initial revision based on weeks of tinkering and protocol analysis. ' 'Notes: 'This was made to work on a PIC 16F628 chip. 'For using a 20MHz resonator... 'Set the DEFINE OSC 20 in the PBP program to tell PBP that it will be running faster than 4MHz. 'In EPICWin, uncheck Options > Update Configuration. This stops EPIC from changing back to INTRC(IN) before programming. 'Then set the Oscillator option HS for external resonator. DEFINE OSC 20 'Set oscillator in MHz RCSTA.7= 1 'Enable UART chan1 var byte chan2 var byte chan3 var byte chan4 var byte chan1 = 0 chan2 = 85 chan3 = 170 chan4 = 255 ch1toggle var bit ch1toggle = 0 ch2toggle var bit ch2toggle = 0 ch3toggle var bit ch3toggle = 0 ch4toggle var bit ch4toggle = 0 'setup hardware uart rx/tx @ 250kbaud, for DMX DEFINE HSER_RCSTA 90h '90hex: enables rx, even though we're not doing that here. DEFINE HSER_TXSTA 65h '65hex: 9-bit, tx enable, BRGH high, First bit is 0 for the Start Bit. DEFINE HSER_BAUD 250000 '250Kbps Baud DEFINE HSER_SPBRG 4 'Baud Rate Generator Register Value (0 to 255!), This seems to make each bit 4us wide which is how wide DMX bits are. LIB_dmx_out: 'This just makes all 4 channels ramp up and down for demonstration purposes. Sequencing: Pause 5 if chan1 = 255 then ch1toggle = 0 if chan1 = 0 then ch1toggle = 1 if ch1toggle = 0 then chan1 = chan1 - 1 if ch1toggle = 1 then chan1 = chan1 + 1 if chan2 = 255 then ch2toggle = 0 if chan2 = 0 then ch2toggle = 1 if ch2toggle = 0 then chan2 = chan2 - 1 if ch2toggle = 1 then chan2 = chan2 + 1 if chan3 = 255 then ch3toggle = 0 if chan3 = 0 then ch3toggle = 1 if ch3toggle = 0 then chan3 = chan3 - 1 if ch3toggle = 1 then chan3 = chan3 + 1 if chan4 = 255 then ch4toggle = 0 if chan4 = 0 then ch4toggle = 1 if ch4toggle = 0 then chan4 = chan4 - 1 if ch4toggle = 1 then chan4 = chan4 + 1 RCSTA.7= 0 'disable UART Low PORTB.2 'low for frame start sync, Break pauseus 120 '88us min required, 120us is safer. High PORTB.2 'high for mark after break pauseus 8 '8usec min required RCSTA.7= 1 'Enable UART HSEROUT [0] 'Start Code. Already includes the start bit. pauseus 36 'let the serial data finish RCSTA.7= 0 High PORTB.2 'high for two stop bits and MTBF pauseus 8 RCSTA.7= 1 HSEROUT [chan1] 'Channel 1 pauseus 36 'let the serial data finish RCSTA.7= 0 High PORTB.2 'high for two stop bits and MTBF pauseus 8 RCSTA.7= 1 HSEROUT [chan2] 'Channel 2 pauseus 36 'let the serial data finish RCSTA.7= 0 High PORTB.2 'high for two stop bits and MTBF pauseus 8 RCSTA.7= 1 HSEROUT [chan3] 'Channel 3 pauseus 36 'let the serial data finish RCSTA.7= 0 High PORTB.2 'high for two stop bits and MTBF pauseus 8 RCSTA.7= 1 HSEROUT [chan4] 'Channel 4 pauseus 36 'let the serial data finish RCSTA.7= 0 High PORTB.2 'high for two stop bits and MTBF pauseus 8 RCSTA.7= 1 Pause 5 Goto LIB_dmx_out