免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1433 | 回复: 0
打印 上一主题 下一主题

8051 内存结构和数据存储类型 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-21 08:43 |只看该作者 |倒序浏览
8051 和 x86 在内存结构方面很大不同。
  • 8051:内存分为物理上独立的若干区域(Memeory Areas/Spaces)。
  • x86:  内存连续编址,数据、程序放在同一个连续的地址空间

在Keil C中声明变量,可以使用存储类型标识符(memory type specifier)来说明变量的存储的内存区域,以此提高代码执行效率。存储标识符包括: code, data, idata, xdata, pdata, etc.

注意区分:变量的数据类型(Data Type)存储类型(Memory Type)


8051 Memory Areas
Program Memory
Program (CODE) memory is read only; it cannot be written to. Program memory may reside within the 8051 MCU, it may be external, or it may be both, depending upon the 8051 derivative and the hardware design.
  • The 8051 architecture supports up to 64K Bytes of program memory. However, program space can be expanded using code banking.
  • Some devices offer a larger code space.
  • Program code, including all functions and library routines, is stored in program memory.
  • Constant variables may also be stored in program memory.
  • The 8051 executes programs stored in program memory only.
  • Program memory may be accessed from your C programs using the code memory type specifier.

Note

  • Program memory may be accessed indirectly using the MOVC instruction. It may not be accessed directly.

Internal Data Memory

Internal data memory resides within the 8051 MCU and is read/write. Up to 256 bytes of internal data memory are available depending upon the 8051 derivative. The first 128 bytes of internal data memory (from 0x00 to ox7F) are both directly and indirectly addressable. The upper 128 bytes of data memory (from 0x80 to 0xFF) can be addressed only indirectly (this address space, when accessed directly, is mapped to SFRs). There is also a 16 byte area starting at 20h that is bit-addressable. (NOTE: The upper 128 bytes of data memory and SFR are DIFFERENT! Although both are marked with same address numbers, 0x80 ~ 0xFF)

Access to internal data memory is very fast because it can be accessed using an 8-bit address. However, internal data memory is limited to a maximum of 256 bytes.

Internal data can be broken down into three distinct memory types: data, idata, and bdata.

  • The data memory specifier always refers to the first 128 bytes of internal data memory. Variables stored here are accessed using direct addressing.
  • The idata memory specifier refers to all 256 bytes of internal data memory; however, this memory type specifier code is generated by indirect addressing which is slower than direct addressing.
  • The bdata memory specifier refers to the 16 bytes of bit-addressable memory in the internal data area (20h to 2Fh). This memory type specifier allows you to declare data types that may also be accessed at the bit level.

External Data Memory

External data memory is read/write. Since external data memory is indirectly accessed through a data pointer register (which must be loaded with an address), it is slower than access to internal data memory.

Several 8051 devices provide on-chip XRAM space that is accessed with the same instructions as the traditional external data space. This XRAM space is typically enabled via dedicated chip configuration SFR registers and overlaps the external memory space.

There may be up to 64K Bytes of external data memory; though, this address space does not necessarily have to be used as memory. Your hardware design may map peripheral devices into the memory space. If this is the case, your program would access external data memory to program and control the peripheral. This technique is referred to as memory-mapped I/O.

The C51 Compiler offers two memory types that access external data: xdata and pdata.

  • The xdata memory specifier refers to any location in the 64K Byte address space of external data memory. The large memory model locates variables in this memory space.
  • The pdata memory type specifier refers to exactly one (1) page (256 bytes) of external data memory. The compact memory model locates variables in this memory space.

Note

  • External data memory may be accessed indirectly using the MOVX instruction. It may not be accessed directly.

REFERENCE
*) Memory Areas, http://www.keil.com/support/man/docs/c51/c51_le_memareas.htm
*) http://blog.csdn.net/sky0829/archive/2010/11/08/5995093.aspx

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP