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:
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?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
I'll be here all night...




Bookmarks