打印

常量表格编译的错误,谢谢大家帮助

[复制链接]
2146|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
neaphy|  楼主 | 2007-12-3 23:32 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
编译器是PICC
程序有点大,分模块写的,编译时CRC校验定义的表格有问题,帖一下相关的:

/****************   CRC.h  **************************/

#ifdef CRC_GLOBALS
    #define CRC_EXT
#else
    #define CRC_EXT extern
#endif

CRC_EXT const uchar CRCHi[256]={....}; //数据省略
CRC_EXT const uchar CRCLo[256]={....};

CRC_EXT uint CRC16(bank2 uchar *puchMsg, uchar usDataLen );

/******************************************************/

/******************** CRC.c ***************************/
/****************就是个CRC校验的函数没什么说的*********/
#define CRC_GLOBALS
#include"includes.h"  //这个文件已经包含了CRC.h
uint CRC16(bank2 uchar *puchMsg, uchar usDataLen ) /* The function returns the CRC as a unsigned short type */
{
    uchar uchCRCHi=0xFF; /* high byte of CRC initialized */
    uchar uchCRCLo=0xFF; /* low byte of CRC initialized */
    uint uIndex; /* will index into CRC lookup table */
    const uchar *PHi;
    const uchar *PLo;
    PHi=CRCHi;
    PLo=CRCLo;
    while(usDataLen--) /* pass through message buffer */
    {
        uIndex=uchCRCLo^(*puchMsg++); /* calculate the CRC */
        //uchCRCLo=uchCRCHi^CRCHi[uIndex];
        uchCRCLo=uchCRCHi^(*(PHi+uIndex));
        //uchCRCHi=CRCLo[uIndex];
        uchCRCHi=*(PLo+uIndex);
    }
    return (uchCRCHi<<8|uchCRCLo);
}

/**************************************************************/


               
             我在另外两个.C模块中调用上面CRC校验函数
/*********************  RTU.c  *********************************/
#define RTU_GLOBALS
#include"includes.h"
....
void RTUReceive(void)
{
  ....
  CRCTmp1=CRC16(ptr1, DataLen1 );
  ....
  
}
....
/******************************************************************/


/*************************  RTUSlave.c  **************************/
#define RTUSlave_GLOBALS
#include"includes.h"
...
void RepuCheck(void)
{
    ....
    CRCTmp2=CRC16(ptr2, DataLen2 );
    ....
}
...
/*******************************************************************/


就在这两个地方用了,因为我原来在51单片机上写没什么问题的,可是在pic上编译有问题,我用pic16f877a :
Error   [482] ; . symbol "_CRCHi" is defined more than once in "ApplMain.obj"
Error   [482] ; . symbol "_CRCLo" is defined more than once in "ApplMain.obj"
Error   [482] ; . symbol "_CRCHi" is defined more than once in "ApplMain.obj"
Error   [482] ; . symbol "_CRCLo" is defined more than once in "ApplMain.obj"
Error   [482] ; . symbol "_CRCHi" is defined more than once in "ApplMain.obj"
Error   [482] ; . symbol "_CRCLo" is defined more than once in "ApplMain.obj"
Error   [482] ; . symbol "_CRCHi" is defined more than once in "ApplMain.obj"
Error   [482] ; . symbol "_CRCLo" is defined more than once in "ApplMain.obj"
Error   [482] ; . symbol "_CRCHi" is defined more than once in "ApplMain.obj"
Error   [482] ; . symbol "_CRCLo" is defined more than once in "ApplMain.obj"
Error   [482] ; . symbol "_CRCHi" is defined more than once in "ApplMain.obj"
Error   [482] ; . symbol "_CRCLo" is defined more than once in "ApplMain.obj"
...

我实在想不出那里把它重定义了,好象语法没错误(提示是"_CRCHi"不是"CRCHi")

谢谢各位了,第一用pic
沙发
shishaojun| | 2007-12-4 08:24 | 只看该作者

"_CRCHi是CRCHi再obj中的符号

呵呵。好像是ucosii的编程风格啊

你把这个表格定义给搞成只一处定义和声明。。。。我用的是ccs。不台知道picc的特性

使用特权

评论回复
板凳
neaphy|  楼主 | 2007-12-4 18:54 | 只看该作者

其它变量都是这样定义的

ccs我也试了一下,好象只认main模块,其它的.c模块都要给include进来,感觉对分模块写不太好,也许是我的习惯问题....

#ifdef CRC_GLOBALS
    #define CRC_EXT
#else
    #define CRC_EXT extern
#endif

这个表格只在CRC.c中定义,在其它模块用时包含了CRC.h,会被extern申明外部的.我其它变量都是这么弄的,没什么问题,不知道怎么会事,谢谢大家帮忙给点意见,谢谢了

使用特权

评论回复
地板
ayb_ice| | 2007-12-4 20:33 | 只看该作者

这和第一次使用PICC没有任何关系

你见过声明外部变量带初始化的吗。。。

使用特权

评论回复
5
neaphy|  楼主 | 2007-12-4 22:00 | 只看该作者

谢谢

非常感谢LS

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

5

主题

69

帖子

0

粉丝