News:

Let's find out together what makes a PIC Tick!

Main Menu

Dmx512 250K Baud Transmitter Demo Code

Started by dnaci, Apr 21, 2024, 09:21 AM

Previous topic - Next topic

dnaci

This code sends the portb and portd statuses to the 4th and 5th channels of the DMX512 receiver, respectively. It is a code open to development. Tested with the this receiver dmx512 and several dmx devices.

'proton basic dmx512 transmitter demo code

Device = 18F46K22
;-------------------------------------------------------------------------------
;**** Added by Fuse Configurator ****
; Use the Fuse Configurator plug-in to change these settings
Config_Start
  FOSC = HSHP    ;HS oscillator (high power > 16 MHz)
  PLLCFG = OFF    ;Oscillator used directly
  PRICLKEN = On    ;Primary clock is always enabled
  FCMEN = OFF    ;Fail-Safe Clock Monitor disabled
  IESO = OFF    ;Oscillator Switchover mode disabled
  PWRTEN = OFF    ;Power up timer disabled
  BOREN = SBORDIS    ;Brown-out Reset enabled in hardware only (SBOREN is disabled)
  BORV = 190    ;VBOR set to 1.90 V nominal
  WDTEN = OFF    ;Watch dog timer is always disabled. SWDTEN has no effect.
  WDTPS = 32768    ;1:32768
  CCP2MX = PORTC1    ;CCP2 input/output is multiplexed with RC1
  PBADEN = On    ;PORTB<5:0> pins are configured as analog input channels on Reset
  CCP3MX = PORTB5    ;P3A/CCP3 input/output is multiplexed with RB5
  HFOFST = On    ;HFINTOSC output and ready status are not delayed by the oscillator stable status
  T3CMX = PORTC0    ;T3CKI is on RC0
  P2BMX = PORTD2    ;P2B is on RD2
  MCLRE = EXTMCLR    ;MCLR pin enabled, RE3 input pin disabled
  STVREN = On    ;Stack full/underflow will cause Reset
  LVP = On    ;Single-Supply ICSP enabled if MCLRE is also 1
  XINST = OFF    ;Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
  Debug = OFF    ;Disabled
  Cp0 = OFF    ;Block 0 (000800-003FFFh) not code-protected
  CP1 = OFF    ;Block 1 (004000-007FFFh) not code-protected
  CP2 = OFF    ;Block 2 (008000-00BFFFh) not code-protected
  CP3 = OFF    ;Block 3 (00C000-00FFFFh) not code-protected
  CPB = OFF    ;Boot block (000000-0007FFh) not code-protected
  CPD = OFF    ;Data EEPROM not code-protected
  WRT0 = OFF    ;Block 0 (000800-003FFFh) not write-protected
  WRT1 = OFF    ;Block 1 (004000-007FFFh) not write-protected
  WRT2 = OFF    ;Block 2 (008000-00BFFFh) not write-protected
  WRT3 = OFF    ;Block 3 (00C000-00FFFFh) not write-protected
  WRTC = OFF    ;Configuration registers (300000-3000FFh) not write-protected
  WRTB = OFF    ;Boot Block (000000-0007FFh) not write-protected
  WRTD = OFF    ;Data EEPROM not write-protected
  EBTR0 = OFF    ;Block 0 (000800-003FFFh) not protected from table reads executed in other blocks
  EBTR1 = OFF    ;Block 1 (004000-007FFFh) not protected from table reads executed in other blocks
  EBTR2 = OFF    ;Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks
  EBTR3 = OFF    ;Block 3 (00C000-00FFFFh) not protected from table reads executed in other blocks
  EBTRB = OFF    ;Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
Config_End

;**** End of Fuse Configurator Settings ****
;-------------------------------------------------------------------------------

Declare Xtal = 20
Declare All_Digital = true
Declare Hserial_Baud = 250000      ' Set baud rate to 250000
Declare Hserial_RCSTA = %10010000  ' Enable serial port and continuous receive
Declare Hserial_TXSTA = %01100101  ' Enable transmit and asynchronous mode
Declare Hserial_SPBRG  = 4

TRISA=%11111111
TRISB=%00000000
TRISC=%10000011
TRISD=%00000000
TRISE=%00000011
PORTA=0
PORTB=0
PORTC=0
PORTD=0
PORTE=0
ADCON0 = 0x3c
ADCON1 = 0x0f
ADCON2 = %10001111
ANSELC=0

Dim tt As Byte
Dim ch[16] As Byte
PORTB.2=1
PORTD=254

main:
ch[0]=1
ch[1]=2
ch[2]=3
ch[3]=PORTD
ch[4]=PORTB
ch[5]=4

RCSTA.7= 0   'disable UART
Low PORTB.1  'low for frame start sync, Break
DelayUS 120  '88us min required, 120us is safer.
High PORTB.1 'high for mark after break
DelayUS 8    '8usec min required
RCSTA.7= 1   'Enable UART

HSerOut [0] 'DMX512 Start Code. Already includes the start bit.
DelayUS 36  'let the serial data finish
RCSTA.7= 0
High PORTB.1 'high for two stop bits and MTBF
DelayUS 4

RCSTA.7= 1
HSerOut [ch[0],ch[1],ch[2],ch[3],ch[4],ch[5],ch[6],ch[7]] 'Channels
DelayUS 36 'let the serial data finish
RCSTA.7= 0
High PORTB.1 'high for two stop bits and MTBF
DelayUS 4

DelayMS 500

ch[0]=6
ch[1]=7
ch[2]=8
ch[3]=PORTB
ch[4]=PORTD
ch[5]=9

RCSTA.7= 0   'disable UART
Low PORTB.1  'low for frame start sync, Break
DelayUS 120  '88us min required, 120us is safer.
High PORTB.1 'high for mark after break
DelayUS 8    '8usec min required
RCSTA.7= 1   'Enable UART

HSerOut [0] 'Start Code. Already includes the start bit.
DelayUS 36  'let the serial data finish
RCSTA.7= 0
High PORTB.1 'high for two stop bits and MTBF
DelayUS 4

RCSTA.7= 1
HSerOut [ch[0],ch[1],ch[2],ch[3],ch[4],ch[5],ch[6],ch[7]] 'Channels
DelayUS 36 'let the serial data finish
RCSTA.7= 0
High PORTB.1 'high for two stop bits and MTBF
DelayUS 4

DelayMS 500
GoTo main