搜索
bottom↓
回复: 12

求助,一个小程序,编译报错。error C141

[复制链接]

出0入0汤圆

发表于 2012-2-4 20:57:05 | 显示全部楼层 |阅读模式
编了一个小模块,一个.c文件,一个对应的.h文件。编译后报错,如下:
SRC\LCD_DISPLAY.H(4): error C141: syntax error near 'one', expected ')'

代码包括两部分:
(1)lcd_display.c文件,如下:
#include <AT89X52.H>
#define  LE0 0x01
#define  LE1 0x02
#define  LE2 0x04
#define  LE3 0x08
#define  LE4 0x10
#define  LE5 0x20
#define  LE6 0x40
#define  LE7 0x80
sbit E1=P0^4;
#define  uchar unsigned char

void  delayms(int  xms)
{
    uchar i,j;
    for(i=xms;i>0;i--)
        for(j=110;j>0;j--);
}

void display(uchar one[2][16],uchar two[2][16],uchar three[2][16],uchar four[2][16] )
{
    uchar j;
    E1=0;       
    for(j=0;j<16;j++)
    {
        P0=j;
        P3=LE0;
        P2=one[0][j];
        P3=LE1;
        P2=one[1][j];
                                         
        P3=LE2;
        P2=two[0][j];
        P3=LE3;
        P2=two[1][j];
                                                                 
        P3=LE4;
        P2=three[0][j];
        P3=LE5;
        P2=three[1][j];
        
        P3=LE6;
        P2=four[0][j];
        P3=LE7;
        P2=four[1][j];
        delayms(5);
    }       
}

(2)这个是对应的lcd_display.h文件,代码如下:
#ifndef __LCD_DISPLAY_H__
#define  __LCD_DISPLAY_H__

extern void display(uchar one,uchar two,uchar three,uchar four);

extern void delayms(int  xms);

#endif


本人实在检查不出来哪里有问题,求助论坛高手。

出0入0汤圆

发表于 2012-2-4 21:16:03 | 显示全部楼层
display参数类型错了

出0入0汤圆

 楼主| 发表于 2012-2-4 21:23:53 | 显示全部楼层
回复【1楼】learner123
-----------------------------------------------------------------------

是这句“extern void display(uchar one,uchar two,uchar three,uchar four);”有问题吗? 需要怎么改呢?还请指教

出0入0汤圆

发表于 2012-2-4 21:58:23 | 显示全部楼层
参数为指针型

出0入0汤圆

 楼主| 发表于 2012-2-6 10:27:34 | 显示全部楼层
问题已解决,我自己来回复一下。其实在这两个文件之外,我还写了一个main函数,main函数是这样写的。
#include <AT89X52.H>
#include "lcd_display.h"
//#include "SoundPlay.h"
#define  uchar unsigned char

uchar code yin[2][16]={{0x40,0x80,0xFC,0x00,0x10,0x20,0xFF,0x00,0xF8,0x08,0x08,0xF8,0x08,0x08,0xF8,0x08},
{0x00,0x00,0x1F,0x00,0x04,0x02,0x7F,0x00,0x0F,0x08,0x08,0x0F,0x08,0x08,0x0F,0x08}};/*"音",0*/
uchar code yue[2][16]={{0x00,0x00,0xF8,0x08,0x88,0x84,0x84,0xFC,0x80,0x90,0x90,0x88,0x84,0x82,0xA0,0x40},
{0x04,0x0F,0x00,0x00,0x00,0x00,0x00,0x3F,0x00,0x04,0x08,0x10,0x20,0x20,0x00,0x00}};/*“乐”*/
uchar code zhi[2][16]={{0x40,0x80,0x80,0x00,0xFE,0x00,0x00,0x00,0x00,0x80,0x40,0x20,0x18,0x24,0xC2,0x00},
{0x00,0x00,0x00,0x00,0x1F,0x08,0x04,0x02,0x01,0x00,0x00,0x00,0x00,0x00,0x7F,0x00}};/*"之",0*/
uchar code sheng[2][16]={{0x80,0x80,0xFF,0x80,0xFE,0x00,0xFC,0x84,0x84,0xFC,0x04,0x04,0x04,0x02,0x02,0x01},
{0x00,0x00,0x7F,0x00,0x3F,0x00,0x1F,0x10,0x10,0x1F,0x00,0x00,0x00,0x00,0x00,0x00}};/*"声",0*/

void main()
{
    while(1)
    {  
        display (yin,yue,zhi,sheng);
    }
}


因为在网上看到关于模块化程序的文章说,不要在头文件里面定义变量,所以关于字码的二维数组定义就放在了main函数里面。当我把四个字码的数组定义放到lcd_display.h中之后,编译之后没有报错。程序没有问题了。

出0入0汤圆

 楼主| 发表于 2012-2-6 10:39:49 | 显示全部楼层
回复【4楼】spegar2011
-----------------------------------------------------------------------

我又试了一下,还有一种方法,这种方法是不在.h里面定义变量,在main函数里面定义字码的数组值,然后在.h里面extern声明一下。

出0入30汤圆

发表于 2012-2-6 11:29:01 | 显示全部楼层
基本功。很重要。

出0入0汤圆

发表于 2012-2-6 12:02:55 | 显示全部楼层
回复【楼主位】spegar2011
-----------------------------------------------------------------------

你定义的参数是数组参数,
void display(uchar one[2][16],uchar two[2][16],uchar three[2][16],uchar four[2][16] )

你声明的参数是字节类型,
extern void display(uchar one,uchar two,uchar three,uchar four);

//
void display(uchar *one,uchar *two,uchar *three,uchar *four)
{
    uchar j;
    E1=0;
    for(j=0;j<16;j++)
    {
        P0=j;
        P3=LE0;
        P2=one[j];
        P3=LE1;
        P2=one[16+j];
           
        P3=LE2;
        P2=two[0];
        P3=LE3;
        P2=two[16+j];
           
        P3=LE4;
        P2=three[j];
        P3=LE5;
        P2=three[16+j];
         
        P3=LE6;
        P2=four[j];
        P3=LE7;
        P2=four[16+j];
        delayms(5);
    }

}

extern void display(uchar *one,uchar *two,uchar *three,uchar *four);

出0入0汤圆

 楼主| 发表于 2012-2-6 19:56:10 | 显示全部楼层
回复【6楼】lovelywwei
-----------------------------------------------------------------------

确实很重要,一步一个脚印把基础打牢了,要不然以后往后学习还得回来补基础。

出0入0汤圆

发表于 2012-2-12 21:48:40 | 显示全部楼层
MARK

出0入0汤圆

发表于 2012-2-12 21:52:11 | 显示全部楼层
以前基本功踩了假水。。。。。。飘过

出0入0汤圆

发表于 2012-2-12 22:12:55 | 显示全部楼层
"不要在头文件里面定义变量,"

that's generally true.

each variable declaration in each invokation of the header file will create a private copy of that variable, each not with their scope.

"所以关于字码的二维数组定义就放在了main函数里面。当我把四个字码的数组定义放到lcd_display.h中之后,编译之后没有报错。程序没有问题了。"

you still do not understand what went wrong. many people have pointed this out for you: the declarations for the display() function are inconsistent between the header file and the source file.

出0入0汤圆

发表于 2012-2-13 11:40:37 | 显示全部楼层
指针真难用啊。不过它是个很 好的东西,一直都学不会,闷。。
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-8 03:11

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表