CodeMonkey 发表于 2013-2-13 16:17:55

求助函数移植

uint16_t fill_tcp_data_p(uint8_t *buf,uint16_t pos, const prog_char *progmem_s)
{
      char c;
      while ((c = pgm_read_byte(progmem_s++))) {
                buf=c;
                pos++;
      }
      return(pos);
}

如何移植到51?

yklstudent 发表于 2013-2-13 18:23:12

你想读取flash内的值?stc不是有内部flash操作函数嘛,去官网找啊

xukai871105 发表于 2013-2-13 19:32:32

prog_char只的是定义在AVR的Flash中的变量,在keil C51中那就只能定义在RAM中了
pgm_read_byte意味读取AVR中的Flash中的变量。uint16_t fill_tcp_data_p(uint8_t *buf,uint16_t pos, const char *progmem_s)
{
char c;
// 循环读取字符串中的每个字节,直到字符串结尾\0
while ((c = progmem_s++))
{
    // 填充负载,长度累加
    buf=c;
    pos++;
}
// 返回总长度
return(pos);
}楼主应该是想通过51来做网页!
我这一句没有看懂?
buf=c;
TCP_CHECKSUM_L_P+3+pos;为什么要加3!!!

CodeMonkey 发表于 2013-2-14 21:53:03

xukai871105 发表于 2013-2-13 19:32 static/image/common/back.gif
prog_char只的是定义在AVR的Flash中的变量,在keil C51中那就只能定义在RAM中了
pgm_read_byte意味读取AVR ...

我打算先做协议,

CodeMonkey 发表于 2013-2-14 21:54:04

TCP校验算法:http://nature0923.blog.51cto.com/202180/589406?

zpxa001 发表于 2013-2-17 11:48:43

xukai871105 发表于 2013-2-13 19:32 static/image/common/back.gif
prog_char只的是定义在AVR的Flash中的变量,在keil C51中那就只能定义在RAM中了
pgm_read_byte意味读取AVR ...

const prog_char *progmem_s;

很显然,const prog_char具有只读属性,应该是定义在ROM中的字节常量,而progmem_s应该是定义在RAM中的指针变量,移植到51无任何悬念:

typedef prog_char unsigned char;
code prog_char *progmem_s;

也即是:

typedef prog_char unsigned char;
code prog_char *data progmem_s;       // small存储类型

code prog_char *pdata progmem_s;   // compactl存储类型

code prog_char *xdata progmem_s;   // large存储类型


xukai871105 发表于 2013-2-17 12:22:19

学习了,平日里51使用的不多!
页: [1]
查看完整版本: 求助函数移植