PBP3 Code Does not Compile with PBP3.1


Closed Thread
Results 1 to 6 of 6
  1. #1

    Default PBP3 Code Does not Compile with PBP3.1

    I upgraded to PBP 3.1 recently and while some PIC code compiles just fine the following does not (although it compiles with PBP3 - I just switched my compiler to the old folder and it worked):

    Code:
    '****************************************************************
    '*  Name    : Nacelle_Steady-On_Lights_12F1840_16Mhz_Int.pbp    *
    '*  Author  : Ross A. Waddell                                   *
    '*  Notice  : Copyright (c) 2016                                *
    '*          : All Rights Reserved                               *
    '*  Date    : 11/26/2016                                        *
    '*  Version : 9.0                                               *
    '*  Notes   : Steady-on nacelle engine lights (TOS Enterprise)  *
    '*          : with PWM fade-in/brightness control               *
    '****************************************************************
    
    ' For production version of this code, comment out the line below re:
    ' LCD debugging and also update config fuses to have code protect on
    '#DEFINE USE_LCD_FOR_DEBUG     ; comment out for non-debug use
    
    ' The PWM/fade works perfectly when **not** connected to a FET
    '   - if using a FET, the LEDs 'pulse' and blink but don't fade in/out
    '   - use a 2N2222A transistor
    
    ' ***************************************************************
    ' Pin Connections
    ' ***************************************************************
    
    ' VDD    -> pin 1            -> +5V
    ' RA5/Rc -> pin 2            -> EUSART receive
    ' RA2    -> pin 5            -> 1kohm -> 2N2222A transistor -> LEDs
    ' RA1    -> pin 6            -> Trim pot input
    ' RA0/Tx -> pin 7            -> EUSART transmit (LCD)
    ' VSS    -> pin 8            -> GND
    
    DEFINE OSC 16               ; Set oscillator 16Mhz
    
    ' ***************************************************************
    ' EUSART Settings for Tx/Rc (e.g. LCD)
    ' ***************************************************************
    
    ' > use Mister E PIC Multi-Calc application to get register/DEFINE settings
    ' > as the values are dependent on the OSC and desired baud rate
    
    DEFINE HSER_RCSTA 90h      ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h      ' Enable transmit, BRGH = 1
    DEFINE HSER_CLROERR 1      ' Clear overflow automatically
    DEFINE HSER_SPBRG 160      ' 9600 Baud @ 16MHz, -0.08%
    
    ' ***************************************************************
    ' Device Fuses
    ' ***************************************************************
    ' PIC chip data sheets can be found here: C:\Program Files\Microchip\MPASM Suite
    
    #CONFIG
       __config _CONFIG1, _FOSC_INTOSC & _WDTE_ON & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF
       __config _CONFIG2, _PLLEN_OFF & _STVREN_ON & _BORV_LO & _LVP_OFF
    #ENDCONFIG
    
    ' ***************************************************************
    ' Initialization
    ' ***************************************************************
    
    OSCCON    = %01111000        ' 16MHz internal osc
    pause 100                    
    
    APFCON.2  = 0                ; Tx on RA0 for LCD display
    APFCON.7  = 1                ; Rc on RA5
    APFCON.0  = 0                ; CCP1 on RA2
    
    ' Some LCD serial modules need inverted data, some do not
    ' Enable the line below if needed, but for SparkFun SerLCD it should be
    ' commented out
    
    'BAUDCON.4 = 1               ; Transmit inverted data to the Tx pin  
    
    ' From Mister E's Multi-Calc (EUSART):
    ' *****************************************************************
    SPBRGH    = 1
    BAUDCON.3 = 1               ' Enable 16 bit baudrate generator
    ' *****************************************************************
    
    TRISA     = %00100010	     ' Make all pins output except for RA1 (trim pot input)
                                 ' and RA5 (EUSART Rc)
    ANSELA    = %00000010        ; Analog on PORTA.1 (AN1) only
    
    FVRCON    = 0                ' Fixed Voltage Reference is disabled
    ADCON0    = %00000101        ' ADC (analog-to-digital) is enabled on AN1 (RA1) only
    PAUSEUS 20                   ; wait for the analog switch 'glitch' to die down
    ADCON1    = %00110000        ; Left-justified results in 8-bits; Frc as timer
    
    #IFDEF USE_LCD_FOR_DEBUG
        LCD_INST   CON 254       ' instruction
        LCD_CLR    CON 1         ' Clear screen
        LCD_L1     CON 128       ' LCD line 1
        LCD_L2     CON 192       ' LCD line 2
        LCD_SP_CMD CON 124       ' special command character (for adjusting backlight brightness or toggling splash screen)
        LCD_BR_LVL CON 140       ' 140==40%
        LCD_SPLASH CON 9         ' toggles splash screen display
    #ENDIF
    
    ' ***************************************************************
    ' Includes
    ' ***************************************************************
    
    INCLUDE "DT_INTS-14.bas"    ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"    ' Include if using PBP interrupts
    INCLUDE "Elapsed_INT.bas"   ' Contains subs for doing elapsed time
                                ' --> copy files to PBP main folder 
                                ' (i.e. c:\pbp3)
    
    ;-- Place a copy of these variables in your Main program -------------------
    ;--   The compiler will tell you which lines to un-comment                --
    ;--   Do Not un-comment these lines                                       --
    ;---------------------------------------------------------------------------
    ;wsave   VAR BYTE    $20     SYSTEM      ' location for W if in bank0
    ;wsave   VAR BYTE    $70     SYSTEM      ' alternate save location for W 
                                             ' if using $70, comment wsave1-3
    
    ' --- IF any of these three lines cause an error ?? ------------------------
    '       Comment them out to fix the problem ----
    ' -- Which variables are needed, depends on the Chip you are using -- 
    ;wsave1  VAR BYTE    $A0     SYSTEM      ' location for W if in bank1
    ;wsave2  VAR BYTE    $120    SYSTEM      ' location for W if in bank2
    ;wsave3  VAR BYTE    $1A0    SYSTEM      ' location for W if in bank3
    ' --------------------------------------------------------------------------
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR1_INT,  _ClockCount,   PBP,  yes
        endm
        INT_CREATE            ; Creates the interrupt processor
    
        INT_ENABLE  TMR1_INT  ; Enable Timer 1 Interrupts  
    ENDASM
    
    ' LED Fade Linearization
    ' ======================
    ' Increasing the duty cycle by discrete integer amounts leads to a logarithmic
    ' increase in brightness; the LED appears to quickly reach maximum brightness
    ' long before it reaches the max duty cycle value. To make the fade in look more
    ' linear (like an incandescent bulb), the data table below uses 'gamma correction'
     ' to genterate appropriate duty cycle values.
     
    ' Values generated by C:\Users\Ross\Dropbox\PBP Projects\PBP3 and MCSPX Software\LEDGammaCorrectGenerator.xlsm
    ' Array size = 100
    ' Total PWM steps: 512
    ' Gamma correction: 0.75 (try values in the range of 0.5 - 2.0)
    ' # of values per line: 15
    
    '-----[The data table]--------------------------------------------------------
    DataWord       VAR WORD
    numSteps       CON 100
    DataTable      CON EXT
    GOTO OverData                ; Make sure data doesn't try to execute
    ASM
    DataTable
      DW   0,  1,  1,  2,  2,  2,  2,  2,  3,  3,  3,  3,  4,  4,  4
      DW   5,  5,  5,  6,  6,  7,  7,  8,  8,  9,  9, 10, 11, 12, 12
      DW  13, 14, 15, 16, 17, 18, 19, 20, 22, 23, 24, 26, 27, 29, 31
      DW  32, 34, 36, 38, 41, 43, 45, 48, 51, 54, 57, 60, 63, 66, 70
      DW  74, 78, 82, 87, 91, 96,101,107,112,118,124,131,138,145,152
      DW 160,168,177,186,196,205,216,227,238,250,263,276,289,304,319
      DW 334,351,368,386,404,424,445,466,488,511
    endasm
    OverData:
    '-----[Continue with code]----------------------------------------------------
    
    ' ***************************************************************
    ' Set up PWM on CCP1
    ' ***************************************************************
    
    CCP1CON = %00001100          ; Use CCP1 in PWM mode
    
    ' Set duty cycle registers initially to 0
    CCP1CON.4 = 0
    CCP1CON.5 = 0
    CCPR1L    = 0
    
    ' Use Mister E's PICMultiCalc_1.3.1.exe application (Windows only)   
    ' to determine prescaler and PR2 values for given OSC frequency (e.g. 16Mhz)
    ' and duty cycle (use 100% to see highest actual value)
    
    ' ************************
    ' CCP1 uses TMR2
    ' ************************
                           
    T2CON   = %00000110         ; Timer2 on with 1:16 prescaler
    PR2     = 127               ; For 16Mhz OSC the desired output freq of 1954Hz
                                ; is achieved with this PR2 value (9-bit resolution
                                ; with 1:16 prescaler)
                                ; MAX DUTY = 512; must match max PWM steps from data
                                ; table above
                                
    PWMDuty       VAR WORD      ; Duty cycle variable for PWM
    
    MaxADCVal     CON 255       ; 255 for 8-bit; 1023 for 10-bit
    
    ADCInVal      VAR BYTE      ; stores ADCIN result read from trim pot
    compVal       VAR BYTE      ; stores last-changed ADC value
    
    CounterA      var BYTE		' Just a BYTE Temporary working variable
    DataW         var WORD		' Just a WORD Temporary working variable
    RawData       var BYTE [16] ' Array holding ADC Result
    
    LEDBrIndx     VAR WORD
    
    i             VAR WORD
    PulseLimit    VAR WORD
    LEDPulse      VAR BIT       ; 1=fully on; 0= start pulsating effect
    
    LCDPause      CON 5         ; Pause for LCD display
    FadeInPause   VAR BYTE      ; Pause during LED fade in
    
    #IFDEF USE_LCD_FOR_DEBUG
        FadeInPause = 12
    #ELSE
        FadeInPause = 40 + LCDPause  ; was 15 + LCDPause
    #ENDIF
    
    ' Should only need to do this one time to adjust backlight brightness
    '#IFDEF USE_LCD_FOR_DEBUG
    '    HSEROUT [LCD_SP_CMD, LCD_BR_LVL]
    '    PAUSE LCDPause
    '#ENDIF
    
    ' Should only need to do this one time to disable splash screen
    '#IFDEF USE_LCD_FOR_DEBUG
    '    HSEROUT [LCD_SP_CMD, LCD_SPLASH]
    '    PAUSE 1000
    '#ENDIF
    
    #IFDEF USE_LCD_FOR_DEBUG
        pause 1000
        HSEROUT [LCD_INST, LCD_CLR, "LCD Init"]
        pause LCDPause
        HSEROUT [LCD_INST, LCD_L2, "  SerLCD_V2_5"]
        pause 2000
    #ENDIF
    
    ' ************************************************
    ' Get Vref from ADC to set brightness step index
    ' ************************************************ 
    GOSUB Do_ADC
    compVal = ADCInVal          ; set initial compare value
    GOSUB Map_ADCInVal_to_PWM_Steps
    
    #IFDEF USE_LCD_FOR_DEBUG
        HSEROUT [LCD_INST, LCD_CLR]
        pause LCDPause
        HSEROUT ["LEDBrIndx=",DEC LEDBrIndx,"  "]
        pause 750
    #ELSE
        PAUSE 500               ; should match motor spin up
    #ENDIF
    
    ' Fade in LED to set brightness
    FOR i = 0 to (LEDBrIndx  - 1)      ; max is 'numSteps' from data table above
        ReadCODE  (DataTable + i), DataWord
        PWMDuty = DataWord
    
        GOSUB ChngLEDBrightness 
             
        #IFDEF USE_LCD_FOR_DEBUG
            HSEROUT [LCD_INST, LCD_CLR]
            pause LCDPause
            HSEROUT ["PWMDuty=",DEC PWMDuty,"  "]
        #ENDIF
       
        pause FadeInPause       ; should match motor spin up
    NEXT i
    
    LEDPulse = 1               ' set initial value
    Gosub ResetTime            ' Reset Time to  0d-00:00:00.00
    Gosub StartTimer           ' Start the Elapsed Timer
    
    
    '    PulseLimit = 95*(LEDBrIndx/100) ' 95%
    '    PulseLimit = 9*(LEDBrIndx/10) ' 90%
    '    PulseLimit = 4*(LEDBrIndx/5) ' 80%
        PulseLimit = 3*(LEDBrIndx/4) ' 75%
    '    PulseLimit = 6*(LEDBrIndx/10) ' 60%
    '    PulseLimit = LEDBrIndx/2     ' 50%
    '    PulseLimit = LEDBrIndx/4     ' 25%
    
    Main:
    '   Check trim pot value
        GOSUB Do_ADC
    '    PAUSE 100
    
    '   If trim pot value has changed, update LED brightness level
        If (compVal > (ADCInVal + 1)) or (compVal < (ADCInVal - 1)) THEn
            compVal = ADCInVal
            GOSUB Map_ADCInVal_to_PWM_Steps
    
            ReadCODE  (DataTable + (LEDBrIndx - 1)), DataWord
            PWMDuty = DataWord
    
            gosub ChngLEDBrightness
    
            #IFDEF USE_LCD_FOR_DEBUG
                HSEROUT [LCD_INST, LCD_CLR]
                pause LCDPause
                HSEROUT ["new LEDBrIndx", LCD_INST, LCD_L2, DEC LEDBrIndx, "  "]
            #ENDIF
    
            Gosub ResetTime           ' Reset Time to  0d-00:00:00.00
        ENDIF
    
    '   Pulse LEDs
        if (Seconds = 1) AND (LEDPulse = 1) then  
        '   Fade down LEDs to a preset minimum    
            FOR i = (LEDBrIndx - 1) to PulseLimit STEP -1
                ReadCODE  (DataTable + i), DataWord
                PWMDuty = DataWord
            
                GOSUB ChngLEDBrightness 
                     
                #IFDEF USE_LCD_FOR_DEBUG
                    HSEROUT [LCD_INST, LCD_CLR]
                    pause LCDPause
                    HSEROUT ["PWMDuty=",DEC PWMDuty,"  "]
                #ENDIF
               
                'pause 15
                pause 12
            NEXT i
    
            LEDPulse = 0
            Gosub ResetTime           ' Reset Time to  0d-00:00:00.00
        ELSEIF (Ticks = 20) and (LEDPulse = 0) THEN
        '   Fade up LEDs back to trim pot setting    
            FOR i = PulseLimit to (LEDBrIndx  - 1)
                ReadCODE  (DataTable + i), DataWord
                PWMDuty = DataWord
            
                GOSUB ChngLEDBrightness 
                     
                #IFDEF USE_LCD_FOR_DEBUG
                    HSEROUT [LCD_INST, LCD_CLR]
                    pause LCDPause
                    HSEROUT ["PWMDuty=",DEC PWMDuty,"  "]
                #ENDIF
               
                'pause 15
                pause 12
            NEXT i 
    
            LEDPulse = 1
            Gosub ResetTime           ' Reset Time to  0d-00:00:00.00
        endif    
    
    GOTO Main
    
    Do_ADC:
    '   Function to 'average out' changing ADC values when the trim pot swiper arm
    '   isn't moving to get a steady value
    
    '	Stuff 16 Element WORD Array full of ADC values
    '	----------------------------------------------
    	For CounterA = 0 to (16 - 1)
            ADCON0    = %00000101 ' Select Channel, Turn-On A/D
    						      '	7=0 Unused
    						      '	6=0 Unused
    						      '	5=0 )
    						      '	4=0 )
    						      '	3=0 ) selects AN1
    						      '	2=0 )
    						      '	1=0 Go-done Bit
    						      '	0=1 switch-On ADC Module
    		Pauseus 50			     ' Wait for channel to setup
            ADCON0.1 = 1			 ' Start conversion
    		While ADCON0.1=1:Wend	 ' Wait for conversion
    '		DataW.HighByte=ADRESH	 
    '		DataW.LowByte=ADRESL
            DataW = ADRESH           ' Read variable from ADC and save
    		RawData(CounterA) = DataW
    
    	Next CounterA
    
    '	Sort ADC Input
    '	--------------
    	CounterA = 0
     
     GetADCSortLoop:
    
    	If RawData(CounterA + 1) < RawData(CounterA) then
    		DataW = RawData(CounterA)
    		RawData(CounterA) = RawData(CounterA+1)
    		RawData(CounterA+1) = DataW
    		If CounterA > 0 then CounterA = CounterA - 2
    	endif
    	CounterA=CounterA+1
    	If CounterA < (16 - 1) then goto GetADCSortLoop
    
    '	Quanticise, discarding top and bottom FOUR elements
    '	----------------------------------------------------
    	DataW = 0
    	For CounterA = 4 to 11
    		DataW = DataW+RawData(CounterA)
    	Next CounterA
    	
        ADCInVal = DataW>>3			' Divide Result by EIGHT
    
    return
    
    '*********** Map Vref to PWM step **************************************
    Map_ADCInVal_to_PWM_Steps:
    '   Map ADC value to the range of accetable PWM steps, as the two ranges may
    '   not be the same( e.g. ADC: 0-255, PWM: 50-100)
    
    '   Arduino Map function to emulate:
    '   ===============================
    '   map(value, fromLow, fromHigh, toLow, toHigh)
    
    '   long map(long x, long in_min, long in_max, long out_min, long out_max)
    '   {
    '     return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
    '   }
    
    '   Need to split up the operations to get full value using DIV32
    '   50% PWM step range
        'LEDBrIndx = ((compVal - 0) * (numSteps - numSteps/2))
        'LEDBrIndx = DIV32 (MaxADCVal - 0) + numSteps/2
    
    '   90% PWM step range
        LEDBrIndx = ((compVal - 0) * (numSteps - numSteps/10))
        LEDBrIndx = DIV32 (MaxADCVal - 0) + numSteps/10
    
    RETURN
    
    '*********** Set duty registers ****************************************
    ChngLEDBrightness:
        CCP1CON.4 = PWMDuty.0
        CCP1CON.5 = PWMDuty.1
        CCPR1L    = PWMDuty >> 2
        
    RETURN
    I get this error:

    Code:
    [ERROR] nacelle_steady-on_lights_12F1840_16Mhz_int_v9.pbp (74) : Syntax error
    I have copied the 3 INCLUDES to C:\Program Files (x86)\PBP3.1 and made sure MicroCode Studio Plus is set to use the MPASMX assembler. Why won't this work now with PBP 3.1?

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,379


    Did you find this post helpful? Yes | No

    Default Re: PBP3 Code Does not Compile with PBP3.1

    SPBRGH = 1
    Is a syntax error

    needs to be

    SP1BRGH = 1

    imho the pbp3 include file is incorrect

    from PIC12F1840.PBPINC

    SP1BRG VAR WORD EXT ; Joined SFR, BANK3
    SP1BRGL VAR BYTE EXT ; BANK3
    SP1BRGH VAR BYTE EXT ; BANK3
    Last edited by richard; - 23rd June 2017 at 02:27.
    Warning I'm not a teacher

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: PBP3 Code Does not Compile with PBP3.1

    Quote Originally Posted by richard View Post
    Is a syntax error

    needs to be




    imho the pbp3 include file is incorrect

    from PIC12F1840.PBPINC
    That's it! Thank you so much Richard. I've got both lines in my code but with comments as to which to use with which compiler.

  4. #4
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: PBP3 Code Does not Compile with PBP3.1

    Dr. Bob at HidMaker informed me that using PBP3.1 requires MPLABX, which doesn't like .bas extensions. I converted my Include files to .pbp. I don't know if it's absolutely necessary, but everything is working. I see you have 3 .bas Include files. Are they working with the PBP3.1 just fine?

    Mike

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: PBP3 Code Does not Compile with PBP3.1

    Quote Originally Posted by mpgmike View Post
    Dr. Bob at HidMaker informed me that using PBP3.1 requires MPLABX, which doesn't like .bas extensions. I converted my Include files to .pbp. I don't know if it's absolutely necessary, but everything is working. I see you have 3 .bas Include files. Are they working with the PBP3.1 just fine?

    Mike
    All my code projects compiles just fine with .bas INCLUDEs. So far.

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    Did you find this post helpful? Yes | No

    Default Re: PBP3 Code Does not Compile with PBP3.1

    Dr. Bob at HidMaker informed me that using PBP3.1 requires MPLABX, which doesn't like .bas extensions.
    If that's true I'm pretty sure it still "only" applies to when you're actually using MPLABX as your IDE. If your using MicroCodeStudio or another IDE you're not really using MPLABX - but PBP relies on the assembler and its device specific include files that comes with MPLAB(X).

    /Henrik.

Similar Threads

  1. PBP3 Compile Errors
    By hjguitarplayer in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 27th August 2015, 00:34
  2. Replies: 1
    Last Post: - 4th April 2013, 02:31
  3. I really need some help with PBP3
    By Ramius in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 26th February 2012, 17:05
  4. Pbp3
    By rcbandwidth in forum mel PIC BASIC Pro
    Replies: 21
    Last Post: - 18th September 2011, 15:13
  5. What's with PBP3?
    By BrianT in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 10th August 2011, 18:09

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