搜索
bottom↓
回复: 4

avr中flash读写的问题

[复制链接]

出0入0汤圆

发表于 2008-7-22 17:17:46 | 显示全部楼层 |阅读模式
avr中操作flash就必须用pgm_read_byte吗?用指针打过去行不行?
我在程序里定义了一个数组
const unsigned int DispHandlerTable[8][9]={略},是存在ram里的,调用的时候chf(&(DispHandlerTable[0][0])),一点问题没有
但当我把它放到flash中时const unsigned int DispHandlerTable[8][9] PROGMEM={略},还是那样调用,结果就不对了。
难道flash中的数不能通过指针访问吗?一定要用pgm_read_byte或pgm_read_word?

出0入0汤圆

发表于 2008-7-22 17:24:45 | 显示全部楼层
FLASH中的数据通常只能读。

当然可以使用指针方式读,但指向RAM的指针和指向FLASH的指针的类型和定义是不同的。这些是扩展的C,每个平台不同,请参考你所使用C平台的HELP,里面肯定有帮助说明。锻炼锻炼吧。

出0入0汤圆

发表于 2008-7-22 20:34:06 | 显示全部楼层
楼主应当先了解avr的架构,avr对ram和flash是独立编址的,ram是按8位编址,而flash却按16位编址,读ram和读flash的汇编指令也是不同的,所以指向ram的指针和指向flash的指针必须区别对待。对flash的读取,必须先使用专门读flash的指令取到寄存器中,然后再作运算,pgm_read_xxx宏定义其实就是一段包括了flash读取指令的内联汇编代码。

出0入0汤圆

发表于 2008-7-22 20:51:38 | 显示全部楼层
2.3.1 Von Neumann

Von Neumann architecture has a single, common memory space where both program instructions and data are stored. There is a single data bus which fetches both instructions and data. Each time the CPU fetches a program instruction it may have to perform one or more read/write operations to data memory space. It must wait until these subsequent operations are complete before it can fetch and decode the next program instruction. The advantage to this architecture lies in its simplicity and economy.


2.3.3 Harvard

Harvard architecture computers have separate memory areas for program instructions and data. There are two or more internal data buses which allow simultaneous access to both instructions and data. The CPU fetches instructions on the program memory bus. If the fetched instruction requires an operation on data memory, the CPU can fetch the next program instruction while it uses the data bus for its data operation. This speeds up execution time at the cost of more hardware complexity.

Since Harvard machines assume that only instructions are stored in program memory space, how do you write and access data stored in program memory space? For example, a data value declared as a C constant must be stored in ROM as a constant value. Different microcontrollers have different solutions to this problem. A good C compiler automatically generates the code to suit the target hardware’s requirements.

Some chips have special instructions allowing the retrieval of information from program memory space. These instructions are always more complex or expensive than the equivalent instructions for fetching data from data memory
Typically these chips have a register analogous to the program counter (PC) which refers to addresses in program space. Also, some chips support the use of any 16 bit value contained in data space as a pointer into the program address space. These chips have special instructions to use these data pointers.

=======================================================================
学校里学的是标准C,标准C是按Von Neumann结构为基础的。
而AVR,51等不是采用Von Neumann结构,是Harvard结构的。所以针对这些芯片开发的C平台,都不是标准C。

出0入0汤圆

发表于 2009-10-23 15:35:57 | 显示全部楼层
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-2 10:19

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表