News:

Let's find out together what makes a PIC Tick!

Main Menu

Fail to compile on all? 18F CAN devices

Started by RGV250, Dec 31, 2021, 12:13 AM

Previous topic - Next topic

RGV250

Hi,
I tried to compile my rewritten CAN code and it failed, I think the last time I tried it did compile but that was using 3.7.5.5 or whatever the pre 4.x.x.x version was.

The issue is "Symbol not previously defined (ABAT)", I have looked in the PPI file for 18F458 and it is there, I get the same error on 18F258, 18F4680 and probably other CAN devices.
I then looked in the DEF file and this is there $define CANCONbits_ABAT CANCON.4 so I tried using CANCONbits_ABAT but it still fails to compile with CANCONbits_ABAT not found.

I comment out the procedure and it compiles so not sure what to try next.

Regards,
Bob


RGV250

Hi,
I have altered the position of "Inc" files and this seems to resolve it if I use CANCONbits_ABAT but still fails to compile if I use ABAT. Not exactly sure why that should make a difference for just that bit?

This is a stripped down test file.
        Xtal = 20   
       
        Device = 18F2680 

Declare Reminders Off
@ CONFIG_REQ = 0 ; Override Compiler's configuration settings
Asm-
Config OSC = HS ;HS oscillator
Config FCMEN = On ;Fail-Safe Clock Monitor enabled
Config IESO = OFF ;Oscillator Switchover mode disabled
Config PWRT = On ;PWRT enabled
Config BOREN = BOHW ;Brown-out Reset enabled in hardware only (SBOREN is disabled)
Config BORV = 0 ;VBOR set to 4.6V
Config WDT = OFF ;WDT disabled (control is placed on the SWDTEN bit)
Config WDTPS = 32768 ;1:32768
Config PBADEN = OFF ;PORTB<4:0> pins are configured as digital I/O on Reset
Config LPT1OSC = OFF ;Timer1 configured for higher power operation
Config MCLRE = On ;MCLR pin enabled; RE3 input pin disabled
Config STVREN = On ;Stack full/underflow will cause Reset
Config LVP = OFF ;Single-Supply ICSP disabled
Config BBSIZ = 1024 ;1K words (2K bytes) Boot Block
Config XINST = OFF ;Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
Config Debug = OFF ;Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
Config Cp0 = OFF ;Block 0 (000800-003FFFh) not code-protected
Config CP1 = OFF ;Block 1 (004000-007FFFh) not code-protected
Config CP2 = OFF ;Block 2 (008000-00BFFFh) not code-protected
Config CP3 = OFF ;Block 3 (00C000-00FFFFh) not code-protected
Config CPB = OFF ;Boot block (000000-0007FFh) not code-protected
Config CPD = OFF ;Data EEPROM not code-protected
Config WRT0 = OFF ;Block 0 (000800-003FFFh) not write-protected
Config WRT1 = OFF ;Block 1 (004000-007FFFh) not write-protected
Config WRT2 = OFF ;Block 2 (008000-00BFFFh) not write-protected
Config WRT3 = OFF ;Block 3 (00C000-00FFFFh) not write-protected
Config WRTC = OFF ;Configuration registers (300000-3000FFh) not write-protected
Config WRTB = OFF ;Boot block (000000-0007FFh) not write-protected
Config WRTD = OFF ;Data EEPROM not write-protected
Config EBTR0 = OFF ;Block 0 (000800-003FFFh) not protected from table reads executed in other blocks
Config EBTR1 = OFF ;Block 1 (004000-007FFFh) not protected from table reads executed in other blocks
Config EBTR2 = OFF ;Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks
Config EBTR3 = OFF ;Block 3 (00C000-00FFFFh) not protected from table reads executed in other blocks
Config EBTRB = OFF ;Boot block (000000-0007FFh) not protected from table reads executed in other blocks
Endasm-
Declare Reminders On

CAN_DUPLICATE_ERROR:
        CANAbortAll()   'Abort ALL pending transmissions in ALL TX buffers


Proc CANAbortAll()
     Bsf CANCON,ABAT   
    '' Bsf CANCONbits_ABAT       
EndProc


top204

The ABAT name is an assembler directive for the bit number of an SFR, and about 2 years ago, I had to remove them from the assembler file and only include the ones that the compiler uses internally, with the PP_ texts preceding them, because users were making directives in the BASIC program with the same name as they were in the assembler file and the assembler became confused and either gave errors or used the incorrect directive created in the user's program.

To use a bit name for an SFR in the main program, create a symbol for it, or look in the device's .def file and see if it has a XXXbits_xxx name attached to the SFR.Bit.

This will stop future problems and keep a program backward compatible, because what is required by the program is in the program.




RGV250

Thanks Les,
So would it be fair to say we should use the "def" file instead of the "PPI" in the future.

Regards,
Bob

top204

If the required SFRbits_xxx $define is within the .def file, it is always better to use it, because they will not change and they are difficult for a user to accidentally replicate them.

Also, it is always better to use a high level command to alter bits within an SFR, or the SFR itself. The assembler mnemonics will not alter RAM banks, and with some devices, not all SFRs are within bankless RAM, so the mnemonic Bsf will access the wrong RAM bank if the previous command was accessing a variable in a different RAM bank.

It is always better to use CANCONbits_ABAT = 1 or Set CANCONbits_ABAT, because the compiler will handle any RAM bank switching if required, and the mnemonic will still be Bsf.