找回密码
 立即注册

QQ登录

只需一步,快速开始

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

Keil编译出现一大堆错误不知道怎么改啊?

[复制链接]
跳转到指定楼层
楼主
ID:942007 发表于 2021-6-21 23:18 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
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++ ;
}



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

使用道具 举报

沙发
ID:942007 发表于 2021-6-21 23:19 | 只看该作者
基础不是很好,不会改
回复

使用道具 举报

板凳
ID:942007 发表于 2021-6-21 23:31 | 只看该作者
在网上看到说改文件后缀名可以解决,改了之后直接打不开
回复

使用道具 举报

地板
ID:236035 发表于 2021-6-22 08:03 | 只看该作者
不知道怎么改,就用排除法。一小段一小段的加上去试。总能找到错。
回复

使用道具 举报

5#
ID:743654 发表于 2021-6-22 08:39 | 只看该作者
找提示的第一个错误,后面的是累记的,一般第一个错误改正后就没错误了,P3重定义
回复

使用道具 举报

6#
ID:942007 发表于 2021-6-22 08:44 来自手机 | 只看该作者
cheney03 发表于 2021-6-22 08:39
找提示的第一个错误,后面的是累记的,一般第一个错误改正后就没错误了,P3重定义

这个问题怎么修改呢?
回复

使用道具 举报

7#
ID:155507 发表于 2021-6-22 08:54 | 只看该作者
给你改了,对比一下就知道哪里错了。

  1. #include <reg51.h>
  2. #define uchar unsigned char
  3. #define uint unsigned int
  4. uchar code table[]={  0x3f,0x06,0x5b,0x4f,
  5.         0x66,0x6d,0x7d,0x07,
  6.         0x7f,0x6f,0x77,0x7c,
  7.         0x39,0x5e,0x79,0x71,
  8.         0xc9,0xff,0x40};
  9. void delay(uint x) ;
  10. void display(uchar,uchar,uchar,uchar) ;
  11. void mkeys();
  12. void traffic();
  13. uchar num,num1,num2,
  14. shi1,ge1,shi2,ge2,
  15. value1,value2,
  16. value3,value4,
  17. count1,count2,flag1,flag2;
  18. void main()
  19. {
  20.         TMOD|=0x01;
  21.         TH0=(65536-50000)/256;
  22.         TL0=(65536-50000)%256;
  23.         EA=1;
  24.         ET0=1;
  25.         TR0=1;
  26.         value1=15;
  27.         value2=5;
  28.         value3=10;
  29.         value4=5;
  30.         num1=value1;
  31.         num2=value2+value1;
  32.         shi1=num1/10;
  33.         ge1=num1%10;
  34.         shi2= num2/10;
  35.         ge2= num2%10;
  36.         P1=0x41;
  37.         while (1){
  38.                 if(num==20)
  39.                 {
  40.                         num=0;
  41.                         num1--;
  42.                         num2--;
  43.                         traffic();
  44.                         shi1=num1/10;
  45.                         ge1=num1%10;
  46.                         shi2=num2/10;
  47.                         ge2=num2%10;
  48.                 }
  49.                 mkeys();
  50.                 display(shi1,ge1,shi2,ge2);
  51.         }
  52. }
  53. void traffic()
  54. {
  55.         if(num1==0){
  56.                 count1++;
  57.                 if(count1==1){
  58.                         P1=0x42;
  59.                         num1=value2;
  60.                 }
  61.                 if(count1==2){
  62.                         num1=value3+value4;
  63.                         P1=0x14;
  64.                 }
  65.                 if(count1==3){
  66.                         P1=0x41;
  67.                         num1=value4;
  68.                         count1=0;
  69.                 }
  70.         }
  71.         if(num2==0){
  72.                 count2++;
  73.                 if(count2==1){
  74.                         P1=0x14;
  75.                         num2=value3;
  76.                 }
  77.                 if(count2==2){
  78.                         P1=0x24;
  79.                         num2=value4;
  80.                 }
  81.                 if(count2==3){
  82.                         num2=value1+value2;
  83.                         num1=value1;
  84.                         count2=0;
  85.                 }
  86.         }
  87. }
  88. void display(uchar shi1,uchar ge1,uchar shi2,uchar ge2)
  89. {        
  90.         uchar temp;
  91.         temp=P2;
  92.         P2=0xfe;
  93.         P0=table[shi1];
  94.         delay(5);
  95.         P2=0xfd;
  96.         P0=table[ge1];
  97.         delay(5);
  98.         P2=0xfb;
  99.         P0=table[shi2];
  100.         delay(5);
  101.         P2=0xf7;
  102.         P0=table[ge2];
  103.         delay(5);
  104. }
  105. void delay(uint x)
  106. {
  107.         uint i,j;
  108.         for(i=x;i>0;i--) //;
  109.             for(j=125;j>0;j--) ;
  110. }
  111. void mkeys()
  112. {
  113.         uchar temp,key;
  114.         P3=0xfe;
  115.         temp=P3;
  116.         temp=temp&0xf0;
  117.         if(temp!=0xf0)
  118.         {
  119.                 delay(10) ;
  120.                 temp=P3;
  121.                 temp=temp&0xf0;
  122.                 if(temp!=0xf0) {
  123.                         temp=P3;
  124.                         switch(temp)
  125.                         {
  126.                         case 0xee:
  127.                                 key=0;
  128.                                 P2=P2&0xbf;
  129.                                 break;
  130.                         case 0xde:
  131.                                 key=1;
  132.                                 break;
  133.                         case 0xbe:
  134.                                 key=2;
  135.                                 break;
  136.                         case 0x7e:
  137.                                 key=3;
  138.                                 break;
  139.                         }
  140.                         while (temp!= 0xf0)
  141.                         temp=P3;
  142.                         temp= temp&0xf0;
  143.                 }
  144.                 if (key==0){
  145.                         TR0=~TR0;
  146.                         flag1=~ flag1;
  147.                         flag2=~ flag2;
  148.                 }
  149.                 if (key==1&&flag1==0){
  150.                         TR0=0;
  151.                         P1=0x44;
  152.                         shi1=ge1=shi2=ge2=16;
  153.                 }
  154.                 if (key==2&&flag2==0){
  155.                         TR0=1;
  156.                         num=0;
  157.                         P1=0x41;
  158.                         num1=value1;
  159.                         num2=value2+ value1;
  160.                         shi1=num1/10;
  161.                         ge1=num1%10;
  162.                         shi2=num2/10;
  163.                         ge2=num2%10;
  164.                 }
  165.                 if(key==3&P1==0x44){
  166.                         P1=0xff;
  167.                         delay (1000);
  168.                         P1=~ P1;
  169.                         shi1=ge1=shi2=ge2=17;
  170.                         P1=0x44;
  171.                 }
  172.         }
  173. //}
  174.         P3=0xfd;
  175.         temp=P3;
  176.         temp=temp&0xf0;
  177.         if(temp!=0xf0);
  178.         {
  179.                 delay (10);
  180.                 temp=P3;
  181.                 temp=temp&0xf0;
  182.                 if(temp! =0xf0){
  183.                         temp=P3;
  184.                         switch (temp);
  185.                         {
  186.                         case 0xed:
  187.                                 key=0;
  188.                                 break;
  189.                         case 0xdd:
  190.                                 key=1;
  191.                                 break;
  192.                         case 0xbd:
  193.                                 key=2;
  194.                                 break;
  195.                         case 0x7d:
  196.                                 key=3;
  197.                                 break;
  198.                         }
  199.                         while(temp!=0xf0)
  200.                         {
  201.                                 temp=P3;
  202.                                 temp=temp&0xf0;
  203.                         }
  204.                         if(key==0&&P1==0x44)
  205.                         { num1=value1;
  206.                                 if(num2! =159)
  207.                                 {num1++;
  208.                                         value1=num1;
  209.                                 }
  210.                                 shi1=num1/10;
  211.                                 ge1=num1% 10;
  212.                                 num2=value1+ value2;
  213.                                 shi2=num2/10;
  214.                                 ge2=num2% 10;
  215.                         }
  216.                         if(key==1&&P1==0x44)
  217.                         { num1=value2;
  218.                                 if(num2! =159) {
  219.                                         num1++;
  220.                                         value2=num1;
  221.                                 }
  222.                                 shi1=num1/10;
  223.                                 ge1=num1% 10;
  224.                                 num2=value1+value2;
  225.                                 shi2=num2/10;
  226.                                 ge2=num2% 10;
  227.                         }
  228.                         if(key==2&&P1==0x44&&value1> 3)
  229.                         {
  230.                                 num1=value1;
  231.                                 num1-- ;
  232.                                 value1=num1;
  233.                                 shi1=num1/10;
  234.                                 ge1=num1% 10;
  235.                                 num2=value1+ value2;
  236.                                 shi2=num2/10;
  237.                                 ge2=num2% 10;
  238.                         }
  239.                         if(key==3&&P1==0x44&&value2> 3)
  240.                         {
  241.                                 num1=value2;
  242.                                 num1-- ;
  243.                                 value2=num1;
  244.                                 shi1=num1/10;
  245.                                 ge1=num1% 10;
  246.                                 num2=value1+ value2;
  247.                                 shi2=num2/10;
  248.                                 ge2=num2% 10;
  249.                         }
  250.                 }
  251.         }
  252.         P3=0xfb;
  253.         temp=P3;
  254.         temp=temp&0xf0;
  255.         if(temp! =0xf0)
  256.         {
  257.                 delay(10);
  258.                 temp=P3;
  259.                 temp=temp&0xf0;
  260.                 if(temp! =0xf0){
  261.                         temp=P3;
  262.                         switch(temp)
  263.                         {
  264.                         case 0xeb:
  265.                                 key=0;
  266.                                 break;
  267.                         case 0xdb:
  268.                                 key=1;
  269.                                 break;
  270.                         case 0xbb:
  271.                                 key=2;
  272.                                 break;
  273.                         case 0x7b:
  274.                                 key=3;
  275.                                 break;
  276.                         }
  277.                         while(temp! =0xf0)
  278.                         {
  279.                                 temp=P3;
  280.                                 temp= temp&0xf0;
  281.                         }
  282.                         if(key==0&&P1==0x44){
  283.                                 num2=value3;
  284.                                 if(num1! =159){
  285.                                         num2++;
  286.                                         value3=num2;
  287.                                 }
  288.                                 shi2=num2/10;
  289.                                 ge2=num2% 10;
  290.                                 num1=value3+ value4;
  291.                                 shi1=num1/10;
  292.                                 ge1=num1% 10;
  293.                         }
  294.                         if(key==1&&P1==0x44){
  295.                                 num2=value4;
  296.                                 if(num1! =159){
  297.                                         num2++;
  298.                                         value4=num2;
  299.                                 }
  300.                                 shi2=num2/10;
  301.                                 ge2=num2% 10;
  302.                                 num1=value3+ value4;
  303.                                 shi1=num1/10;
  304.                                 ge1=num1% 10
  305.                         }
  306.                         if(key==2&&P1==0x44&value3> 3){
  307.                                 num2=value3;
  308.                                 num2--;
  309.                                 value3=num2;
  310.                                 shi2=num2/10;
  311.                                 ge2=num2% 10;
  312.                                 num1=value3+ value4;
  313.                                 shi1=num1/10;
  314.                                 ge1=num1% 10
  315.                         }
  316.                         if(key==3&&P1==0x44&&value4> 3){ //}
  317.                                 num2=value4;
  318.                                 num2--;
  319.                                 value4=num2 ;
  320.                                 shi2=num2/ 10;
  321.                                 ge2=num2% 10;
  322.                                 num1=value3+ value4;
  323.                                 shi1=num1/10;
  324.                                 ge1=num1% 10
  325.                         }
  326.                 }
  327.         }
  328.         P3=0xf7;
  329.         temp=P3;
  330.         temp=temp&0xf0;
  331.         if (temp! =0xf0)
  332.         {
  333.                 delay(10) ;
  334.                 temp=P3;
  335.                 temp=temp&0xf0;
  336.                 if (temp! =0xf0) {
  337.                         temp= P3;
  338.                         switch (temp)
  339.                         {
  340.                         case 0xe7 :
  341.                                 key= 0;
  342.                                 P2= P2&0xdf;
  343.                                 break;
  344.                         case 0xd7 :
  345.                                 key=1;
  346.                                 P2= P2&0xef;
  347.                                 break;
  348.                         case 0xb7 :
  349.                                 key=2;
  350.                                 break;
  351.                         case 0x77 :
  352.                                 key= 3;
  353.                                 break;
  354.                         }
  355.                         while (temp! =0xf0)
  356.                         {
  357.                                 temp=P3;
  358.                                 temp= temp&0xf0;
  359.                         }
  360.                         if (key==0&&P1==0x44){
  361.                                 P1=0x41;
  362.                                 shi1=ge1=shi2=ge2=18;
  363.                         }
  364.                         if (key==1&&P1==0x44){
  365.                                 P1=0x14;
  366.                                 shi1=ge1=shi2=ge2=18;
  367.                         }
  368.                         if (key==2&&P1==0x44){
  369.                                 P1=0x14;
  370.                                 shi1=ge1=shi2=ge2=18;

  371.                         }
  372.                         if (key==3&&P1==0x44) {
  373.                                 P1=0x14;
  374.                                 shi1=ge1=shi2=ge2=18;

  375.                         }
  376.                 }
  377.         }
  378. }
  379. void TO_time() interrupt 1
  380. {
  381.         TH0= (65536-50000)/256;
  382.         TLO= (65536-50000)%256;
  383.         num++ ;
  384. }

复制代码

评分

参与人数 1黑币 +40 收起 理由
admin + 40 回帖助人的奖励!

查看全部评分

回复

使用道具 举报

8#
ID:941274 发表于 2021-6-22 08:54 来自手机 | 只看该作者
根据错误,一句一句搜错误原因,改错
回复

使用道具 举报

9#
ID:386001 发表于 2021-6-22 09:24 | 只看该作者
错误的地方太多了(如,少;号,后面有的代码都没有函数名),而且代码又杂又乱,光靠人眼识别,太难了,写代码,首先要理清思路的

评分

参与人数 1黑币 +20 收起 理由
admin + 20 回帖助人的奖励!

查看全部评分

回复

使用道具 举报

10#
ID:942007 发表于 2021-6-22 09:27 来自手机 | 只看该作者
已经解决了,谢谢各位
回复

使用道具 举报

11#
ID:123289 发表于 2021-6-22 13:48 | 只看该作者
每一句都有提示,按照提示处理就可以了。
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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