标题:
Keil编译出现一大堆错误不知道怎么改啊?
[打印本页]
作者:
不知名大学学生
时间:
2021-6-21 23:18
标题:
Keil编译出现一大堆错误不知道怎么改啊?
1.C(174): error C231: 'P3': redefinition
1.C(174): error C231: 'P3': redefinition
1.C(175): error C247: non-address/-constant initializer
1.C(176): error C279: 'temp': multiple initialization
1.C(176): error C247: non-address/-constant initializer
1.C(177): error C141: syntax error near 'if'
1.C(177): error C141: syntax error near '!=', expected ')'
1.C(179): error C141: syntax error near '10'
1.C(179): error C231: '_delay': redefinition
1.C(180): error C279: 'temp': multiple initialization
1.C(180): error C247: non-address/-constant initializer
1.C(181): error C279: 'temp': multiple initialization
1.C(181): error C247: non-address/-constant initializer
1.C(182): error C141: syntax error near 'if'
1.C(182): error C141: syntax error near '!', expected ')'
1.C(183): error C279: 'temp': multiple initialization
1.C(183): error C247: non-address/-constant initializer
1.C(184): error C141: syntax error near 'switch'
1.C(185): error C141: syntax error near '{'
1.C(188): error C141: syntax error near 'break'
1.C(190): error C279: 'key': multiple initialization
1.C(191): error C141: syntax error near 'break'
1.C(193): error C279: 'key': multiple initialization
1.C(194): error C141: syntax error near 'break'
1.C(196): error C279: 'key': multiple initialization
1.C(197): error C141: syntax error near 'break'
1.C(199): error C141: syntax error near '!=', expected ')'
1.C(201): error C279: 'temp': multiple initialization
1.C(201): error C247: non-address/-constant initializer
1.C(202): error C279: 'temp': multiple initialization
1.C(202): error C247: non-address/-constant initializer
1.C(203): error C141: syntax error near '}'
1.C(204): error C141: syntax error near '==', expected ')'
1.C(204): error C129: missing ';' before '=='
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[]={ 0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,
0xc9,0xff,0x40};
void delay(uint x) ;
void display(uchar,uchar,uchar,uchar) ;
void mkeys();
void traffic();
uchar num,num1,num2,
shi1,ge1,shi2,ge2,
value1,value2,
value3,value4,
count1,count2,flag1,flag2;
void main ()
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
value1=15;
value2=5;
value3=10;
value4=5;
num1=value1;
num2=value2+value1;
shi1=num1/10;
ge1=num1%10;
shi2= num2/10;
ge2= num2%10;
P1=0x41;
while (1){
if(num==20)
{
num=0;
num1--;
num2--;
traffic();
shi1=num1/10;
ge1=num1%10;
shi2=num2/10;
ge2=num2%10;
}
mkeys();
display(shi1,ge1,shi2,ge2);
}
}
void traffic()
{
if(num1==0){
count1++;
if(count1==1){
P1=0x42;
num1=value2;
}
if(count1==2){
num1=value3+value4;
P1=0x14;
}
if(count1==3){
P1=0x41;
num1=value4;
count1=0;
}
}
if(num2==0){
count2++;
if(count2==1){
P1=0x14;
num2=value3;
}
if(count2==2){
P1=0x24;
num2=value4;
}
if(count2==3){
num2=value1+value2;
num1=value1;
count2=0;
}
}
}
void display(uchar shi1,uchar ge1,uchar shi2,uchar ge2)
{
uchar temp;
temp=P2;
P2=0xfe;
P0=table[shi1];
delay(5);
P2=0xfd;
P0=table[ge1];
delay(5);
P2=0xfb;
P0=table[shi2];
delay(5);
P2=0xf7;
P0=table[ge2];
delay(5);
}
void delay(uint x)
{
uint i,j;
for(i=x;i>0;i--);
for(j=125;j>0;j--) ;
}
void mkeys ()
{
uchar temp,key;
P3=0xfe;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10) ;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0) {
temp=P3;
switch(temp)
{
case 0xee:
key=0;
P2=P2&0xbf;
break;
case 0xde:
key=1;
break;
case 0xbe:
key=2;
break;
case 0x7e:
key=3;
break;
}
while (temp!= 0xf0)
temp=P3;
temp= temp&0xf0;
}
if (key==0){
TR0=~TR0;
flag1=~ flag1;
flag2=~ flag2;
}
if (key==1&&flag1==0){
TR0=0;
P1=0x44;
shi1=ge1=shi2=ge2=16;
}
if (key==2&&flag2==0){
TR0=1;
num=0;
P1=0x41;
num1=value1;
num2=value2+ value1;
shi1=num1/10;
ge1=num1%10;
shi2=num2/10;
ge2=num2%10;
}
if(key==3&P1==0x44){
P1=0xff;
delay (1000);
P1=~ P1;
shi1=ge1=shi2=ge2=17;
P1=0x44;
}
}
}
P3=0xfd;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0);
{
delay (10);
temp=P3;
temp=temp&0xf0;
if(temp! =0xf0){
temp=P3;
switch (temp);
{
case 0xed:
key=0;
break;
case 0xdd:
key=1;
break;
case 0xbd:
key=2;
break;
case 0x7d:
key=3;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
if(key==0&&P1==0x44)
{num1=value1;
if(num2! =159)
{num1++;
value1=num1;
}
shi1=num1/10;
ge1=num1% 10;
num2=value1+ value2;
shi2=num2/10;
ge2=num2% 10;
}
if(key==1&&P1==0x44)
{ num1=value2;
if(num2! =159) {
num1++;
value2=num1;
}
shi1=num1/10;
ge1=num1% 10;
num2=value1+value2;
shi2=num2/10;
ge2=num2% 10;
}
if(key==2&&P1==0x44&&value1> 3)
{
num1=value1;
num1-- ;
value1=num1;
shi1=num1/10;
ge1=num1% 10;
num2=value1+ value2;
shi2=num2/10;
ge2=num2% 10;
}
if(key==3&&P1==0x44&&value2> 3)
{
num1=value2;
num1-- ;
value2=num1;
shi1=num1/10;
ge1=num1% 10;
num2=value1+ value2;
shi2=num2/10;
ge2=num2% 10;
}
}
}
P3=0xfb;
temp=P3;
temp=temp&0xf0;
if(temp! =0xf0)
{
delay(10);
temp=P3;
temp=temp&0xf0;
if(temp! =0xf0){
temp=P3;
switch(temp)
{
case 0xeb:
key=0;
break;
case 0xdb:
key=1;
break;
case 0xbb:
key=2;
break;
case 0x7b:
key=3;
break;
}
while(temp! =0xf0)
{
temp=P3;
temp= temp&0xf0;
}
if(key==0&&P1==0x44){
num2=value3;
if(num1! =159){
num2++;
value3=num2;
}
shi2=num2/10;
ge2=num2% 10;
num1=value3+ value4;
shi1=num1/10;
ge1=num1% 10;
}
if(key==1&&P1==0x44){
num2=value4;
if(num1! =159){
num2++;
value4=num2;
}
shi2=num2/10;
ge2=num2% 10;
num1=value3+ value4;
shi1=num1/10;
ge1=num1% 10
}
if(key==2&&P1==0x44&value3> 3)}
num2=value3;
num2--;
value3=num2;
shi2=num2/10;
ge2=num2% 10;
num1=value3+ value4;
shi1=num1/10;
ge1=num1% 10
}
if(key==3&&P1==0x44&&value4> 3){
num2=value4;
num2--;
value4=num2 ;
shi2=num2/ 10;
ge2=num2% 10;
num1=value3+ value4;
shi1=num1/10;
ge1=num1% 10
}
}
}
P3=0xf7;
temp=P3;
temp=temp&0xf0;
if (temp! =0xf0)
{
delay(10) ;
temp=P3;
temp=temp&0xf0;
if (temp! =0xf0) {
temp= P3;
switch (temp)
{
case 0xe7 :
key= 0;
P2= P2&0xdf;
break;
case 0xd7 :
key=1;
P2= P2&0xef;
break;
case 0xb7 :
key=2;
break;
case 0x77 :
key= 3;
break;
}
while (temp! =0xf0)
{
temp=P3;
temp= temp&0xf0;
}
if (key==0&&P1==0x44){
P1=0x41;
shi1=ge1=shi2=ge2=18;
}
if (key==1&&P1==0x44){
P1=0x14;
shi1=ge1=shi2=ge2=18;
}
if (key==2&&P1==0x44){
}
if (key==3&&P1==0x44) {
}
}
}
}
void TO_time() interrupt 1
{
TH0= (65536-50000) /256;
TLO= (65536- 50000)%256;
num++ ;
}
作者:
不知名大学学生
时间:
2021-6-21 23:19
基础不是很好,不会改
作者:
不知名大学学生
时间:
2021-6-21 23:31
在网上看到说改文件后缀名可以解决,改了之后直接打不开
作者:
ly1972001
时间:
2021-6-22 08:03
不知道怎么改,就用排除法。一小段一小段的加上去试。总能找到错。
作者:
cheney03
时间:
2021-6-22 08:39
找提示的第一个错误,后面的是累记的,一般第一个错误改正后就没错误了,P3重定义
作者:
不知名大学学生
时间:
2021-6-22 08:44
cheney03 发表于 2021-6-22 08:39
找提示的第一个错误,后面的是累记的,一般第一个错误改正后就没错误了,P3重定义
这个问题怎么修改呢?
作者:
angmall
时间:
2021-6-22 08:54
给你改了,对比一下就知道哪里错了。
#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[]={ 0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,
0xc9,0xff,0x40};
void delay(uint x) ;
void display(uchar,uchar,uchar,uchar) ;
void mkeys();
void traffic();
uchar num,num1,num2,
shi1,ge1,shi2,ge2,
value1,value2,
value3,value4,
count1,count2,flag1,flag2;
void main()
{
TMOD|=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
value1=15;
value2=5;
value3=10;
value4=5;
num1=value1;
num2=value2+value1;
shi1=num1/10;
ge1=num1%10;
shi2= num2/10;
ge2= num2%10;
P1=0x41;
while (1){
if(num==20)
{
num=0;
num1--;
num2--;
traffic();
shi1=num1/10;
ge1=num1%10;
shi2=num2/10;
ge2=num2%10;
}
mkeys();
display(shi1,ge1,shi2,ge2);
}
}
void traffic()
{
if(num1==0){
count1++;
if(count1==1){
P1=0x42;
num1=value2;
}
if(count1==2){
num1=value3+value4;
P1=0x14;
}
if(count1==3){
P1=0x41;
num1=value4;
count1=0;
}
}
if(num2==0){
count2++;
if(count2==1){
P1=0x14;
num2=value3;
}
if(count2==2){
P1=0x24;
num2=value4;
}
if(count2==3){
num2=value1+value2;
num1=value1;
count2=0;
}
}
}
void display(uchar shi1,uchar ge1,uchar shi2,uchar ge2)
{
uchar temp;
temp=P2;
P2=0xfe;
P0=table[shi1];
delay(5);
P2=0xfd;
P0=table[ge1];
delay(5);
P2=0xfb;
P0=table[shi2];
delay(5);
P2=0xf7;
P0=table[ge2];
delay(5);
}
void delay(uint x)
{
uint i,j;
for(i=x;i>0;i--) //;
for(j=125;j>0;j--) ;
}
void mkeys()
{
uchar temp,key;
P3=0xfe;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10) ;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0) {
temp=P3;
switch(temp)
{
case 0xee:
key=0;
P2=P2&0xbf;
break;
case 0xde:
key=1;
break;
case 0xbe:
key=2;
break;
case 0x7e:
key=3;
break;
}
while (temp!= 0xf0)
temp=P3;
temp= temp&0xf0;
}
if (key==0){
TR0=~TR0;
flag1=~ flag1;
flag2=~ flag2;
}
if (key==1&&flag1==0){
TR0=0;
P1=0x44;
shi1=ge1=shi2=ge2=16;
}
if (key==2&&flag2==0){
TR0=1;
num=0;
P1=0x41;
num1=value1;
num2=value2+ value1;
shi1=num1/10;
ge1=num1%10;
shi2=num2/10;
ge2=num2%10;
}
if(key==3&P1==0x44){
P1=0xff;
delay (1000);
P1=~ P1;
shi1=ge1=shi2=ge2=17;
P1=0x44;
}
}
//}
P3=0xfd;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0);
{
delay (10);
temp=P3;
temp=temp&0xf0;
if(temp! =0xf0){
temp=P3;
switch (temp);
{
case 0xed:
key=0;
break;
case 0xdd:
key=1;
break;
case 0xbd:
key=2;
break;
case 0x7d:
key=3;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
if(key==0&&P1==0x44)
{ num1=value1;
if(num2! =159)
{num1++;
value1=num1;
}
shi1=num1/10;
ge1=num1% 10;
num2=value1+ value2;
shi2=num2/10;
ge2=num2% 10;
}
if(key==1&&P1==0x44)
{ num1=value2;
if(num2! =159) {
num1++;
value2=num1;
}
shi1=num1/10;
ge1=num1% 10;
num2=value1+value2;
shi2=num2/10;
ge2=num2% 10;
}
if(key==2&&P1==0x44&&value1> 3)
{
num1=value1;
num1-- ;
value1=num1;
shi1=num1/10;
ge1=num1% 10;
num2=value1+ value2;
shi2=num2/10;
ge2=num2% 10;
}
if(key==3&&P1==0x44&&value2> 3)
{
num1=value2;
num1-- ;
value2=num1;
shi1=num1/10;
ge1=num1% 10;
num2=value1+ value2;
shi2=num2/10;
ge2=num2% 10;
}
}
}
P3=0xfb;
temp=P3;
temp=temp&0xf0;
if(temp! =0xf0)
{
delay(10);
temp=P3;
temp=temp&0xf0;
if(temp! =0xf0){
temp=P3;
switch(temp)
{
case 0xeb:
key=0;
break;
case 0xdb:
key=1;
break;
case 0xbb:
key=2;
break;
case 0x7b:
key=3;
break;
}
while(temp! =0xf0)
{
temp=P3;
temp= temp&0xf0;
}
if(key==0&&P1==0x44){
num2=value3;
if(num1! =159){
num2++;
value3=num2;
}
shi2=num2/10;
ge2=num2% 10;
num1=value3+ value4;
shi1=num1/10;
ge1=num1% 10;
}
if(key==1&&P1==0x44){
num2=value4;
if(num1! =159){
num2++;
value4=num2;
}
shi2=num2/10;
ge2=num2% 10;
num1=value3+ value4;
shi1=num1/10;
ge1=num1% 10
}
if(key==2&&P1==0x44&value3> 3){
num2=value3;
num2--;
value3=num2;
shi2=num2/10;
ge2=num2% 10;
num1=value3+ value4;
shi1=num1/10;
ge1=num1% 10
}
if(key==3&&P1==0x44&&value4> 3){ //}
num2=value4;
num2--;
value4=num2 ;
shi2=num2/ 10;
ge2=num2% 10;
num1=value3+ value4;
shi1=num1/10;
ge1=num1% 10
}
}
}
P3=0xf7;
temp=P3;
temp=temp&0xf0;
if (temp! =0xf0)
{
delay(10) ;
temp=P3;
temp=temp&0xf0;
if (temp! =0xf0) {
temp= P3;
switch (temp)
{
case 0xe7 :
key= 0;
P2= P2&0xdf;
break;
case 0xd7 :
key=1;
P2= P2&0xef;
break;
case 0xb7 :
key=2;
break;
case 0x77 :
key= 3;
break;
}
while (temp! =0xf0)
{
temp=P3;
temp= temp&0xf0;
}
if (key==0&&P1==0x44){
P1=0x41;
shi1=ge1=shi2=ge2=18;
}
if (key==1&&P1==0x44){
P1=0x14;
shi1=ge1=shi2=ge2=18;
}
if (key==2&&P1==0x44){
P1=0x14;
shi1=ge1=shi2=ge2=18;
}
if (key==3&&P1==0x44) {
P1=0x14;
shi1=ge1=shi2=ge2=18;
}
}
}
}
void TO_time() interrupt 1
{
TH0= (65536-50000)/256;
TLO= (65536-50000)%256;
num++ ;
}
复制代码
作者:
冰点36
时间:
2021-6-22 08:54
根据错误,一句一句搜错误原因,改错
作者:
sustlixin
时间:
2021-6-22 09:24
错误的地方太多了(如,少;号,后面有的代码都没有函数名),而且代码又杂又乱,光靠人眼识别,太难了,写代码,首先要理清思路的
作者:
不知名大学学生
时间:
2021-6-22 09:27
已经解决了,谢谢各位
作者:
yzwzfyz
时间:
2021-6-22 13:48
每一句都有提示,按照提示处理就可以了。
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1