Decoding DMX with picbasic pro


Results 1 to 9 of 9

Threaded View

  1. #1
    Join Date
    Jan 2006
    Posts
    8

    Smile Decoding DMX with picbasic pro

    hello,

    I have studied the posts concerning dmx with picbasic, I want to dimming a led on portC.5 on a 18F452. I try this basic code but unfortunately it doesn't run.

    the dmx is converted by a driver SN75176 connected on pin 26 (RC.7/RX/DT). Please is someone can look my code for help me.

    sorry for my bad english i'm french.....
    greating

    Code:
    '****************************************************************
    '*  Name    : UNTITLED.BAS                                      *
    '*  Author  : [select VIEW...EDITOR OPTIONS]                    *
    '*  Notice  : Copyright (c) 2006 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 26/01/2006                                        *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    DEFINE OSC 16             ' for pic 18f452  
    DEFINE HSER_BAUD 250000    
    DEFINE HSER_CLROERR 1
    ASM
            ERRORLEVEL -306, -302
    ENDASM
    
    ' Variables diverves 
     
          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
       
    adresse_grada = 20
        
    'This next routine is called on a gosub from my main housekeeping loop:
    
    checkdmx:
    
    counter = 1 'just a dummy variable
    pulsin portc.7,0,counter 'here I'm looking for 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.5, newlevel1 ,100  'i want dimming a LED on PORTC.5
    RCSTA.7 = 0 'turn off the USART
    
    goto checkdmx
    return
    Last edited by ScaleRobotics; - 6th August 2010 at 15:51. Reason: added code tags

Similar Threads

  1. ICD, ICSP and Picbasic Pro
    By mwhatley in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 8th August 2024, 20:42
  2. How to configure SPI in PICBASIC PRO?
    By moogle in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 15th April 2007, 18:31
  3. Question for all that use MELABS PICBASIC PRO
    By oskuro in forum Off Topic
    Replies: 2
    Last Post: - 24th March 2005, 17:15
  4. DMX & PicBasic coding problem
    By magicmarty in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 20th September 2004, 15:35
  5. PicBasic Pro & PicBasic syntax different
    By Billyc in forum General
    Replies: 5
    Last Post: - 16th April 2004, 21:19

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts