16F876 Usart Receive


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2007
    Posts
    16

    Default 16F876 Usart Receive

    hi friends i search in the forum and found many examples thanks. i have pic 16f876 , 20 mhz osc and 1 led ,i have dmx512 lighting desk too and i want to dimm a led on dmxadres 1 (0-255 to led intensty) but there is some problem on this code it is not working. i found this code in the forum and made it again for my pic but couldnt find the problem.can you look to my code and say what is my problem here?or you can send other example code to receive dmx ..

    ' PIC 16F876 - 20MHZ OSC

    DEFINE OSC 20 ' 20 MHZ OSC
    DEFINE HSER_TXSTA 24h ' Enable transmit
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_SPBRG 4 ' 250 000 Baud @ 20MHz, 0.0%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically

    ASM
    ERRORLEVEL -306, -302
    ENDASM

    ADCON0 = 0
    ADCON1 = 7

    counter var word
    idleflag var word
    dummy var word
    RCIF VAR BYTE
    startcode var word
    aminus var word
    adress var word
    x var word
    level1 var word
    adress = 1 ' My Start Adress


    checkdmx:
    counter = 1 ' Dummy variable
    pulsin portC.7,0,counter 'Here 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"
    dummy = RCREG
    dummy = RCREG
    SPBRG = 0
    TXSTA.2 = 0
    TXSTA.4 = 0
    RCSTA.7 = 1
    RCSTA.6 = 0
    RCSTA.4 = 0
    RCSTA.4 = 1

    while RCIF = 0: wend
    startcode = RCREG 'firs byte after break
    if startcode <> 0 then checkdmx
    aminus = adress -1

    for x = 1 to aminus
    while RCIF = 0: wend
    dummy = RCREG
    next x

    level1 = RCREG
    portC.1 = level1 'i want to dimm led on port c.1
    RCSTA.7 = 0

    goto checkdmx
    return

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    level1 = RCREG
    portC.1 = level1 'i want to dimm led on port c.1
    RCSTA.7 = 0


    What exactly is the line above supposed to accomplish? and/or what is portC.1 doing for you with the above program?

  3. #3
    Join Date
    Mar 2007
    Posts
    16


    Did you find this post helpful? Yes | No

    Default dmx

    thanks.

    portc.1 is for the led i will make a led dimmer.(0-255 = %0 -%100 intensty)

    but there is some problem on the code i think.

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I do not see RCREG defined as a variable.
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Mar 2007
    Posts
    16


    Did you find this post helpful? Yes | No

    Default dmx

    thanks for your qick answer friend .
    i was looking for a example code in this forum and saw many examples and wanted to make it for my pic 16F876 i have forund that code here in the forum and it was and also they said that it is working code.but can you say where is my problem on that code it is not working

    http://www.picbasic.co.uk/forum/show...ghlight=dmx%2A

  6. #6
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default You did not answer skimask

    Hi,
    level1 = RCREG
    portC.1 = level1 'i want to dimm led on port c.1
    RCSTA.7 = 0
    RCREG is the hardware USART receive register (SFR). You are trying to dump its value (dimming value) to a Port PIN C.1 . You should use a PWM to achieve this. Your checkdmx routine waits for a valid address and then grabs the byte being received. Use the Hardware PWM unit to make your life easier.
    Regards

    Sougata

  7. #7
    Join Date
    Mar 2007
    Posts
    16


    Did you find this post helpful? Yes | No

    Default dmx

    thanks for answer and can you say me how to use it ? i dont know cause ima new user on pbp

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by syscoder View Post
    thanks.

    portc.1 is for the led i will make a led dimmer.(0-255 = %0 -%100 intensty)

    but there is some problem on the code i think.
    You do know that you aren't going to dim anything using just portc.1 and turning it on and off. You have to use a PWM output or some sort of software driven PWM...change the duty cycle. Just sending the intensity (0-255, a byte value) to portc.1 (a bit value) isn't going to do anything for you...

    And I'm done answering your multiple questions in multiple forums about the same thing...

Similar Threads

  1. How to receive stream of bytes using PIC USART
    By unifoxz in forum mel PIC BASIC Pro
    Replies: 34
    Last Post: - 20th June 2009, 10:38
  2. Replies: 6
    Last Post: - 31st August 2007, 09:31
  3. problem with USART
    By leemin in forum Serial
    Replies: 4
    Last Post: - 11th December 2006, 17:56
  4. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07
  5. receive ASCII with usart
    By harryweb in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 9th February 2004, 08:57

Members who have read this thread : 1

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