#include<reg51.h>
#define LEDData P0
unsigned char code
LEDCode[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char minit,second,count,count1; //·Ö£¬Ã룬¼ÆÊýÆ÷
sbit add1=P1^0; //¼×¶Ó¼Ó·Ö
sbit dec1=P1^1; //¼×¶Ó¼õ·Ö
sbit exchange=P1^2; //»»³¡
sbit add2=P1^3; //ÒÒ¶Ó¼Ó·Ö
sbit dec2=P1^4; //ÒÒ¶Ó¼õ·Ö
sbit secondpoint=P0^7; //ÃëµãÉÁ¶¯
sbit led1=P2^7;
sbit led2=P2^6;
sbit led3=P2^5;
sbit led4=P2^4;
sbit led5=P2^3;
sbit led6=P2^2;
sbit led7=P2^1;
sbit led8=P2^0;
sbit led9=P3^7;
sbit led10=P3^6;
sbit led11=P3^5;
sbit alam=P1^7; //±¨¾¯
bit playon=0; //±ÈÈü½øÐбê־룬1±íʾ¿ªÊ¼
bit timeover=0; //±ÈÈü½áÊø±ê־룬1±íʾ½áÊø
bit AorB=0; //¼×¡¢ÒÒ¶Ó½»»»Î»Öñê־λ
bit halfsecond=0; //°ëÃë±ê־λ
unsigned int scoreA; //¼×¶ÓµÃ·Ö
unsigned int scoreB; //ÒҶӵ÷Ö
void Delay5ms(void)
{
unsigned int i;
for(i=100;i>0;i--);
}
void display(void)
{
LEDData=LEDCode[minit/10];
led1=0;
Delay5ms();
led1=1;
LEDData=LEDCode[minit%10];
led2=0;
Delay5ms();
led2=1; //ÏÔʾʱ¼ä·Ö
if(halfsecond==1)
LEDData=0x80;
else
LEDData=0x00;
led2=0;
Delay5ms();
led2=1;
secondpoint=0; //ÃëµãÉÁ¶¯
LEDData=LEDCode[second/10];
led3=0;
Delay5ms();
led3=1;
LEDData=LEDCode[second%10];
led4=0;
Delay5ms();
led4=1; //ÏÔʾʱ¼äÃë
if(AorB==0)
LEDData=LEDCode[scoreA/100];
else
LEDData=LEDCode[scoreB/100];
led5=0;
Delay5ms();
led5=1; //ÏÔʾ1×éµÄ·ÖÊý°Ùλ
if(AorB==0)
LEDData=LEDCode[(scoreA%100)/10];
else
LEDData=LEDCode[(scoreB%100)/10];
led6=0;
Delay5ms();
led6=1; //ÏÔʾ1×éµÄ·ÖÊýʮλ
if(AorB==0)
LEDData=LEDCode[scoreA%10];
else
LEDData=LEDCode[scoreB%10];
led7=0;
Delay5ms();
led7=1; //ÏÔʾ1×éµÄ·ÖÊý¸öλ
if(AorB==1)
LEDData=LEDCode[scoreA/100];
else
LEDData=LEDCode[scoreB/100];
led8=0;
Delay5ms();
led8=1; //ÏÔʾ2×éµÄ·ÖÊý°Ùλ
if(AorB==1)
LEDData=LEDCode[(scoreA%100)/10];
else
LEDData=LEDCode[(scoreB%100)/10];
led9=0;
Delay5ms();
led9=1; //ÏÔʾ2×éµÄ·ÖÊýʮλ
if(AorB==1)
LEDData=LEDCode[scoreA%10];
else
LEDData=LEDCode[scoreB%10];
led10=0;
Delay5ms();
led10=1; //ÏÔʾ2×éµÄ·ÖÊý¸öλ
}
//==============°´¼ü¼ì²â³ÌÐ=====================ò
void keyscan(void)
{
if(playon==0)
{
if(add1==0)
{
display();
if(add1==0);
{
if(minit<99)
minit++;
else
minit=99;
}
do
display();
while(add1==0);
}
if(dec1==0)
{
display();
if(dec1==0);
{
if(minit>0)
minit--;
else
minit=0;
}
do
display();
while(dec1==0);
}
if(add2==0)
{
display();
if(add2==0);
{
if(second<59)
second++;
else
second=59;
}
do
display();
while(add2==0);
}
if(dec2==0)
{
display();
if(dec2==0);
{
if(second>0)
second--;
else
second=0;
}
do
display();
while(dec2==0);
}
if(exchange==0)
{
display();
if(exchange==0);
{
TR1=0; //¹Ø±ÕT1¼ÆÊýÆ÷
alam=1; //¹Ø±Õ±¨¾¯
AorB=~AorB; //¿ªÆô½»»»
minit=15; //ʱ¼äÔ¤ÉèΪ15·Ö
second=0;
}
do
display();
while(exchange==0);
}
}
else
{
if(add1==0)
{
display();
if(add1==0);
{
if(AorB==0)
{
if(scoreA<999)
scoreA++;
else
scoreA=999;
}
else
{
if(scoreB<999)
scoreB++;
else
scoreB=999;
}
}
do
display();
while(add1==0);
}
if(dec1==0)
{
display();
if(dec1==0);
{
if(AorB==0)
{
if(scoreA>0)
scoreA--;
else
scoreA=0;
}
else
{
if(scoreB>0)
scoreB--;
else
scoreB=0;
}
}
do
display();
while(dec1==0);
}
if(add2==0)
{
display();
if(add2==0);
{
if(AorB==1)
{
if(scoreA<999);
scoreA++;
else
scoreA=999;
}
else
{
if(scoreB<999);
scoreB++;
else
scoreB=999;
}
}
do
display();
while(add2==0);
}
if(dec2==0)
{
display();
if(dec2==0)£»
{
if(AorB==1)
{
if(scoreA>0)
scoreA--;
else
scoreA=0;
}
else
{
if(scoreB>0);
scoreB--;
else
scoreB=0;
}
}
do
display();
while(dec2==0);
}
}
}
//=========Ö÷º¯Êý===========
void main(void)
{
TMOD=0x11;
TL0=0Xb0;
TH0=0X3c;
TL1=0Xb0;
TH1=0X3c;
minit=15;
second=0;
EA=1;
ET0=1;
ET1=1;
TR0=0;
TR1=0;
EX0=1;
IT0=1;
IT1=1;
//EX1=1;
PX0=1;
//PX1=1;
PT0=0;
P1=0Xff;
P3=0Xff;
while(1)
{
keyscan();
display();
}
}
void PxInt0(void) interrupt0
{
Delay5ms();
EX0=0;
alam=1;
TR1=0;
if(timeover==1)
{
timeover=0;
}
if(playon==0)
{
playon=1; //¿ªÊ¼±ê־λ
TR0=1; //¿ªÆô¼Æʱ
}
else
{
playon=0; //¿ªÊ¼±ê־λÇåÁã
TR0=0; //ÔÝÍ£¼Æʱ
}
EX0=1; //¿ªÖжÏ
}
void PxInt1(void) interrupt2
{
Delay5ms();
EX1=0; //¹ØÖжÏ
if(timeover==1) //±ÈÈü½áÊø±êÖ¾
{
TR1=0; //¹Ø±ÕT1¼ÆÊýÆ÷
alam=1; //¹Ø±¨¾¯
AorB=~AorB; //¿ªÆô½»»»
minit=15; //Ô¤Éèʱ¼äΪ15min
second=0;
}
EX1=1; //¿ªÖжÏ
}
//======ÖжÏÎå·þÎñº¯Êý============
void time0_int(void) interrupt1
{
TL0=0Xb0;
TH0=0X3c;
TR0=1;
count++;
if(count==10)
{
halfsecond=0;
}
if(count==20)
{
count=0;
halfsecond=1;
if(second==0)
{
if(minit>0);
{
second=59;
minit--;
}
else
{
timeover=1;
playon=0;
TR0=0;
TR1=1;
}
}
else
second--;
}
}
void time1_int(void) interrupt3
{
TL1=0Xb0;
TH1=0X3c;
TR1=1;
count1++;
if(count1==10)
{
alam=0;
}
if(count1==20)
{
count1=0;
alam=1;
}
}
程序要求是设计一个篮球计时计分器,6个LED显示两个队伍的分数,4个LED显示时间的倒计时,有独立按键控制加减分,计时调整和开始暂停,结束发生警报。
求大家都来看看我的error怎么解决。本来就几个error。改对了反而变成了好几十个。感觉无力- -
篮球.c(348): error C132: 'EX1': not in formal parameter list
篮球.c(349): error C141: syntax error near 'if'
篮球.c(349): error C141: syntax error near '==', expected ')'
篮球.c(351): error C231: 'TR1': redefinition
篮球.c(351): error C231: 'TR1': redefinition
篮球.c(352): error C231: 'alam': redefinition
篮球.c(352): error C231: 'alam': redefinition
篮球.c(353): error C279: 'AorB': multiple initialization
篮球.c(353): error C231: 'AorB': redefinition
篮球.c(353): error C247: non-address/-constant initializer
篮球.c(354): error C231: 'minit': redefinition
篮球.c(355): error C231: 'second': redefinition
篮球.c(356): error C141: syntax error near '}'
篮球.c(357): error C231: 'EX1': redefinition
篮球.c(357): error C231: 'EX1': redefinition
篮球.c(358): error C141: syntax error near '}'
篮球.c(361): error C132: 'interrupt1': not in formal parameter list
篮球.c(361): error C141: syntax error near '{'
篮球.c(362): error C244: 'TL0': can't initialize, bad type or class
篮球.c(362): error C132: 'TL0': not in formal parameter list
篮球.c(363): error C244: 'TH0': can't initialize, bad type or class
篮球.c(363): error C132: 'TH0': not in formal parameter list
篮球.c(364): error C279: 'TR0': multiple initialization
篮球.c(364): error C244: 'TR0': can't initialize, bad type or class
篮球.c(364): error C132: 'TR0': not in formal parameter list
篮球.c(365): error C132: 'count': not in formal parameter list
篮球.c(365): error C141: syntax error near '++'
篮球.c(368): error C279: 'halfsecond': multiple initialization
篮球.c(368): error C244: 'halfsecond': can't initialize, bad type or class
篮球.c(368): error C132: 'halfsecond': not in formal parameter list
篮球.c(369): error C141: syntax error near '}'
篮球.c(370): error C141: syntax error near '==', expected ')'
篮球.c(372): error C231: 'count': redefinition
篮球.c(373): error C279: 'halfsecond': multiple initialization
篮球.c(373): error C231: 'halfsecond': redefinition
篮球.c(374): error C141: syntax error near 'if'
篮球.c(374): error C141: syntax error near '==', expected ')'
篮球.c(376): error C141: syntax error near '>', expected ')'
篮球.c(378): error C279: 'second': multiple initialization
篮球.c(379): error C129: missing ';' before '--'
篮球.c - 77 Error(s), 0 Warning(s).
#define LEDData P0
unsigned char code
LEDCode[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char minit,second,count,count1; //·Ö£¬Ã룬¼ÆÊýÆ÷
sbit add1=P1^0; //¼×¶Ó¼Ó·Ö
sbit dec1=P1^1; //¼×¶Ó¼õ·Ö
sbit exchange=P1^2; //»»³¡
sbit add2=P1^3; //ÒÒ¶Ó¼Ó·Ö
sbit dec2=P1^4; //ÒÒ¶Ó¼õ·Ö
sbit secondpoint=P0^7; //ÃëµãÉÁ¶¯
sbit led1=P2^7;
sbit led2=P2^6;
sbit led3=P2^5;
sbit led4=P2^4;
sbit led5=P2^3;
sbit led6=P2^2;
sbit led7=P2^1;
sbit led8=P2^0;
sbit led9=P3^7;
sbit led10=P3^6;
sbit led11=P3^5;
sbit alam=P1^7; //±¨¾¯
bit playon=0; //±ÈÈü½øÐбê־룬1±íʾ¿ªÊ¼
bit timeover=0; //±ÈÈü½áÊø±ê־룬1±íʾ½áÊø
bit AorB=0; //¼×¡¢ÒÒ¶Ó½»»»Î»Öñê־λ
bit halfsecond=0; //°ëÃë±ê־λ
unsigned int scoreA; //¼×¶ÓµÃ·Ö
unsigned int scoreB; //ÒҶӵ÷Ö
void Delay5ms(void)
{
unsigned int i;
for(i=100;i>0;i--);
}
void display(void)
{
LEDData=LEDCode[minit/10];
led1=0;
Delay5ms();
led1=1;
LEDData=LEDCode[minit%10];
led2=0;
Delay5ms();
led2=1; //ÏÔʾʱ¼ä·Ö
if(halfsecond==1)
LEDData=0x80;
else
LEDData=0x00;
led2=0;
Delay5ms();
led2=1;
secondpoint=0; //ÃëµãÉÁ¶¯
LEDData=LEDCode[second/10];
led3=0;
Delay5ms();
led3=1;
LEDData=LEDCode[second%10];
led4=0;
Delay5ms();
led4=1; //ÏÔʾʱ¼äÃë
if(AorB==0)
LEDData=LEDCode[scoreA/100];
else
LEDData=LEDCode[scoreB/100];
led5=0;
Delay5ms();
led5=1; //ÏÔʾ1×éµÄ·ÖÊý°Ùλ
if(AorB==0)
LEDData=LEDCode[(scoreA%100)/10];
else
LEDData=LEDCode[(scoreB%100)/10];
led6=0;
Delay5ms();
led6=1; //ÏÔʾ1×éµÄ·ÖÊýʮλ
if(AorB==0)
LEDData=LEDCode[scoreA%10];
else
LEDData=LEDCode[scoreB%10];
led7=0;
Delay5ms();
led7=1; //ÏÔʾ1×éµÄ·ÖÊý¸öλ
if(AorB==1)
LEDData=LEDCode[scoreA/100];
else
LEDData=LEDCode[scoreB/100];
led8=0;
Delay5ms();
led8=1; //ÏÔʾ2×éµÄ·ÖÊý°Ùλ
if(AorB==1)
LEDData=LEDCode[(scoreA%100)/10];
else
LEDData=LEDCode[(scoreB%100)/10];
led9=0;
Delay5ms();
led9=1; //ÏÔʾ2×éµÄ·ÖÊýʮλ
if(AorB==1)
LEDData=LEDCode[scoreA%10];
else
LEDData=LEDCode[scoreB%10];
led10=0;
Delay5ms();
led10=1; //ÏÔʾ2×éµÄ·ÖÊý¸öλ
}
//==============°´¼ü¼ì²â³ÌÐ=====================ò
void keyscan(void)
{
if(playon==0)
{
if(add1==0)
{
display();
if(add1==0);
{
if(minit<99)
minit++;
else
minit=99;
}
do
display();
while(add1==0);
}
if(dec1==0)
{
display();
if(dec1==0);
{
if(minit>0)
minit--;
else
minit=0;
}
do
display();
while(dec1==0);
}
if(add2==0)
{
display();
if(add2==0);
{
if(second<59)
second++;
else
second=59;
}
do
display();
while(add2==0);
}
if(dec2==0)
{
display();
if(dec2==0);
{
if(second>0)
second--;
else
second=0;
}
do
display();
while(dec2==0);
}
if(exchange==0)
{
display();
if(exchange==0);
{
TR1=0; //¹Ø±ÕT1¼ÆÊýÆ÷
alam=1; //¹Ø±Õ±¨¾¯
AorB=~AorB; //¿ªÆô½»»»
minit=15; //ʱ¼äÔ¤ÉèΪ15·Ö
second=0;
}
do
display();
while(exchange==0);
}
}
else
{
if(add1==0)
{
display();
if(add1==0);
{
if(AorB==0)
{
if(scoreA<999)
scoreA++;
else
scoreA=999;
}
else
{
if(scoreB<999)
scoreB++;
else
scoreB=999;
}
}
do
display();
while(add1==0);
}
if(dec1==0)
{
display();
if(dec1==0);
{
if(AorB==0)
{
if(scoreA>0)
scoreA--;
else
scoreA=0;
}
else
{
if(scoreB>0)
scoreB--;
else
scoreB=0;
}
}
do
display();
while(dec1==0);
}
if(add2==0)
{
display();
if(add2==0);
{
if(AorB==1)
{
if(scoreA<999);
scoreA++;
else
scoreA=999;
}
else
{
if(scoreB<999);
scoreB++;
else
scoreB=999;
}
}
do
display();
while(add2==0);
}
if(dec2==0)
{
display();
if(dec2==0)£»
{
if(AorB==1)
{
if(scoreA>0)
scoreA--;
else
scoreA=0;
}
else
{
if(scoreB>0);
scoreB--;
else
scoreB=0;
}
}
do
display();
while(dec2==0);
}
}
}
//=========Ö÷º¯Êý===========
void main(void)
{
TMOD=0x11;
TL0=0Xb0;
TH0=0X3c;
TL1=0Xb0;
TH1=0X3c;
minit=15;
second=0;
EA=1;
ET0=1;
ET1=1;
TR0=0;
TR1=0;
EX0=1;
IT0=1;
IT1=1;
//EX1=1;
PX0=1;
//PX1=1;
PT0=0;
P1=0Xff;
P3=0Xff;
while(1)
{
keyscan();
display();
}
}
void PxInt0(void) interrupt0
{
Delay5ms();
EX0=0;
alam=1;
TR1=0;
if(timeover==1)
{
timeover=0;
}
if(playon==0)
{
playon=1; //¿ªÊ¼±ê־λ
TR0=1; //¿ªÆô¼Æʱ
}
else
{
playon=0; //¿ªÊ¼±ê־λÇåÁã
TR0=0; //ÔÝÍ£¼Æʱ
}
EX0=1; //¿ªÖжÏ
}
void PxInt1(void) interrupt2
{
Delay5ms();
EX1=0; //¹ØÖжÏ
if(timeover==1) //±ÈÈü½áÊø±êÖ¾
{
TR1=0; //¹Ø±ÕT1¼ÆÊýÆ÷
alam=1; //¹Ø±¨¾¯
AorB=~AorB; //¿ªÆô½»»»
minit=15; //Ô¤Éèʱ¼äΪ15min
second=0;
}
EX1=1; //¿ªÖжÏ
}
//======ÖжÏÎå·þÎñº¯Êý============
void time0_int(void) interrupt1
{
TL0=0Xb0;
TH0=0X3c;
TR0=1;
count++;
if(count==10)
{
halfsecond=0;
}
if(count==20)
{
count=0;
halfsecond=1;
if(second==0)
{
if(minit>0);
{
second=59;
minit--;
}
else
{
timeover=1;
playon=0;
TR0=0;
TR1=1;
}
}
else
second--;
}
}
void time1_int(void) interrupt3
{
TL1=0Xb0;
TH1=0X3c;
TR1=1;
count1++;
if(count1==10)
{
alam=0;
}
if(count1==20)
{
count1=0;
alam=1;
}
}
程序要求是设计一个篮球计时计分器,6个LED显示两个队伍的分数,4个LED显示时间的倒计时,有独立按键控制加减分,计时调整和开始暂停,结束发生警报。
求大家都来看看我的error怎么解决。本来就几个error。改对了反而变成了好几十个。感觉无力- -
篮球.c(348): error C132: 'EX1': not in formal parameter list
篮球.c(349): error C141: syntax error near 'if'
篮球.c(349): error C141: syntax error near '==', expected ')'
篮球.c(351): error C231: 'TR1': redefinition
篮球.c(351): error C231: 'TR1': redefinition
篮球.c(352): error C231: 'alam': redefinition
篮球.c(352): error C231: 'alam': redefinition
篮球.c(353): error C279: 'AorB': multiple initialization
篮球.c(353): error C231: 'AorB': redefinition
篮球.c(353): error C247: non-address/-constant initializer
篮球.c(354): error C231: 'minit': redefinition
篮球.c(355): error C231: 'second': redefinition
篮球.c(356): error C141: syntax error near '}'
篮球.c(357): error C231: 'EX1': redefinition
篮球.c(357): error C231: 'EX1': redefinition
篮球.c(358): error C141: syntax error near '}'
篮球.c(361): error C132: 'interrupt1': not in formal parameter list
篮球.c(361): error C141: syntax error near '{'
篮球.c(362): error C244: 'TL0': can't initialize, bad type or class
篮球.c(362): error C132: 'TL0': not in formal parameter list
篮球.c(363): error C244: 'TH0': can't initialize, bad type or class
篮球.c(363): error C132: 'TH0': not in formal parameter list
篮球.c(364): error C279: 'TR0': multiple initialization
篮球.c(364): error C244: 'TR0': can't initialize, bad type or class
篮球.c(364): error C132: 'TR0': not in formal parameter list
篮球.c(365): error C132: 'count': not in formal parameter list
篮球.c(365): error C141: syntax error near '++'
篮球.c(368): error C279: 'halfsecond': multiple initialization
篮球.c(368): error C244: 'halfsecond': can't initialize, bad type or class
篮球.c(368): error C132: 'halfsecond': not in formal parameter list
篮球.c(369): error C141: syntax error near '}'
篮球.c(370): error C141: syntax error near '==', expected ')'
篮球.c(372): error C231: 'count': redefinition
篮球.c(373): error C279: 'halfsecond': multiple initialization
篮球.c(373): error C231: 'halfsecond': redefinition
篮球.c(374): error C141: syntax error near 'if'
篮球.c(374): error C141: syntax error near '==', expected ')'
篮球.c(376): error C141: syntax error near '>', expected ')'
篮球.c(378): error C279: 'second': multiple initialization
篮球.c(379): error C129: missing ';' before '--'
篮球.c - 77 Error(s), 0 Warning(s).