标题: 51单片机keil编译错误error C141: syntax error near ';', expected 'hdata' [打印本页]

作者: Flynnkk    时间: 2021-7-27 14:35
标题: 51单片机keil编译错误error C141: syntax error near ';', expected 'hdata'
编译错误如下:
template.c(173): error C141: syntax error near ';', expected 'hdata'
template.c(206): error C141: syntax error near ';', expected 'hdata'
template.c(208): error C202: 'i': undefined identifier
template.c(209): error C202: 'i': undefined identifier
template.c(211): error C202: 'j': undefined identifier


代码如下:
//独立按键(加消抖)
#include<reg52.h>
#define uint unsigned int;
#define uchar unsigned char;
sbit LED1=P1^0;
sbit KEY1=P3^4;
sbit dula=P2^6;
sbit wela=P2^7;
uchar disnum;
uchar code table_du[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,                                //数码管段选编码
                          0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
delay(uchar);
void main()
{
        KEY1=1;
        P0=0xfe;
        wela=1;
        wela=0;
        while(1)
        {
                if(KEY1==0)
                {
                        delay(10);     //延时10ms
                        if(KEY1==0)    //消除前沿抖动
                        {
                                LED1=0;
                                disnum++;
                                if(disnum==10)
                                disnum=0;
                                while(!KEY1); //按键松手检测
                                delay(10);
                                while(!KEY1); //消除后沿抖动
                    }
                }
                else
                {
                        LED1=1;
                        P0=table_du[disnum];
                        dula=1;
                        dula=0;
                }
        }
}

delay(uchar x)
{
        uchar i,j;
        for(i=0;i<x;i++)
        {
                for(j=0;j<200;j++);
        }
}




作者: kern..    时间: 2021-7-27 16:29
i j 定义的类型不对 要么字符 要么数字  咋字符和数字一起了
作者: lkc8210    时间: 2021-7-27 16:41
不要用#define
#define uint unsigned int;
#define uchar unsigned char;
改用 typedef
typedef unsigned int uint;
typedef unsigned char uchar;
作者: wojiaoguogai    时间: 2021-7-27 16:47
函数不写返回值类型吗
作者: angmall    时间: 2021-7-27 16:54
你可以用
#define uint unsigned int        //不要添加分号
#define uchar unsigned char   //不要添加分号
改用 typedef
typedef unsigned int uint;       //要添加分号
typedef unsigned char uchar;  //要添加分号

作者: 效果也很好    时间: 2021-7-27 17:07
#define 是宏定义 不用加分号
typedef  是类型重定义 得加分号
作者: Flynnkk    时间: 2021-7-27 17:09
效果也很好 发表于 2021-7-27 17:07
#define 是宏定义 不用加分号
typedef  是类型重定义 得加分号

懂了 谢谢!
作者: Flynnkk    时间: 2021-7-27 17:09
lkc8210 发表于 2021-7-27 16:41
不要用#define
#define uint unsigned int;
#define uchar unsigned char;

懂了 谢谢
作者: Flynnkk    时间: 2021-7-27 17:09
angmall 发表于 2021-7-27 16:54
你可以用
#define uint unsigned int        //不要添加分号
#define uchar unsigned char   //不要添加 ...

懂了 谢谢
作者: 云雀在天    时间: 2021-7-28 21:01
#define uint unsigned int;
#define uchar unsigned char;
这两行不要加分号




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1