Defining I/O Registers

The HC(S)08 I/O Registers are usually based at address 0. To tell the compiler to use direct addressing mode to access the I/O registers, define these registers in a __SHORT_SEG section based at the specified address.

In the C source file, define the I/O registers as follows:

Listing: I/O Example
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

volatile SCIStruct   SCI;

#pragma DATA_SEG DEFAULT

Place the segment at the appropriate address in the PRM file.

Listing: Example PRM File
LINK test.abs
NAMES test.o start08.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;

    _DATA_ZEROPAGE                 INTO  Z_RAM;

    SCIRegs                        INTO  SCI_RG;

END

STACKSIZE 0x60

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