Table of Contents        Previous topic       Next topic       

C COMPILER->Accessing the 8051 Internal Registers->SFR Bytes

The _sfr keyword is used to declare an identifier which accesses an 8 bit wide location in sfr data space.  The format for the declaration is:

_sfr <identifier name> = <address>;

For example:

_sfr  InputPort = 0XA0;

declares InputPort to be address A0 hex in sfr address space.

When you assign a value to InputPort the value is written to address A0.  For example:

InputPort = 0X20;

writes 20 hex to address A0.

When you assign InputPort to another variable, or use Inputport in an expression, the value is read from address A0.  For example:

unsigned char nPortValue;
nPortValue = InputPort;

read from address A0 and places the result in variable nPortValue.

When you OR InputPort with a variable (or a constant), the value is read from address A0, ORed with the variable and written back to address A0.  For example:

unsigned char nPortValue = 0X32;
InputPort |= nPortValue;

read the value from address A0, OR's it with the value of nPortValue and writes the result back to A0.