18.2 Reading and Writing I/O Registers

The Rabbit has two I/O spaces: internal I/O registers and external I/O registers.

18.2.1 Using Assembly Language

The fastest way to read and write I/O registers in Dynamic C is to use a short segment of assembly language inserted in the C program. Access is the same as for accessing data memory except that the instruction is preceded by a prefix (IOI or IOE) to indicate the internal or external I/O space. For example:

//compute value and write to Port A Data Register value=x+y

#asm

 

 

 

 

ld a,(value)

;

value

to write

 

ioi ld (PADR),a

;

write

value to

PADR

#endasm

 

 

 

 

In the example above the IOI prefix changes a store to memory to a store to an internal I/O port. The prefix ioe is used for writes to external I/O ports.

18.2.2 Using Library Functions

Dynamic C functions are available to read and write I/O registers. These functions are pro- vided for convenience. For speed, assembly code is recommended. For a complete description of the functions noted in this section, refer to the Dynamic C User’s Manual or from the Help menu in Dynamic C, access the HTML Function Reference or Function Lookup options.

To read internal I/O registers, there are two functions.

int

RdPortI(int PORT)

;

//

returns PORT, high byte zero

int

BitRdPortI(int PORT, int bitcode);

//

bit code 0-7

To write internal I/O registers, there are two functions.

void WrPortI(int PORT, char *PORTShadow, int value);

void BitWrPortI(int PORT, char *PORTShadow, int value, int bitcode);

The external registers are also accessible with Dynamic C functions.

int RdPortE(int PORT); // returns PORT, high byte zero

int BitRdPortE(int PORT, int bitcode); // bit code 0-7 int WrPortE(int PORT, char *PORTShadow, int value);

int BitWrPortE(int PORT, char *PORTShadow, int value, int bitcode);

In order to read a port the following code could be used:

k=RdPortI(PADR); // returns Port A Data Register

242

Rabbit 3000 Microprocessor

Page 251
Image 251
Jameco Electronics 2000, 3000 manual Reading and Writing I/O Registers, Using Assembly Language, Using Library Functions