本帖最后由 ltwsq 于 2015-4-17 13:33 编辑
用CVAVR编写了一段程序,其中定义了一个常量数组。
flash unsigned int level_count[]={ 0x0000,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0002,
0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,
0x0002,0x0002,0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0004,
0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0005,0x0005,0x0005,0x0005,0x0005,0x0005,0x0005,0x0006,
0x0006,0x0006,0x0006,0x0006,0x0006,0x0007,0x0007,0x0007,0x0007,0x0007,0x0008,0x0008,0x0008,0x0008,0x0008,0x0009,
0x0009,0x0009,0x0009,0x000a,0x000a,0x000a,0x000a,0x000b,0x000b,0x000b,0x000c,0x000c,0x000c,0x000d,0x000d,0x000d,
0x000e,0x000e,0x000e,0x000f,0x000f,0x0010,0x0010,0x0011,0x0011,0x0012,0x0012,0x0013,0x0013,0x0014,0x0014,0x0015,
0x0015,0x0016,0x0016,0x0017,0x0018,0x0018,0x0019,0x001a,0x001a,0x001b,0x001c,0x001d,0x001d,0x001e,0x001f,0x0020,
0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,0x0028,0x0029,0x002a,0x002b,0x002c,0x002e,0x002f,0x0030,0x0031,
0x0033,0x0034,0x0036,0x0037,0x0039,0x003a,0x003c,0x003e,0x003f,0x0041,0x0043,0x0045,0x0047,0x0048,0x004a,0x004d,
0x004f,0x0051,0x0053,0x0055,0x0058,0x005a,0x005d,0x005f,0x0062,0x0065,0x0067,0x006a,0x006d,0x0070,0x0073,0x0076,
0x007a,0x007d,0x0081,0x0084,0x0088,0x008c,0x008f,0x0093,0x0097,0x009c,0x00a0,0x00a4,0x00a9,0x00ae,0x00b2,0x00b7,
0x00bc,0x00c2,0x00c7,0x00cd,0x00d2,0x00d8,0x00de,0x00e4,0x00ea,0x00f1,0x00f8,0x00fe,0x0105,0x010d,0x0114,0x011c,
0x0124,0x012a,0x0134,0x013d,0x0145,0x014e,0x0158,0x0161,0x016b,0x0175,0x017f,0x018a,0x0195,0x01a0,0x01ab,0x01b7,
0x01c3,0x01d0,0x01dd,0x01ea,0x01f8,0x0205,0x0214,0x0222,0x0232,0x0241,0x0251,0x0262,0x0272,0x0284,0x0296,0x02a8,
0x02bb,0x02ce,0x02e2,0x02f6,0x030b,0x0321,0x0337,0x034e,0x0365,0x037d,0x0396,0x03af,0x03ca,0x03e4,0x03ff,0x03ff };
使用CVAVR编译时指定了把常量存入Flash。现在在AVR Studio4中使用JTAG ICE进行硬仿真。从加载的数据来看,这个数据已经正确加到Program区。如图2所示。
现在单步执行到i=i_Power_on_level,已经得到i=254,如图3所示。 那么向下执行到OCR1A= level_count,按理就是应该将这个level_count[]常量数组的第254项的值,此时应为0x03FF赋值给OCR1A,但执行之后,OCR1A的值依然是0。如图4所示。 这是为什么呢?给人的感觉好象都没有从常量中取得该得的值。更奇怪的是,如果在AVR Studio4中进行软仿真,这个地方可以按程序的要求得到正确的值,这是为什么呢?
|