syntax吧 关注:6贴子:10
  • 0回复贴,共1
有气球的两行出错
main.c(124): error C141: syntax error near 'void'
main.c(125): error C141: syntax error near '{'
这是问题
#include <REGX51.H>
#define uchar unsigned char
void Run();
void KeyScan();
void PlayKey();
void delay_lms(uchar i);
void PlayMusic();
void DisPlay();
sbit Beep=P3^7;
uchar Th0,T10;
uchar flag=0xff; //模式,0表示音乐,ff表示按键
uchar key=0; //按键代号
uchar a;uchar gaodi=0; //音乐符号
uchar code MusicCode[]={0xfc,0x44,0xfc,0xac,0xfd,0x09,0xfd,0x34,
0xfd,0x82,0xfd,0xc8,0xfd,0x06,0xfb,0x04,
0xfb,0x90,0xfc,0x0c,0xfe,0x22,0xf9,0x5b,0xfa,0x15};
//月亮代表我的心
uchar code Music[]={
0x02,0x82,
0x16,0x32,0x54,0x02,0x52,
0xa6,0x32,0x54,0x02,0x52,
0x64,0x74,0xb6,0x64,
0x52,0x5c,0x32,0x22,
0x16,0x12,0x12,0x32,0x22,
0x16,0x12,0x14,0x22,0x32,
0x26,0x12,0x94,0x22,0x32,
0x2c,
0x32,0x52,
0x36,0x22,0x14,0x52,
0xac,0x0a2,0x96,0x82,
0x3c,0x54,
0x36,0x22,0x14,0x54,
0xac,0x92,0xa2,
0x16,0x12,0x14,0x22,0x32,
0x2c,0x02,0x82,
0x16,0x32,0x56,0x12,
0xa6,0x32,0x56,0x52,
0x66,0x72,0xb6,0x62,
0x62,0x52,0x52,0x32,0x22,
0x16,0x12,0x14,0x32,0x22,
0x16,0x12,0x14,0x22,0x32,
0x1c,
0xff}; //按键音符
uchar code KeyCode[]={0xff,0xff,
0xf8,0x8b,0xf9,0x5b,0xfa,0x14,0xfa,0x66,0xfb,0x03,0xfb,0x8f,0xfc,0x0b,//低音
0xfc,0x43,0xfc,0xab,0xfd,0x08,0xfd,0x33,0xfd,0x81,0xfd,0xc7,0xfe,0x05,//中音
0xfe,0x21,0xfe,0x55,0xfe,0x84,0xfe,0x99,0xfe,0xc0,0xfe,0xe3,0xff,0x02,//高音
};
void main()
{ P1=0xff; //初始化
P0=0xff;
P2=0;
TMOD=0x01;
IT0=1;
TR0=0;
EX0=1;
ET0=1;
EA=1;
while(1)
{ KeyScan();
Run();
DisPlay();
}
}
void Run()
{ if(flag==0)
PlayMusic();
else
PlayKey();
}
void KeyScan() //按键扫描
{ if(P1==0xfe)
{ delay_lms(12);
if(P1==0xfe)
{key=1;a=key;}
}
else if(P1==0xfd)
{ delay_lms(12);
if(P1==0xfd)
{ key=2;a=key;}
else if(P1==0xfb)
{ delay_lms(12);
if(P1==0xfb)
{ key=3;a=key;}
}
else if(P1==0xf7)
{ delay_lms(12);
if(P1==0xf7)
{ key=4;a=key;}
}
else if(P1==0xef)
{ delay_lms(12);
if(P1==0xef)
{ key=5;a=key;}
}
else if(P1==0xdf)
{ delay_lms(12);
if(P1==0xdf)
{ key=6;a=key;}
}
else if(P1==0xbf)
{ delay_lms(12);
if(P1==0xbf)
{ key=7;a=key;}
}
else if(P0==0xfe) //按下低音模式键
{ delay_lms(12);
if(P0==0xfe)
{ gaodi=0;a=gaodi;}
}
else if(P0==0xfd) //按下中音模式键
{ delay_lms(12);
if(P0==0xfd)
{ gaodi=1;a=gaodi;}
}
else if(P0==0xfb)//按下高音模式键
{ delay_lms(12);
if(P0==0xfb)
{ gaodi=2;a=gaodi;}
}
else return;
}
🎈void PlayKey() //响应按键
🎈{
if(key==0)
return;
else
{ Th0=KeyCode[gaodi*14+key*2];
TL0=KeyCode[gaodi*14+key*2+1];
TR0=1; delay_lms(187);
TR0=0; key=0;
}
}
time0() interrupt 1
{ TH0=Th0;
TL0=Tl0;
Beep=~Beep;
}
void interrupt0() interrupt 0
{ flag=~flag;
if(flag==0)
{ a=8;
P2=0;
}
}
void delay_lms(uchar i) //延时
{ uchar j,k;
for(j=0;j<i;j++);
for(k=0;k<148;k++);
}
void PlayMusic() //播放音乐
{ uchar yinfu,jiepai;
uchar j,k;
for(i=0;Music[i]!=0xff;i++)
{ yinfu=(Music[i]>>4);
jiepai=(Music[i]&0x0f);
if(yinfu==0)
continue;
Th0=MusicCode[(yinfu-1)*2];
Tl0=MusicCode[(yinfu-1)*2+1];
TR0=1;
for(j=jiepai;J>0;--j)
{ delay_lms(250);}
TR0=0;
if(flag!=0)
break;
}
}
void DisPlay() //显示
{ swith(a)
{ case 0;P2=0x3f;break;
case 1:P2=0x06;break;
case 2;P2=0x5b;break;
case 3;P2=0x4f;break;
case 4;P2=0x66;break;
case 5;P2=0x6d;break;
case 6;P2=0x7d;break;
case 7;P2=0x07;break;
default:P2=0x00;break;
}
}


1楼2021-12-26 22:40回复