SEROUT or HSEROUT "ODD" parity


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    Aug 2005
    Posts
    95

    Default How do you work out

    Darrel if you have time, how do you work out which is bit 13 of the mode number. I have a similar problem but I need to use even and none.

    Thanks Sphere....

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    The easiest way will be to bug mister_e for his latest PicMultiCalc. Don't tell him I said that.

    But until then, here's how to do it manually... First calculate the BAUD part for the lower 12 bits.

    (1,000,000 / baud) -20

    So for 9600 baud that's

    (1,000,000 / 9600) -20 = 84     9600 baud, NO parity, TRUE

    Now, bit 13 is equal to 8192 (2 to the 13th power [2^13])

    If you want parity to be turned ON, add 8192 to the baud.

    84 + 8192 = 8276     9600 baud, with parity, TRUE

    Note that this only turns the parity ON and OFF, it doesn't select EVEN or ODD.
    EVEN is the default parity mode, but if you want ODD parity then you have to set the SER2_ODD define.

    Then there's bit 14, which determines the polarity.
    2 to the 14th power [2^14] = 16,384

    If you add 16,384 to the previous number, the polarity will be Inverted.
    8276 + 16,384 = 24,660     9600 baud, with parity, INVERTED

    Now how do we do that without having to do the math ourselves...
    Well, we can let the compilers do it for us.
    And for good measure, we'll let it figure out the numbers for bit13 and 14 too.
    Code:
    Parity    CON 1 << 13
    Inverted  CON 1 << 14
    
    @MODE = (1000000 / 9600) - 20 + _Parity + _Inverted   
    MODE      CON EXT
    OR, if using multiple protocols...
    Code:
    @MODE1 = (1000000 / 9600) - 20 + _Parity + _Inverted  ; 9600, with parity, inverted
    MODE1      CON EXT
    
    @MODE2 = (1000000 / 19200) - 20 + _Inverted           ; 19200, no parity, inverted
    MODE2      CON EXT
    Then to use them later...
    Code:
    SEROUT2 PORTB.0, MODE1, ["Hello World!"]      ; Mode 1, 9600, with parity, inverted
    
    SEROUT2 PORTB.1, MODE2, ["Just 5 more minutes"] ; Mode 2, 19200, no parity, inverted

    OR, you can just go here and look them up in a table.

    http://www.melabs.com/resources/ser2modes.htm

    DT

  3. #3
    Join Date
    Aug 2005
    Posts
    95

    Default

    What more can I say other than give that man a cigar. Now I can use one pic chip instead of two. Thanks for your time.

    Sphere....

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898

    Default

    Quote Originally Posted by Darrel Taylor
    The easiest way will be to bug mister_e for his latest PicMultiCalc. Don't tell him I said that.
    I didn't saw, i didn't heard that
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. I2C Slave with a PIC
    By ralfmayr in forum mel PIC BASIC Pro
    Replies: 129
    Last Post: - 21st August 2016, 17:44
  2. A Serial GLCD 128x64 Simple Project
    By Oldspring in forum Off Topic
    Replies: 0
    Last Post: - 8th March 2010, 20:58
  3. Serout to serial servo
    By azmax100 in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 12th August 2009, 16:46
  4. HSEROUT and Commas, What? Help Me Understand
    By altech6983 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 20th July 2009, 19:12
  5. Keypad unlock (as in garage door possibly)
    By Fred in forum Code Examples
    Replies: 5
    Last Post: - 2nd April 2006, 04:26

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