Click the above “Chuangxue Electronics” to follow for easy learning of electronic knowledge.
Keil C51 memory areas are divided into two main types: program memory area and data memory area.
1. Program Memory Area:
To store declared data in the program memory area, you can use the keyword “code” to specify.
For example, unsigned char code i=10;
indicates that i is an unsigned character type data stored in the program memory area.
2. Data Memory Area:
The data memory area is divided into internal data memory, external data memory, and special function register addressing area.
1. Internal Data Memory: You can use the keywords “data, idata, bdata” for appropriate specification.
data: Direct addressing area, the declared data storage range is the lower 128 bytes of internal RAM 0X00~0X7F.
For example, unsigned char data i=10;
indicates that i is an unsigned character type data stored in the lower 128 bytes of the data memory area (RAM).
idata: Indirect addressing area, the declared data storage range is the entire internal RAM area 0X00~0XFF.
For example, unsigned char idata i=10;
indicates that i is an unsigned character type data stored in the data memory area (RAM).
bdata: Bit-addressable area, with an addressing range of 0X20~0X2F.
2. External Data Memory: You can use the keywords “pdata, xdata” for specification.
pdata: Mainly used in compact mode, it can access one page (256 bytes) of external RAM, meaning that accessing data defined by pdata does not affect the output level of port P2 (when accessing certain self-extended external RAM, it does not affect I/O ports).
For example, unsigned char pdata i;
indicates that i is an unsigned character type data stored in the external data memory area (RAM) (can only be within one page range), and which page to operate on can be set by other I/O ports.
xdata: Can access 64k of external data storage, with an address range of 0X0000~0XFFFF, and like pdata, accessing the chip’s own internal extended RAM does not affect I/O ports.
For example, unsigned char xdata i;
indicates that i is an unsigned character type data stored in the external data memory area (RAM).
3. Special Function Register Addressing Area (SFR): The 8051 provides a 128-byte SFR addressing area, which can be byte-addressable, word-addressable, and addresses divisible by 8 can also be bit-addressable. This area is used to control timers, counters, serial ports, and other peripheral interfaces. Use the keywords “sfr, sfr16, sbit” for appropriate declaration.
For example, byte-addressing sfr P0=0x80;
indicates that the P0 port address is 80H, where “=” is followed by a constant between 0X00~0XFF.
Word-addressing sfr16 T2=0XCC;
specifies Timer2 port address T2L=0XCC T2H=0XCD.
Bit-addressing sbit EA=0xAF;
specifies that the 0xAF bit is EA, which means interrupt enable.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >
==> Visit www.eeskill.com to learn more!