Search code examples
linkermicrocontrollerpicpic18

How to place variables in the access bank - PIC 18 MPASM linker script


I have a linker script which starts

    INCLUDE 18f14K50_g.lkr

I want my interrupt service variables to go into the ACCESS bank. (My program's so small at the moment the whole lot can, but maybe in future...). So

    SECTION     NAME=VarsModemISR   RAM=accessram

which results in:

MPLINK 4.39, Linker
Device Database Version 1.1
Copyright (c) 1998-2011 Microchip Technology Inc.
Error - section 'VarsModemISR' has a memory 'accessram' which is not defined in the linker command file.
Errors    : 1

Examining the included file I believe it is. Either that or I'm working in extended mode and "gpre" is. I can use an #IFDEF to check, which I tried. The result, it was trying to use "accessram" not "gpre".

Maybe if I try defining the access bank explicitly by copying the line from the include file:

ACCESSBANK NAME=accessram  START=0x0               END=0x5F
SECTION     NAME=VarsModemISR   RAM=accessram

This results in the error

MPLINK 4.39, Linker
Device Database Version 1.1
Copyright (c) 1998-2011 Microchip Technology Inc.
Error - duplicate definition of memory 'accessram' 
Errors    : 1

Which has me confused. According to the Assembler/Linker documentation I use SECTION with the RAM option, where RAM has previously been declared using ACCESSBANK, SHAREBANK or DATABANK. It should work.

Thanks - Richard


Solution

  • There is really no need to change linker script, use default one!

    Accessed file registers are available at any moment under PIC18 MCPUs. Just declare variables in appropriate memory databank named ACCESSBANK which start at 0x00 and end at 0x60 address.

    If you are using MPLAB than declare:

    _Shared        udata_acs        0        ;Shared memory file registers
    IntReg1        res              1
    IntReg2        res              1
    ;...
    
    _UpperBank0    udata            060h     ;Banked file memory registers
    RegA           res              1
    ;...
    
    _Bank1         udata            0100h    ;Banked file memory registers
    N              res              1
    ;...
    

    Linker should automatically set the 'a' bit in code instruction for file register addresses, which are declared in ACCESSBANK.