Menu ▾ ▴

USART_DELAY OFF error when it's within a #ifdef ... #endif

R. G. Keen
2026-10-02
2026-10-04
  • R. G. Keen

    R. G. Keen - 2026-10-02

    Got strange results with USART_DELAY OFF and #ifdef ... #endif.
    If the delay setting is inside the ifdef...endif, I get

    IFDEF/OFF: USART_DELAY equates to 1MS and cannot be reassigned to equate to OFF

    Moving it outside the #ifdef... #endif produces no error. There are other #defines inside the ifdef that produce no error.

    #chip 16F18044, 32  ' 32MHz
    #Option Explicit
    
    #define SerialOutput
    #startup InitPPS, 85            ' have to run PPS Before HSER runs
    
    #ifdef SerialOutput
    #define USART_DELAY OFF
    #define USART_BAUD_RATE 115200  ' Define desired baud rate
    #define USART_TX_BLOCKING 
    #endif
    

    ... produces the error message, moving it above the #ifdef does not reproduce the error.
    Moving it after USART_BLOCKING also causes the error.

    Particulars:
    GCBASIC (2026.09.27(Windows 64 bit) : Build 1653)

    I figure there is some obscure rule I haven't found in the documentation and/or forum, but I've tried and I'm baffled. I can work around it by moving the define outside the ifdef, but I was trying to neatly encapsulate the serial stuff with an ifdef.

     
  • Anobium

    Anobium - 2026-10-02

    A script is the answer.

    #chip 16F18044, 32  ' 32MHz
    #Option Explicit
    
    #define SerialOutput
    #startup InitPPS, 85            ' have to run PPS Before HSER runs
    
    #script
    ifdef SerialOutput then
    USART_DELAY = OFF
    USART_BAUD_RATE = 115200  ' Define desired baud rate
    USART_TX_BLOCKING = True
    end if
    #script
    

    Untested, but, a script is the method to use.

     

    Last edit: Anobium 2026-10-04
  • Anobium

    Anobium - 2026-10-04

    Correct/tested and it works

    #chip 16F18044, 32  ' 32MHz
    #Option Explicit
    
    #define SerialOutput
    // #startup InitPPS, 85            ' have to run PPS Before HSER runs
    
    #script
        if def(SerialOutput) then
            USART_DELAY = OFF
            USART_BAUD_RATE = 115200  ' Define desired baud rate
            USART_TX_BLOCKING = True
            INFO "Serial Setup"
        else
            INFO "Serial Not setup"
        end if
    #endscript
    
     

Log in to post a comment.