User selectable baud rate


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1

    Default Re: User selectable baud rate

    Hi all here is the code I use now and it works, 48M crystal on a PIC18F4550
    Next will be parity, I will copy the code again when it works

    If bRate = 0 THEN
    RCSTA = $90 ' Enable serial port & continuous receive
    TXSTA = $24 ' Enable transmit, BRGH = 1
    SPBRG = 225 ' 9600 Baud @ 0.0%
    SPBRGH = 4
    BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
    ENDIF

    If bRate = 1 THEN
    RCSTA = $90 ' Enable serial port & continuous receive
    TXSTA = $24 ' Enable transmit, BRGH = 1
    SPBRG = 112 ' 19200 Baud @ 0.0%
    SPBRGH = 2
    BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
    ENDIF

    If bRate = 2 THEN
    RCSTA = $90 ' Enable serial port & continuous receive
    TXSTA = $24 ' Enable transmit, BRGH = 1
    SPBRG = 56 ' 38400 Baud @ -0.16%
    SPBRGH = 1
    BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
    ENDIF

    If bRate = 3 THEN
    RCSTA = $90 ' Enable serial port & continuous receive
    TXSTA = $20 ' Enable transmit, BRGH = 0
    SPBRG = 51 ' 57600 Baud @ 0.16%
    SPBRGH = 0
    BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
    ENDIF

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818

    Default Re: User selectable baud rate

    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3

    Default Re: User selectable baud rate

    Thanks for this I had a look and it could have saved me a few hours - will definitely remember it now.
    I have another question in my quest for user select ability :is there some were I can read up on what the PBP command HSER_EVEN does?
    I have set it up now for 8 and 9 bit operation but as soon as I add HSER_EVEN or ODD even in if commands every thing stops it is as if a define is processed no matter what.

    Any thoughts on this

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631

    Default Re: User selectable baud rate

    defines are set in concrete when your program is compiled ,they cannot be used to alter precompiled code at all '
    if you wish to change parity or bit length on the fly you will need to write your own version of hserin/hserout
    2.3 DEFINEs
    The DEFINE keyword in PBP is used to set parameters for compilation and
    assembly. This should not be confused with #DEFINE, which is used for
    conditional compilation. Further explanation of DEFINE and how it works can be
    found at the end of this section.
    before you ask

    The #DEFINE directive creates a compile-time constant and, optionally, assigns a
    value to the constant.

  5. #5

    Default Re: User selectable baud rate

    Thanks Richard
    Just a question from what manual did you get the quote I had a look in the manual I got when I bought PBP and it does not match, is there a advance manual for PBP ?

  6. #6
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154

    Default Re: User selectable baud rate

    He is probably on v3 and you are on v2.6 on less (like me).

    Robert

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631

    Default Re: User selectable baud rate

    Robert is right , the excerpt is from the pbp3 online pdf .
    I had a look at my old pbp2.6 printed book and its definitely not as informative on this issue , I hope you get the concept though
    any defines are set in concrete after compliation and not really expected to be alterable at runtime

Similar Threads

  1. RS232 Baud Rate
    By gadelhas in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 10th August 2010, 00:06
  2. MCLoader baud rate
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 14th July 2010, 01:41
  3. Baud rate calculation
    By Demon in forum Serial
    Replies: 12
    Last Post: - 21st July 2006, 22:02
  4. Detect baud rate
    By Dick M in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 2nd July 2005, 21:10
  5. User Selectable LED Brightness
    By Tissy in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 10th April 2005, 18:24

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