4738|9

71

帖子

0

TA的资源

一粒金砂(初级)

楼主
 

keil求助!!!我是新手,各位大侠帮帮忙!! [复制链接]

我买了个射频收发模块,它自带的数字手册上有它的CRC校验程序如下:
An example implementation of CRC calculation on a message is shown next
// Definitions for CRC constants
#define MSG_CRC_INIT(0xFFFF)
#define MSG_CCITT_CRC_POLY(0x1021)
// Message object structure for sending/receiving messages
typedef struct MsgObj
{
u8 dataLen;
u8 opCode;
u16 data[MSG_MAX_DATA_LENGTH];
u16 crc;
} MsgObj;
// This function updates a running CRC value
void CRC_calcCrc8(u16 *crc_calc, u8 ch)
{
u8 i, v, xor_flag;
// Align test bit with leftmost bit of the message byte.
v = 0x80;
for (i=0; i<8; i++)
{
if (crc_calc & 0x8000)
{
xor_flag = 1;
}
else
{
xor_flag = 0;
}
crc_calc = crc_calc <<1;
if (ch & v)
{
// Append next bit of msg to CRC if it a one. The zero bit placed there by the
shift above need not be changed if the next bit in msg is zero.
crc_calc= crc_calc + 1;
}
if (xor_flag)
{
crc_calc = crc_calc ^ MSG_CCITT_CRC_POLY;
}
// Align test bit with next bit of the message byte. v = v >> 1;
}
}
// This function calculates the CRC for an arbitrary message.
u16 CRC_calcCrcMsgObj(MsgObj *hMsg)
{
u16 crcReg, i;
// Initialize the CRC register
crcReg = MSG_CRC_INIT;
CRC_calcCrc8(&crcReg, MSG_CCITT_CRC_POLY, hMsg->dataLen);
CRC_calcCrc8(&crcReg, MSG_CCITT_CRC_POLY, hMsg->opCode);
for(i=0; idataLen; i++)
{
CRC_calcCrc8(&crcReg, MSG_CCITT_CRC_POLY, hMsg->data);
}
return(crcReg);
}
我自己在keil uvision3上改了改程序,没改完,改后的程序如下:
#include
#define MSG_CRC_INIT 0xFFFF// Definitions for CRC constants
#define MSG_CCITT_CRC_POLY 0x1021// Definitions for CRC constants                     
typedef unsigned char u8;
typedef unsigned int u16;
typedef struct MsgObj// Message object structure for sending/receiving messages
{
        u8 dataLen;
        u8 opCode;
        u8 db[250];
        u16 crc;       
}MsgObj;
void CRC_calcCrc8(u16 *crc_calc, u8 ch);// This function updates a running CRC value
u16 CRC_calcCrcMsgObj(MsgObj *hMsg);// This function calculates the CRC for an arbitrary message.
u16 CRC;
void main()
{
        CRC=0;
        while(1);
}
void CRC_calcCrc8(u16 *crc_calc, u8 ch)
{
        u8 i, v, xor_flag;
        // Align test bit with leftmost bit of the message byte.
        v = 0x80;
        for (i=0; i<8; i++)
        {
                if (crc_calc & 0x8000)
                {
                        xor_flag = 1;
                }
                else
                {
                        xor_flag = 0;
                }
                crc_calc<<=1;
                if (ch & v)
                {
                        /* Append next bit of msg to CRC if it a one. The zero bit placed there by the
               shift above need not be changed if the next bit in msg is zero.*/
                        crc_calc+=1;       
                }
                if (xor_flag)
                {
                    crc_calc = crc_calc ^ MSG_CCITT_CRC_POLY;
                }
                // Align test bit with next bit of the message byte. v = v >> 1;
        }
}
u16 CRC_calcCrcMsgObj(MsgObj *hMsg)
{
         u16 crcReg, i;
         crcReg = MSG_CRC_INIT;// Initialize the CRC register
         CRC_calcCrc8(&crcReg, hMsg->dataLen);
         CRC_calcCrc8(&crcReg, hMsg->opCode);
         for(i=0; idataLen; i++)
         {
                 CRC_calcCrc8(&crcReg, hMsg->db);       
         }
         return(crcReg);
}
编译后在“if (crc_calc & 0x8000)”上出现“error C193:‘&’:bad operand type”的错误,各位大侠帮忙分析分析!!

最新回复

感谢各位的帮助!!问题解决了:操作的应当是crc_calc的值,而不是地址,谢谢tcdzyq的提醒,谢谢大家的帮助!!  详情 回复 发表于 2009-12-16 15:15
点赞 关注

回复
举报

68

帖子

0

TA的资源

一粒金砂(初级)

沙发
 
应该是if (crc_calc &&0x8000)吧。
 
 

回复

91

帖子

0

TA的资源

一粒金砂(初级)

板凳
 
把0x8000用define定义成常量试试
 
 
 

回复

71

帖子

0

TA的资源

一粒金砂(初级)

4
 
u16 *crc_calc 是给指针,if (*crc_calc & 0x8000),但 crc_calc = crc_calc <<1;这就不明白了
 
 
 

回复

85

帖子

0

TA的资源

一粒金砂(初级)

5
 
大家的方法都试过了,还是同样的错误提示出现。后来我怀疑是没编完整造成的原因,就又有把程序编完整了,程序如下:
#include
#define MSG_CRC_INIT 0xFFFF
#define MSG_CCITT_CRC_POLY 0x1021
typedef unsigned char u8;
typedef unsigned int u16;
typedef struct{
        u8 dataLen;
        u8 opCode;
        u8 db[250];
        u16 crc;       
} MSGOBJ;
MSGOBJ message=
{
        0x04;
        0x0b;
        db[250]={0x27,0x0b,0x09,0x41};
        0xfc3b;
},*address;
void CRC_calcCrc8(u16 *crc_calc, u8 ch);
u16 CRC_calcCrcMsgObj(MSGOBJ *hMsg);
u16 CRC;
void main()
{
        CRC=0;
        address=&message;
        CRC=CRC_calcCrcMsgObj(address);
        while(1);
}
void CRC_calcCrc8(u16 *crc_calc, u8 ch)
{
        u8 i, v, xor_flag;
        v = 0x80;
        for (i=0; i<8; i++)
        {
                if (crc_calc & 0x8000)
                {
                        xor_flag = 1;
                }
                else
                {
                        xor_flag = 0;
                }
                crc_calc<<=1;
                if (ch & v)
                {
                crc_calc+=1;       
                }
                if (xor_flag)
                {
                    crc_calc = crc_calc ^ MSG_CCITT_CRC_POLY;
                }
               
        }
}
u16 CRC_calcCrcMsgObj(MSGOBJ *hMsg)
{
         u16 crcReg, i;
         crcReg = MSG_CRC_INIT;
         CRC_calcCrc8(&crcReg, hMsg->dataLen);
         CRC_calcCrc8(&crcReg, hMsg->opCode);
         for(i=0; idataLen; i++)
         {
                 CRC_calcCrc8(&crcReg, hMsg->db);       
         }
         return(crcReg);
}
编译后在“0x04;”一行出现“error C141:syntax error near';'”;
在“0x0b;”一行出现“error C141:syntax error near'0x0b'”;
在“0xfc3b;”一行出现“error C141:syntax error near'0xfc3b'”的错误。
帮帮忙啦,谢谢各位!!!
 
 
 

回复

82

帖子

0

TA的资源

一粒金砂(初级)

6
 
自己查查啊 又不是逻辑错误 编译错误好好查查
 
 
 

回复

67

帖子

0

TA的资源

一粒金砂(初级)

7
 
引用 5 楼 qzf368 的回复:
自己查查啊 又不是逻辑错误 编译错误好好查查


对头。
 
 
 

回复

77

帖子

0

TA的资源

一粒金砂(初级)

8
 
是不是出现中文输入了
 
 
 

回复

67

帖子

0

TA的资源

一粒金砂(初级)

9
 
  1. void CRC_calcCrc8(u16 *crc_calc, u8 ch)
  2. {
  3. u8 i, v, xor_flag;
  4. // Align test bit with leftmost bit of the message byte.
  5. v = 0x80;
  6. for (i=0; i <8; i++)
  7. {
  8. if (*crc_calc & 0x8000)
  9. {
  10. xor_flag = 1;
  11. }
  12. else
  13. {
  14. xor_flag = 0;
  15. }
  16. *crc_calc <<= 1;
  17. if (ch & v)
  18. {
  19. /* Append next bit of msg to CRC if it a one. The zero bit placed there by the
  20.               shift above need not be changed if the next bit in msg is zero.*/
  21. crc_calc+=1;
  22. }
  23. if (xor_flag)
  24. {
  25.     *crc_calc = *crc_calc ^ MSG_CCITT_CRC_POLY;
  26.    
  27. }
  28. // Align test bit with next bit of the message byte. v = v >> 1;
  29. }
  30. }
复制代码

是否crc_calc这样操作?  操作的应当是crc_calc的值,而不是地址.
 
 
 

回复

78

帖子

0

TA的资源

一粒金砂(初级)

10
 
感谢各位的帮助!!问题解决了:操作的应当是crc_calc的值,而不是地址,谢谢tcdzyq的提醒,谢谢大家的帮助!!
 
 
 

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

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/10 下一条
直播报名最后1周:艾迈斯欧司朗 OSP 开放协议,从氛围灯动态照明到传感器交互融合
直播时间:4月22日(周二)10:00
直播奖励:京东卡、蓝牙温湿度计、定制水杯

查看 »

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

 
机器人开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网 13

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表