PBP bad expression


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2009
    Posts
    11

    Post PBP bad expression

    Alright, I think I got a good one for ya here:

    I have a large main program that is calling subroutines from an INCLUDE file (include "umfpuV3-spi.bas"). These subroutines use variables that are defined in the main program file. For some reason, the compiler (PBPro 2.46) does not recognize these variables when inside the INCLUDEd subroutines, and I get the error "Bad Expression".

    These variables are PORT names, as shown in the code below. When I change the variable name to the PORTC.x name inside the INC file, the Main program compiles with no problem.

    To be specific, when the GOSUB FPU_RESET is called in the main program below, the FpuOut, FpuClk, and FpuIn are not recognized in the subroutine.

    Here is the header to my main program with the GOSUB:
    Code:
    '=============================================================================
    '              MAIN PROGRAM CODE
    '=============================================================================
    
    '-------------------- PIC oscillator speed ------------------------------------
    define      OSC 20                      ' specify the speed of the oscillator
    OSC_SPEED   con 20                      ' define PICBASIC constant
    
    '-------------------- debug definitions ---------------------------------------
    define DEBUG_REG PORTD
    define DEBUG_BIT 0
    define DEBUG_BAUD 9600
    define DEBUG_MODE 0
    DEFINE DEBUGIN_BIT 1
    
    '-------------------- ADC CONFIG definitions ----------------------------------
    Define	ADC_BITS	    10	' Set number of bits in result
    Define	ADC_CLOCK	    3	' Set clock source (3=rc)
    Define	ADC_SAMPLEUS	5	' Set sampling time in uS
    TRISA = %11111111	        'Set PORTA to all input
    'ADCON1 = %10001100          'config of 877
    adcon1 = %00011000          'config for 4550
    TRISD.3 = %1
    
    '-------------------- INCLUDE files --------------------------------------------
    Include "modedefs.bas"      'Include for serial communication
    include     "umfpuV3-spi.bas"           ' include uM-FPU V3.1 support routines
    include "fp1832.bas"        'Floating point math
    
    '-------------------- uM-FPU pin definitions ----------------------------------
    FpuClk          var     PORTC.3			' SPI SCLK (uM-FPU SCLK)
    FpuIn           var     PORTC.4			' SPI MISO (uM-FPU SOUT)
    FpuOut          var     PORTC.5			' SPI MOSI (uM-FPU SIN)
    
    '-------------------- AD7715 calibration data ----------------------------------  
        data @200, 0        'high byte of zs_mv
        data @201, 0        'low byte of zs_mv
        data @202, 0        'high byte of zs_adval
        data @203, 0        'low byte of zs_adval
        data @204, 4        'high byte of fs_mv
        data @205, 237      'low byte of fs_mv
        data @206, 233      'high byte of fs_adval
        data @207, 188      'low byte of fs_adval
    
    
    Reset:
      DEBUG 13, 10, 13, 10, "Demo 2: "
    
      GOSUB Fpu_Reset                       ' initialize uM-FPU
      IF fpu_status <> SYNC_CHAR THEN
        DEBUG "uM-FPU not detected."
        END
      ELSE
        GOSUB Print_Version                 ' display version string
      ENDIF
    
    *clipped*

    Here is the subroutine inside the .inc file. You can see where I changed the first SHIFTOUT to use the PORT pin numbers, and the second SHIFTOUT is using the variable names.
    Code:
    '==============================================================================
    '-------------------- uM-FPU SPI support routines -----------------------------
    '==============================================================================
    
    Fpu_Reset:								' send reset command to uM-FPU V3
      SHIFTOUT portc.5, portc.3, 1,_
    	[$FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, 0]
      PAUSE 10
    										' check for synchronization
      SHIFTOUT FpuOut, FpuClk, MSBFIRST, [SYNC]
      GOTO Fpu_Status2

    Here is a WORKING main program. When I compile this program, the subroutine recognizes the variables and has no errors:
    Code:
    '=============================================================================
    
    '-------------------- PIC oscillator speed ------------------------------------
    define      OSC 20                      ' specify the speed of the oscillator
    OSC_SPEED   con 20                      ' define PICBASIC constant
    
    '-------------------- debug definitions ---------------------------------------
    define      DEBUG_REG   PORTC
    define      DEBUG_BIT   6
    define      DEBUG_BAUD  19200
    define      DEBUG_MODE  0
    
    '-------------------- uM-FPU pin definitions ----------------------------------
    FpuClk          var     PORTC.3			' SPI SCLK (uM-FPU SCLK)
    FpuIn           var     PORTC.4			' SPI MISO (uM-FPU SOUT)
    FpuOut          var     PORTC.5			' SPI MOSI (uM-FPU SIN)
    
    include     "umfpuV3-spi.bas"           ' include uM-FPU V3.1 support routines
    
    '-------------------- DS1620 pin definitions ---------------------------------
    
    DS_RST      var     PORTA.0             ' DS1620 reset/enable
    DS_CLK      var     PORTA.1             ' DS1620 clock
    DS_DATA     var     PORTA.2             ' DS1620 data
    
    LSBFIRST	con		0					' shiftout mode
    LSBPRE		con		1					' shiftin mode
    
    '-------------------- uM-FPU register definitions ----------------------------
    
    DegC            CON     1               ' temperature in degrees Celsius
    DegC_Min        CON     2               ' minimum temperature
    DegC_Max        CON     3               ' maximum temperature
    DegF            CON     4               ' temperature in degrees Fahrenheit
    F1_8            CON     5               ' constant 1.8
    
    '-------------------- variables ----------------------------------------------
    
    rawTemp         VAR     Word            ' raw temperature reading
    
    '=============================================================================
    '-------------------- initialization -----------------------------------------
    '=============================================================================
    
    Reset:
      DEBUG 13, 10, 13, 10, "Demo 2: "
    
      GOSUB Fpu_Reset                       ' initialize uM-FPU
      IF fpu_status <> SYNC_CHAR THEN
        DEBUG "uM-FPU not detected."
        END
      ELSE
        GOSUB Print_Version                 ' display version string
      ENDIF
      DEBUG 13, 10, "---------------------"
    
      GOSUB Init_DS1620                     ' initialize DS1620
    So ... granted that my MAIN program is very large (25K) and has many other things going on, does anyone know what a possible problem or solution could be?

    I'll be here all night...
    Last edited by MyBuddy; - 24th October 2009 at 00:20.

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


    Did you find this post helpful? Yes | No

    Default

    Put any variables or aliases used in the include file, before the INCLUDE statement.
    Code:
    '-------------------- uM-FPU pin definitions ----------------------------------
    FpuClk          var     PORTC.3			' SPI SCLK (uM-FPU SCLK)
    FpuIn           var     PORTC.4			' SPI MISO (uM-FPU SOUT)
    FpuOut          var     PORTC.5			' SPI MOSI (uM-FPU SIN)
    
    '-------------------- INCLUDE files --------------------------------------------
    Include "modedefs.bas"      'Include for serial communication
    include     "umfpuV3-spi.bas"           ' include uM-FPU V3.1 support routines
    include "fp1832.bas"        'Floating point math
    DT

  3. #3
    Join Date
    Oct 2009
    Posts
    11


    Did you find this post helpful? Yes | No

    Default OMG you are amazing.

    I'm noticeably balder after that experience, and all for something so simple.

    Thanks Darrel. I love you.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by MyBuddy View Post
    I'm noticeably balder after that experience ...
    It happens ...
    Start the Rogaine now.

    One of our other users waited too long.



    __________________
    DT

Similar Threads

  1. PBP Book
    By Bruce in forum Off Topic
    Replies: 83
    Last Post: - 4th October 2021, 12:55
  2. Extensions to PBP variables
    By John_Mac in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 23rd October 2009, 05:21
  3. bad expression error, linking addresses incorrectly.
    By robertpeach in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 26th August 2009, 13:04
  4. Compiler differences between PBP 2.33 & 2.46
    By nikopolis in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd May 2006, 19:01
  5. Newby- PBP wont compile for 18F (MPLAB)
    By jd76duke in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th December 2005, 23:30

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