Device 16f877
xtal 20

HSERIAL_BAUD = 250000
HSERIAL_RCSTA = %10010000
HSERIAL_TXSTA = %00100000
HSERIAL_CLEAR = On

'CONFIG HS_OSC, WDT_OFF, PWRTE_OFF, BODEN_OFF, LVP_OFF, CP_OFF

ALL_DIGITAL = TRUE

Dim Sb As Byte
Dim Channel As Byte
Dim Var1[42] as byte' for (1-42) channels

delayms 100
RCSTA.7 = 1
RCSTA.6 = 0 'setting 8 bit receive mode, no parity, etc
RCSTA.4 = 0

Start:
RCSTA.4 = 0 'dis-enable serial

DMX_Break:

Sb=PulsIn portc.7,0 'measure a pulse

If Sb < = 44 Then DMX_Break '( test the pulse is greater than 88 us if not valid so return to DMX_Break and test again)

Clear RCREG 'clears rcreg twice as it can hold 2 bytes

RCSTA.4 = 1 'enable the serial to read value

For Channel = 1 To 42
Var1[Channel] = HRSin 'read value of dmx
Next Channel

goto start