Defining I/O Registers

The I/O Registers are usually based at address 0. To tell the compiler it must use direct addressing mode to access th e I/O registers, define these registers in a __SHORT_SEG section (if available) based at the specified address.

Define the I/O register in the C source file as in the following listing.

Listing: Definition of an I/O Register
typedef struct {
  unsigned char SCC1;

  unsigned char SCC2;

  unsigned char SCC3;

  unsigned char SCS1;

  unsigned char SCS2;

  unsigned char SCD;

  unsigned char SCBR;

} SCIStruct;

#pragma DATA_SEG __SHORT_SEG SCIRegs

SCIStruct   SCI;

#pragma DATA_SEG DEFAULT

Place the segment at the appropriate address in the PRM file (refer the following listing).

Listing: Linker Parameter File Allocating the I/O Register
LINK test.abs
NAMES test.o startup.o ansi.lib END

SECTIONS

    SCI_RG = READ_WRITE  0x0013 TO 0x0019; 

    Z_RAM  = READ_WRITE  0x0080 TO 0x00FF; 

    MY_RAM = READ_WRITE  0x0100 TO 0x01FF;

    MY_ROM = READ_ONLY   0xF000 TO 0xFEFF;

PLACEMENT

    DEFAULT_ROM                    INTO  MY_ROM;

    DEFAULT_RAM                    INTO  MY_RAM;

    _ZEROPAGE                      INTO  Z_RAM;

    SCIRegs                        INTO  SCI_RG;

END

STACKSIZE 0x60

VECTOR 0 _Startup /* set reset vector on _Startup */
Note: The Linker is case-sensitive. The segment name must be identical in the C/C++ and PRM files.