SEROUT or HSEROUT "ODD" parity


Closed Thread
Results 1 to 8 of 8
  1. #1

    Default SEROUT or HSEROUT "ODD" parity

    Hi all

    I'm suffering with a serout routine where I have to use ODD parity

    I'm using a 16F876A with several SEROUT and SEROUT2 ports

    some are 8N1 , 1 is 8O1

    If I use the define command: Define ser2_odd = 1

    Then all my serout2s are ODD parity

    Do i need to put this define infront of each Serout2 command ?

    What if I want to use ODD parity with serout instead of serout2 ?

    Thanks

  2. #2

    Default

    Still suffering, anyone who can help me ?

    I have the ODD parity working on 1 Serout2 pin, but I also need to do
    some other serout2's on other pins but with parity none

    Anyone ?

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

    Default

    The SER2_ODD define only changes the way the parity works for SERIN/OUT2. (EVEN or ODD)

    To select parity mode, you use bit 13 of the mode number. 1=parity, 0=noparity.

    So, if the parity is not turned on for that specific SEROUT2 statement, the SER2_ODD define will not have any effect.
    DT

  4. #4

    Default

    Thanks Darrel , I will give it a try

  5. #5
    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....

  6. #6
    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

  7. #7
    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....

  8. #8
    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 : 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