找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1361|回复: 6
收起左侧

单片机循迹小车程序编译错误,有大佬帮忙教教怎么改吗

[复制链接]
ID:730552 发表于 2020-5-2 16:01 | 显示全部楼层 |阅读模式
51hei图片_20200502155701.png
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar temp1,temp2,signal1,signal2;

void delay_1ms(uint d)
{
uint i;
while(d--)
  for(i=0;i<75;i++);
}
void  main0()
{
    EA=1;
ET1=1;
TR1=1;
TMOD=0x01;
TH1=-(1000/256);
TL1=-(1000%256);
temp1=P0;
signal1=temp1&0xff;
if(signal1==0xff)
    {
void  motor_run()     // ??????
{
    P1=0x53;
    delay_1ms(150);
    P1=0x00;
    delay_1ms(20);
/* ENA=1;
OUT1=0;
OUT2=1;
delay_1ms(800);
OUT2=0;
delay_1ms(200);

ENB=1;
OUT4=0;
OUT3=1;
delay_1ms(800);
OUT3=0;
delay_1ms(200);
*/
}
void motor_left()    //???
{
    P1=0x50;
delay_1ms(150);
P1=0x00;
delay_1ms(20);
}
void motor_right()    //???
{
    P1=0x03;
delay_1ms(150);
P1=0x00;
delay_1ms(20);
}
  void motor_big_right()    //?????
{
P1=0x33;
delay_1ms(150);
P1=0x00;
delay_1ms(20);
}
void motor_big_left()     //?????
{
P1=0x55;
delay_1ms(150);
P1=0x00;
delay_1ms(20);
}

void motor_stop()     //?????
{
  P1=0x00;
}
void motor_back()      //???????
{
P1=0x35;
}
void main1()
{
EA=1;
ET1=1;
TR1=1;
TMOD=0x01;
TH1=-(1000/256);
TL1=-(1000%256);
while(1)
{
   temp2=P2;
  signal2=temp2&0xff;     //????????????
  switch(signal2)
  {
   case 0xff:    //?????
    motor_run();
    break;
   case  0xfb:    //????
       motor_left();
    break;
      case  0xfd:       //???
   case  0xf9:
       motor_big_left();
    break;
   case  0xfe:    //???????
   case  0xfc:            
       motor_big_left();
    delay_1ms(10);
    break;
   case  0xef:     //????
       motor_right();
    break;   
   case  0xdf:    //???
   case  0xcf:
       motor_big_right();
    break;
   case  0xbf:   //???????
   case  0x9f:
       motor_big_right();
    delay_1ms(10);
    break;
   case  0xc9:    //?м??????????????????
   case  0x88:    //???д???????????????
       motor_back();
    delay_1ms(200);
    motor_stop();
   default:
    break;
  }  
}
   
  }
  }
else
{      

void  motor_run1 ()     // ?????????
{
    P1=0x35;
    delay_1ms(150);
    P1=0x00;
    delay_1ms(20);
/* ENA=1;
OUT1=1;
OUT2=0;
delay_1ms(800);
OUT2=1;
delay_1ms(200);

ENB=1;
OUT4=1;
OUT3=0;
delay_1ms(800);
OUT3=1;
delay_1ms(200);
*/
}
void motor_left1()    //???
{
    P1=0x30;
delay_1ms(150);
P1=0x00;
delay_1ms(20);
}
void motor_right1()    //???
{
    P1=0x05;
delay_1ms(150);
P1=0x00;
delay_1ms(20);
}
  void motor_big_right1()    //?????
{
P1=0x55;
delay_1ms(150);
P1=0x00;
delay_1ms(20);
}
void motor_big_left1()     //?????
{
P1=0x33;
delay_1ms(150);
P1=0x00;
delay_1ms(20);
}

void motor_stop1()     //?????
{
  P1=0x00;
}
void motor_back1()      //???????
{
P1=0x53;
}
void main2()
{
EA=1;
ET1=1;
TR1=1;
TMOD=0x01;
TH1=-(1000/256);
TL1=-(1000%256);
while(1)
{
   temp2=P2;
  signal2=temp2&0xff;     //????????????
  switch(signal2)
  {
   case 0xff:    //?????
    motor_run1();
    break;
   case  0xfb:    //????
       motor_left1();
    break;
      case  0xfd:       //???
   case  0xf9:
       motor_big_left1();
    break;
   case  0xfe:    //???????
   case  0xfc:            
       motor_big_left1();
    delay_1ms(10);
    break;
   case  0xef:     //????
       motor_right1();
    break;   
   case  0xdf:    //???
   case  0xcf:
       motor_big_right1();
    break;
   case  0xbf:   //???????
   case  0x9f:
       motor_big_right1();
    delay_1ms(10);
    break;
   case  0xc9:    //?м??????????????????
   case  0x88:    //???д???????????????
       motor_back1();
    delay_1ms(200);
    motor_stop1();
   default:
    break;
  }  
}
   
  }
  }
}      
这几行显示语法错误,但是后面程序中有相同形式的语句,是正确的,这几个错误要怎么改,上面是完整的程序
回复

使用道具 举报

ID:452950 发表于 2020-5-2 19:55 | 显示全部楼层
主程序入口是main(),我不知道你的main0()/main1()/main2()哪个是入口
回复

使用道具 举报

ID:462827 发表于 2020-5-3 13:49 | 显示全部楼层
你这代码乱来的,函数里套函数了,估计是搞错了
回复

使用道具 举报

ID:155507 发表于 2020-5-3 16:52 | 显示全部楼层
函数里套函数了
自始至终错误百出!!!楼主看的是什么书?
你所能理解的方式都是最笨最糟糕的方法。

先学理论,打基础,否则,问题多多,事倍功半。
回复

使用道具 举报

ID:511890 发表于 2020-5-3 17:51 | 显示全部楼层
先把void  motor_run()拉到main0()外面去.
回复

使用道具 举报

ID:155507 发表于 2020-5-3 22:46 | 显示全部楼层
给你改了,对比一下就知道哪里错了。


  1. #include <reg52.h>
  2. #define uchar unsigned char
  3. #define uint  unsigned int
  4. uchar temp1,temp2,signal1,signal2;

  5. void delay_1ms(uint d)
  6. {
  7.         uint i;
  8.         while(d--)
  9.         for(i=0;i<75;i++);
  10. }

  11. void  motor_run()     // ??????
  12. {
  13.         P1=0x53;
  14.         delay_1ms(150);
  15.         P1=0x00;
  16.         delay_1ms(20);
  17.         /* ENA=1;
  18.                 OUT1=0;
  19.                 OUT2=1;
  20.                 delay_1ms(800);
  21.                 OUT2=0;
  22.                 delay_1ms(200);

  23.                 ENB=1;
  24.                 OUT4=0;
  25.                 OUT3=1;
  26.                 delay_1ms(800);
  27.                 OUT3=0;
  28.                 delay_1ms(200);
  29.                 */
  30. }
  31. void motor_left()    //???
  32. {
  33.         P1=0x50;
  34.         delay_1ms(150);
  35.         P1=0x00;
  36.         delay_1ms(20);
  37. }
  38. void motor_right()    //???
  39. {
  40.         P1=0x03;
  41.         delay_1ms(150);
  42.         P1=0x00;
  43.         delay_1ms(20);
  44. }
  45. void motor_big_right()    //?????
  46. {
  47.         P1=0x33;
  48.         delay_1ms(150);
  49.         P1=0x00;
  50.         delay_1ms(20);
  51. }
  52. void motor_big_left()     //?????
  53. {
  54.         P1=0x55;
  55.         delay_1ms(150);
  56.         P1=0x00;
  57.         delay_1ms(20);
  58. }

  59. void motor_stop()     //?????
  60. {
  61.         P1=0x00;
  62. }
  63. void motor_back()      //???????
  64. {
  65.         P1=0x35;
  66. }
  67. void  motor_run1 ()     // ?????????
  68. {
  69.         P1=0x35;
  70.         delay_1ms(150);
  71.         P1=0x00;
  72.         delay_1ms(20);
  73.         /* ENA=1;
  74.                 OUT1=1;
  75.                 OUT2=0;
  76.                 delay_1ms(800);
  77.                 OUT2=1;
  78.                 delay_1ms(200);

  79.                 ENB=1;
  80.                 OUT4=1;
  81.                 OUT3=0;
  82.                 delay_1ms(800);
  83.                 OUT3=1;
  84.                 delay_1ms(200);
  85.                 */
  86. }
  87. void motor_left1()    //???
  88. {
  89.         P1=0x30;
  90.         delay_1ms(150);
  91.         P1=0x00;
  92.         delay_1ms(20);
  93. }
  94. void motor_right1()    //???
  95. {
  96.         P1=0x05;
  97.         delay_1ms(150);
  98.         P1=0x00;
  99.         delay_1ms(20);
  100. }
  101. void motor_big_right1()    //?????
  102. {
  103.         P1=0x55;
  104.         delay_1ms(150);
  105.         P1=0x00;
  106.         delay_1ms(20);
  107. }
  108. void motor_big_left1()     //?????
  109. {
  110.         P1=0x33;
  111.         delay_1ms(150);
  112.         P1=0x00;
  113.         delay_1ms(20);
  114. }

  115. void motor_stop1()     //?????
  116. {
  117.         P1=0x00;
  118. }
  119. void motor_back1()      //???????
  120. {
  121.         P1=0x53;
  122. }

  123. void main()
  124. {
  125.         EA=1;
  126.         ET1=1;
  127.         TR1=1;
  128.         TMOD=0x01;
  129.         TH1=-(1000/256);
  130.         TL1=-(1000%256);
  131.         //EA=1;
  132.         //ET1=1;
  133.         //TR1=1;
  134.         //TMOD=0x01;
  135.         //TH1=-(1000/256);
  136.         //TL1=-(1000%256);
  137.         //EA=1;
  138.         //ET1=1;
  139.         //TR1=1;
  140.         //TMOD=0x01;
  141.         //TH1=-(1000/256);
  142.         //TL1=-(1000%256);
  143.         while(1)
  144.         {
  145.                 temp1=P0;
  146.                 signal1=temp1&0xff;
  147.                 if(signal1==0xff)
  148.                 {
  149.                         //while(1)
  150.                         {
  151.                                 temp2=P2;
  152.                                 signal2=temp2&0xff;     //????????????
  153.                                 switch(signal2)
  154.                                 {
  155.                                 case 0xff:    //?????
  156.                                         motor_run1();
  157.                                         break;
  158.                                 case  0xfb:    //????
  159.                                         motor_left1();
  160.                                         break;
  161.                                 case  0xfd:       //???
  162.                                 case  0xf9:
  163.                                         motor_big_left1();
  164.                                         break;
  165.                                 case  0xfe:    //???????
  166.                                 case  0xfc:            
  167.                                         motor_big_left1();
  168.                                         delay_1ms(10);
  169.                                         break;
  170.                                 case  0xef:     //????
  171.                                         motor_right1();
  172.                                         break;   
  173.                                 case  0xdf:    //???
  174.                                 case  0xcf:
  175.                                         motor_big_right1();
  176.                                         break;
  177.                                 case  0xbf:   //???????
  178.                                 case  0x9f:
  179.                                         motor_big_right1();
  180.                                         delay_1ms(10);
  181.                                         break;
  182.                                 case  0xc9:    //?м??????????????????
  183.                                 case  0x88:    //???д???????????????
  184.                                         motor_back1();
  185.                                         delay_1ms(200);
  186.                                         motor_stop1();
  187.                                 default:
  188.                                         break;
  189.                                 }  
  190.                         }
  191.                        
  192.                 }
  193.                 else
  194.                 {      
  195.                         //while(1)
  196.                         {
  197.                                 temp2=P2;
  198.                                 signal2=temp2&0xff;     //????????????
  199.                                 switch(signal2)
  200.                                 {
  201.                                 case 0xff:    //?????
  202.                                         motor_run();
  203.                                         break;
  204.                                 case  0xfb:    //????
  205.                                         motor_left();
  206.                                         break;
  207.                                 case  0xfd:       //???
  208.                                 case  0xf9:
  209.                                         motor_big_left();
  210.                                         break;
  211.                                 case  0xfe:    //???????
  212.                                 case  0xfc:            
  213.                                         motor_big_left();
  214.                                         delay_1ms(10);
  215.                                         break;
  216.                                 case  0xef:     //????
  217.                                         motor_right();
  218.                                         break;   
  219.                                 case  0xdf:    //???
  220.                                 case  0xcf:
  221.                                         motor_big_right();
  222.                                         break;
  223.                                 case  0xbf:   //???????
  224.                                 case  0x9f:
  225.                                         motor_big_right();
  226.                                         delay_1ms(10);
  227.                                         break;
  228.                                 case  0xc9:    //?м??????????????????
  229.                                 case  0x88:    //???д???????????????
  230.                                         motor_back();
  231.                                         delay_1ms(200);
  232.                                         motor_stop();
  233.                                 default:
  234.                                         break;
  235.                                 }  
  236.                         }
  237.                 }
  238.         }
  239. }

  240. //void main1()
  241. //{
  242. //}

  243. //void  main0()
  244. //{
  245. //}


复制代码
回复

使用道具 举报

ID:462827 发表于 2020-5-3 23:45 | 显示全部楼层
估计是抄错代码了
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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