Can defines be changed with port input?


Closed Thread
Results 1 to 13 of 13

Hybrid View

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

    Default Can defines be changed with port input?

    Hello Again Everyone,
    Is it possible to alter <h4>DEFINES</h4> by assigning an alias or variable to their value and then making them subject to port input?
    I want to alter the DEFINE HSER_SPBRG and LCD lines = X defines by switching port inputs, but I get assembler errors if I try method listed below.
    Thank You for your patience, and help.
    Joe



    DEFINE HSER_SPBRG BAUD ' FOR 20MHZ 129 = 2400, 32=9600,25 @ 4 for 2400
    define BAUD Var
    BAUD = 129
    if PortB.3 =1 then
    BAUD = 32

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Wink Assembler !!!

    Hi, Joe

    As DEFINEs write to special registers or PBP constants ... you could consider it's "a kind" of CON statement !!!

    for values, a look to PBPxx.lib and the function listing could give you the value name ... in order you to change it.

    For registers, It wil be much better to change their values Through assembler ( As DEFINEs do ...) : Addressing them directly ...

    But Think to disable the concerned peripheral before any change ... or the mix might be funny ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    You don't need to change defines to change the baud rate. In PBP, the baud rate generator gets set once, at the beginning of the program. Your program can change it any time later by writing to the SPBRG register. I switch between baud rates all the time in my programs.

    Just remember - when using the UART, your program writes the output buffer and moves on, which means that you can still be outputting a byte many instructions after the HSEROUT. You should wait at least two byte-times after any HSEROUT command before you change the baud rate.
    Charles Linquist

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


    Did you find this post helpful? Yes | No

    Default Like This ?

    Quote Originally Posted by Charles Linquis
    You don't need to change defines to change the baud rate. In PBP, the baud rate generator gets set once, at the beginning of the program. Your program can change it any time later by writing to the SPBRG register. I switch between baud rates all the time in my programs.

    Just remember - when using the UART, your program writes the output buffer and moves on, which means that you can still be outputting a byte many instructions after the HSEROUT. You should wait at least two byte-times after any HSEROUT command before you change the baud rate.
    Hi Charles,
    Happy Thanksgiving to you and all who share this forum!
    I am thankful to all who post here.

    So are you saying, the statement posted below:
    <h4>DEFINE HSER_SPBRG 32 ' __ _ FOR 20MHZ 129 = 2400, 32=9600,25 @ 4 for 2400, </h4> might be written as something like:<h4> IF PortB.n = 1
    THEN HSER_SPBRG = 32
    ELSE
    HSER_SPBRG = 129</h4>
    JS

    EDIT
    AHHHH SOOO
    I see, just define it to your default and change it later with SPBRG = "new setting number"
    <h3>THANKS CHARLES !</h3>
    Last edited by Archangel; - 23rd November 2006 at 22:47.

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


    Did you find this post helpful? Yes | No

    Default

    SPBRG is the USART register. so just writing to it change the baudrate.

    SPBRG=x
    SPBRG=y
    '
    '
    '
    and so on

    AND you could also skip all DEFINEs, just write to the according register... as the PICMultiCalc .

    Code:
    RCSTA = $90 ' Enable serial port & continuous receive
    TXSTA = $24 ' Enable transmit, BRGH = 1
    SPBRG = 129 ' 9600 Baud @ 0.16%
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default Defining Question

    Quote Originally Posted by mister_e
    AND you could also skip all DEFINEs, just write to the according register... as the PICMultiCalc .
    Thank You mister_e,
    so many subtel little turns and twists to learn. Can you answer this?
    If I define
    Code:
    DEFINE LCD_LINES 2
    and send
    Code:
    serout PortB.4,T9600,[254,128,"9600 baud line 1~"] '128 so as not to add space
    pause 100
    serout PortB.4,T9600,[254,192,"9600 baud line 2~"] 
    pause 100
    serout PortB.4,T9600,[254,148,"9600 baud line 3~"] 
    pause 100
    serout PortB.4,T9600,[254,212,"9600 baud line 4~"]
    pause 100
    It still displays all 4 lines as if define was set to 4?
    JS

Similar Threads

  1. Matrix Keypad routine
    By mister_e in forum Code Examples
    Replies: 134
    Last Post: - 18th September 2022, 20:30
  2. Input and Output on same Port
    By Frozen001 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th November 2008, 18:46
  3. Accessing Portion of Input Port
    By Frozen001 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 24th October 2008, 16:33
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  5. Timing input pulses and re-outputting them
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th February 2007, 01:50

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