这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 综合技术 » 基础知识 » GCC 请教GCC

共2条 1/1 1 跳转至

GCC 请教GCC

院士
2006-09-17 18:14:16     打赏
GCC 请教GCC



关键词: 请教    

院士
2006-12-22 22:43:00     打赏
2楼
问 prog_char StrLength[396]={4,26,18,6,18,34,16,30,24,36,
                          30,10,12,46,24,8,8,12,18,40,
                          20,2,22,14,10,10,10,6,24,6,
                          20,24,20,12,20,30,30,10,24,
                          34,2,14,10,10,14,2,24,12,2,
                          8,6,16,6,12,12,24,30,10,24,
                          6,14,36,32,16,14,18,2,20,16,
                          28,12,8,16,24,26,2,16,16,34,
                          22,24,30,30,2,2,88,4,12,22,
                          18,20,34,2,4,14,30,18,36,12,
                          6,22,6,32,6,12,4,14,38,6,18,
                          34,4,8,10,18,14,36,18,10,28,
                          28,42,12,20,108,36,78,26,56,
                          50,40,50,4,34,52,14,18,22,6,
                          10,14,14,8,30,8,4,8,8,14,10,
                          8,4,16,22,8,8,14,6,30,14,18,
                          6,22,6,68,28,24,24,10,24,28,
                          22,18,12,40,12,4,14,24,28,18,
                          12,18,12,24,2,32,6,16,28,18,
                          16,4,12,12,2,36,6,30,14,10,6,
                          2,10,2,4,2,2,22,14,4,4,14,2,
                          12,8,8,6,2,4,8,2,2,14,14,12,
                          16,10,14,18,4,28,36,8,8,4,10,
                          18,16,2,30,72,6,44,16,30,10,
                          22,26,4,16,26,22,16,4,8,10,
                          6,4,20,4,2,20,6,20,4,6,4,4,
                          6,8,8,6,8,6,2,2,18,4,34,16,22,
                          24,34,22,96,20,66,4,8,4,6,8,8,
                          8,30,16,8,22,6,22,6,16,18,18,36,
                          26,22,2,8,30,16,12,6,20,26,8,22,
                          4,12,8,22,14,4,34,20,66,20,6,18,
                          58,68,24,54,40,34,40,20,28,14,20,
                          38,20,14,28,32,66,34,34,30,106,32,
                          36,2,30,40,88,40,18,24,8,16,8,6,
                          28,8,2,2,6,26,14,34,32,22,22,34,
                          28,86,22,28,52,2,2,10,16,12,4,
                          20,28,14,8,16,6,8,4,14};    


mLatterIndex=1;
    set_lcd_xy(100,100);
    sl=StrLength[mLatterIndex];
    Disp_Int(sl,3);
    set_lcd_xy(200,100);
    sl=StrLength[1];
    Disp_Int(sl,3);
不知为什么,对于StrLength这个数组,以上两种调用方式得到的结果不一样,不知为什么,这个数组在FLASH里面.请高手指教,急急急. 1: 结果分别是:243和26 2: 好象不能这样调用吧要用专门的命令,我不记得了,要找找资料 3: lornboat兄,帮找一下,谢谢. 4: 看AVR-LIB文档读取FLASH里的数据有专门的宏。 5: 用pgm_read_byte()函数
  用pgm_read_byte()函数,必须包括头文件“AVR/pgmspace.h"。
以下是一段程序,希望对你有用:
  #include "AVR/io.h"
#include "AVR/pgmspace.h"

char mLatterIndex;
char sl;
char sll;
const char StrLength[] PROGMEM={4,26,18,6,18,34,16,30,24,36,
                          30,10,12,46,24,8,8,12,18,40,
                          20,2,22,14,10,10,10,6,24,6,
                          20,24,20,12,20,30,30,10,24,
                          34,2,14,10,10,14,2,24,12,2,
                          8,6,16,6,12,12,24,30,10,24,
                          6,14,36,32,16,14,18,2,20,16,
                          28,12,8,16,24,26,2,16,16,34,
                          22,24,30,30,2,2,88,4,12,22,
                          18,20,34,2,4,14,30,18,36,12,
                          6,22,6,32,6,12,4,14,38,6,18,
                          34,4,8,10,18,14,36,18,10,28,
                          28,42,12,20,108,36,78,26,56,
                          50,40,50,4,34,52,14,18,22,6,
                          10,14,14,8,30,8,4,8,8,14,10,
                          8,4,16,22,8,8,14,6,30,14,18,
                          6,22,6,68,28,24,24,10,24,28,
                          22,18,12,40,12,4,14,24,28,18,
                          12,18,12,24,2,32,6,16,28,18,
                          16,4,12,12,2,36,6,30,14,10,6,
                          2,10,2,4,2,2,22,14,4,4,14,2,
                          12,8,8,6,2,4,8,2,2,14,14,12,
                          16,10,14,18,4,28,36,8,8,4,10,
                          18,16,2,30,72,6,44,16,30,10,
                          22,26,4,16,26,22,16,4,8,10,
                          6,4,20,4,2,20,6,20,4,6,4,4,
                          6,8,8,6,8,6,2,2,18,4,34,16,22,
                          24,34,22,96,20,66,4,8,4,6,8,8,
                          8,30,16,8,22,6,22,6,16,18,18,36,
                          26,22,2,8,30,16,12,6,20,26,8,22,
                          4,12,8,22,14,4,34,20,66,20,6,18,
                          58,68,24,54,40,34,40,20,28,14,20,
                          38,20,14,28,32,66,34,34,30,106,32,
                          36,2,30,40,88,40,18,24,8,16,8,6,
                          28,8,2,2,6,26,14,34,32,22,22,34,
                          28,86,22,28,52,2,2,10,16,12,4,
                          20,28,14,8,16,6,8,4,14};    

void main(void)
{
    mLatterIndex=1;
    //set_lcd_xy(100,100);
    sl=pgm_read_byte(&StrLength[mLatterIndex]);//pgm_read_byte(address short)
    //Disp_Int(sl,3);
    //set_lcd_xy(200,100);
    sll=pgm_read_byte(&StrLength[1]);
   // Disp_Int(sl,3);
}

6: 谢谢lee_t_1000谢谢lee_t_1000大哥,你解决了我n天未解决的问题,谢谢!!! 7: 我用的是PRG_RDB这个宏,问题解决了但又有一个新的问题:
#include <AVR/pgmspace.h>
const char foo[] PROGMEM = "Foo";
const char bar[] PROGMEM = "Bar";
PGM_P array[2] PROGMEM = {
foo,
bar
};
int main (void)
{
char buf[32];
strcpy_P (buf, array[1]);
return 0;
}

这是LIB文档上的例子,变量为PGM_P指针形的,这时如果将其中的array[1]改为
i=1;
array[i];
同样读取的数据不对,这个如何解决.请教高手. 8: 请问请问const char StrLength[] PROGMEM={4,26,18,6,18,34,16,30,24,36,、、、、}
这段数组是否是存在flash还是rom里还是每次都有程序调到ram里啊? 9: 就是在Flash里,是一组常数,死的

共2条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]