找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 5973|回复: 3
打印 上一主题 下一主题
收起左侧

单片机运行老是出现这些错误 error C141: syntax error near 'if'

[复制链接]
跳转到指定楼层
楼主
Build target '目标 1'
compiling 十花样.c...
十花样.C(94): error C141: syntax error near 'if'
十花样.C(94): error C141: syntax error near '==', expected ')'
十花样.C(94): error C129: missing ';' before '=='
目标未创建

单片机源程序如下:
#include<reg51.h>
#define        false 0
#define        true 1
#define uchar unsigned char
#define uint unsigned int
sbit pause_key=P3^0;
sbit auto_key=P3^1;
sbit change_key=P3^2;
sbit pauseLed=P3^6;
sbit autoLed=P3^7;
int ledCode[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f} ;
int ledCode2[8]={0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00} ;
int disCode[10]={0x03,0x9f,0x25,0x0d,0x99,0x49,0x41,0x1f,0x01,0x09}        ;
void displayLed(void);
void keyScan(void) ;
void Delay10ms( unsigned int n);
bit isPause=false;
bit isAuto=true;
bit isChange=false;
uchar  time;
uchar types;
uchar counts;
void T0_INT(void)   interrupt 1
{
TL0=(65536-50000)/256;
TH0=(65536-50000)%256;
time++;
if(time>=10)
{
time=0;
if(isChange==true)
{
counts=0;
types++;
if(types>9)types=0;
P0=disCode[types] ;
isChange=false;
}
displayLed();
counts++;
}
}
void main(void)
{
TMOD=0x61;
TL0=(65536-50000)/256;
TH0=(65536-50000)%256;
TR0=1;
ET0=1;
EA=1;
time=0;
counts=0;
types=0;
pauseLed=0;
P0=disCode[types] ;
while(1)

{
keyScan();
}
}
void keyScan(void)
{
if(pause_key==0)
{
Delay10ms(1);
if(pause_key==0)
{
isPause=~isPause;
pauseLed=isPause ;
if(isPause==true)
{
ET0=0;
P0=0xfd;
P1=0x00;
P2=0x00;
}
else
{
ET0=1;
P0=disCode[types];
displayLed();
}
while(pause_key==0);
}
}
if(auto_key==0)
{
isAuto=~isAuto;
autoLed=isAuto;
}
while(auto_key==0);
}
if(change_key==0&&isAuto==false)   
{
Delay10ms(1);
if(change_key==0)
{
isChange=true;
}
while (change_key==0);
}

void displayLed(void)
{
switch(types)
{
case:0
{
if(counts>=16)counts=0;
if(counts>=15)
{
if(isAuto==true)   isChange=true;
}
if(counts<8)
{
P1=0xff;
P2=ledCode[7-counts];
}
else
{
P1=ledCode[15-counts];
P2=0xff;
}
break;
}
case 1:
{
if(counts>=16)counts=0;
if(counts>=15)
{
if(isAuto==true)isChange=true;
}
if(counts<8)
{
P1=ledCode[counts];
P2=0xff;
}
else
{
P1=0xff;
P2=ledCode[counts-8];
}
break;
}
case 2:
{
if(counts>=16)counts=0;
if(counts>=15)
{
if(isAuto==true)   isChange=true;
}
if(counts%2==0)
{
P1=0xaa;
P2=0xaa;
}
else
{
P1=0x55;
P2=0x55;
}
break;
}
case 3:
{
if(counts>=8)counts=0;
if(counts>=7)
{
if(isAuto==true)isChange=true;
}
P1=ledCode[7-counts];
P2=ledCode[7-counts];
break;
}
case 4:
{
if(counts>=8)counts=0;
if(counts>=7)
{
if(isAuto==true)isChange=true;
}
P1=ledCode[counts];
P2=ledCode[counts];
break;
}
case 5:
{
if(counts>=17)counts=0;
if(counts<8)
{
P1=~ledCode2[7-counts];
P2=0xff;
}
else if(counts<16)
{
P1=0x00;
P2=~ledCode2[15-counts];
}
else
{
P1=0x00;
P2=0x00;
if(isAuto==true)isChange=true;
}
break;
}
case 6:
{
if(counts>=17)counts=0;
if(counts<8)
{
P1=ledCode2[7-counts];
P2=0x00;
}
else if(counts<16)
{
P1=0xff;
P2=ledCode2[15-counts];
}
  else
{
P1=0xff;
P2=0xff;
if(isAuto==true)isChange=true;
}
break;
}
case 7:
{
if(counts>=17)counts=0;
if(counts<8)
{
P1=0xff;
P2=ledCode2[counts];
}
else if(counts<16)
{
P1=ledCode2[counts-7];
P2=0x00;
}
  else
{
P1=0x00;
P2=0x00;
if(isAuto==true)isChange=true;
}
break;
}
case 8:
{
if(counts>=17)counts=0;
if(counts<8)
{
P1=0x00;
P2=~ledCode2[counts];
}
else if(counts<16)
{
P1=~ledCode2[counts-7];
P2=0xff;
}
  else
{
P1=0xff;
P2=0xff;
if(isAuto==true)isChange=true;
}
break;
}
case 9:
{
if(counts>=255)counts=0;
if(counts==254&&isAuto==true)
isChange=true;
P1=        ~counts;
P2=        ~counts;
break;
}
default:
types=0;
P0=disCode[types];
}
}
void Delay10ms( unsigned int n)
{
  unsigned char a,b;
  for(;n>0;n--)
  {
    for(b=38;b>0;b--)
{
  for(a=130;a>0;a--);
}
}
}

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:267719 发表于 2020-4-29 18:26 | 只看该作者
keyScan 函数里大括号不配对
回复

使用道具 举报

板凳
ID:267719 发表于 2020-4-29 18:30 | 只看该作者
void keyScan(void)
{
    if(pause_key==0)
    {
        Delay10ms(1);
        if(pause_key==0)
        {
            isPause=~isPause;
            pauseLed=isPause ;
            if(isPause==true)
            {
                ET0=0;
                P0=0xfd;
                P1=0x00;
                P2=0x00;
            }
            else
            {
                ET0=1;
                P0=disCode[types];
                displayLed();
            }
            while(pause_key==0);
        }
    }
    if(auto_key==0)
    {
        isAuto=~isAuto;
        autoLed=isAuto;
    }
    while(auto_key==0);
}
if(change_key==0&&isAuto==false)
{
    Delay10ms(1);
    if(change_key==0)
    {
        isChange=true;
    }
    while (change_key==0);
}

大括号配对了就这样。
要养成良好的代码编写习惯。
回复

使用道具 举报

地板
ID:592807 发表于 2020-4-30 09:31 | 只看该作者
括号没配对

3.png (20.1 KB, 下载次数: 68)

3.png
回复

使用道具 举报

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

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

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