Conditional Defines?


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    Thanks DT. I will follow your advice.
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

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


    Did you find this post helpful? Yes | No

    Default

    I am confused again. Funny how I never ran into this before...
    The below only works at OSC 32 and below.
    Code:
    RCSTA = $90   ' Enable serial port & continuous receive
    TXSTA = $20   ' Enable transmit, BRGH = 0
    SPBRG = 225   ' 2400 Baud @ 0.0%
    SPBRGH = 4
    BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
    Why does it work above OSC 32 if it is DEFINED?

    But these work with the 202 Warning. 2400 BAUD will not work like this.
    Work meaning it displays on a terminal.
    Code:
    RUN: '9600 BAUD
       RCSTA=$90:TXSTA=$20:SPBRG=77
       RCSTA.4 = 0 : RCSTA.4 = 1
       HSEROUT ["HOWDY THERE",$d,$a]
       PAUSE 250
       GOTO RUN
    Code:
    RUN: '4800 BAUD
       RCSTA=$90:TXSTA=$20:SPBRG=155
       RCSTA.4 = 0 : RCSTA.4 = 1
       HSEROUT ["HOWDY THERE",$d,$a]
       PAUSE 250
       GOTO RUN
    Setup
    Code:
    '4550 HSER TEST'18F4550'06/20/10
    DEFINE OSC 48
    @ __CONFIG   _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
    @ __CONFIG   _CONFIG1H, _FOSC_HSPLL_HS_1H
    @ __CONFIG    _CONFIG2H, _WDT_OFF_2H & _WDTPS_512_2H
    @ __CONFIG    _CONFIG3H, _PBADEN_OFF_3H & _MCLRE_OFF_3H 
    @ __CONFIG    _CONFIG4L, _LVP_OFF_4L & _ICPRT_OFF_4L &_XINST_OFF_4L
    Once a NEWBE always a NEWBE
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    Dave, it's the same thing as from post #6.

    If there is an HSERIN or HSEROUT anywhere in your program. PBP will initialize the USART at the beginning of the program, before jumping to user code.

    If you don't set the defines, PBP defaults to 2400 baud and standard USART mode (8-bit BRG).
    Anything above 32mhz, and 2400 baud is too slow for a standard USART. SPBRG ends up larger than 255, and throws an out of range warning.

    If you define HSER_SPBRG, then PBP does not try to calculate SPBRG ... hence no warning.
    If you define an HSER_BAUD that works at that OSC, it calculates a valid SPBRG and also doesn't give a warning.

    Once you've made it past the Initialization, you can manually set the EUSART registers for whatever baud rate you want.

    hth,
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Thanks again Darrel for your help.
    This is the part that I was not getting
    If there is an HSERIN or HSEROUT anywhere in your program. PBP will initialize the USART at the beginning of the program, before jumping to user code.
    For some reason I thought PBP went line by line when compiling so I did not understand why setting the registers before HSERIN did not do the same as DEFINE XX.

    I am beginning to get it.
    Dave
    Always wear safety glasses while programming.

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