找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 22293|回复: 8
收起左侧

51单片机避障智能小车原理图和源程序资料

  [复制链接]
ID:201534 发表于 2017-5-16 20:32 | 显示全部楼层 |阅读模式
避障智能小车电路原理图如下:
200983022524847934.gif

单片机

单片机


单片机源程序如下:
  1. 附录B
  2. 按照预定的功能,系统实现预定的功能的程序如下所示:

  3. #include <intrins.h>                                                 
  4. #include <AT89X52.h>
  5. /********************************************************************************\
  6. **                                                 宏定义区                                                                        **
  7. \********************************************************************************/

  8. /*-------------------------------  LCD模块 ------------------------------------*/
  9. #define LCD_RW                          P2_6                                 //读写控制端
  10. #define LCD_RS                          P2_7                                        //数据命令选择端
  11. #define LCD_E                           P2_5                                        //执行使能端
  12. #define LCD_Data                        P1                                          //P1口
  13. #define Write                                0x00                                        //低电平写入
  14. #define Read                                0x01                                        //高电平读出
  15. #define Data                                0x01                                        //高电平选择数据
  16. #define Cmd                                0x00                                        //低电平选择命令

  17. #define Enable                        0x00                                        //跃变到低电平时执行命令
  18. #define Disable                        0x01   
  19. #define True                                0x01
  20. #define False                                0x00
  21. #define LCD_Init                        0x38                                        //初始化模式                                                       
  22. #define LCD_DispCtr                    0x0C                                        //开显示及光标设置
  23. #define LCD_CloseCtr                0x08                                        //关显示
  24. #define LCD_CLS                        0x01                                        //清屏幕
  25. #define LCD_EnterSet                   0x06                                        //显示光标
  26. #define Busy                                P1_7                                        //忙信号

  27. /*--------------------------  测速/测距/测时模块 -------------------------------*/
  28. #define CircleLength                0.132                                //小车转一轮的长度为.132m

  29. /*--------------------------------  控速模块 -----------------------------------*/
  30. #define P03                                P0_3                                           //后电机
  31. #define P04                                P0_4                                          //后电机
  32. #define P01                                  P0_1                                           //前电机
  33. #define P02                                P0_2                                           //前电机
  34. #define P31                                P0_5                               //控制液晶背光
  35. #define P33                                P3_3

  36. /*------------------------------  菜单选择模块        ---------------------------------*/
  37. #define Line                                0x00                                        //0代表直线模式
  38. #define Curve                                0x01                                        //1代表S型模式
  39. #define Normal                        0x00                                        //0 代表正常速度
  40. #define Low                                0x01                                        //1 代表低速
  41. #define High                                0x02                                        //2 代表高速
  42. /*********************************************************************************\
  43. **                                                          全局函数声明区                                                        **
  44. \*********************************************************************************/
  45. /*-------------------------------  LCD模块 -------------------------------------*/
  46. void LCDInit(void);                                                                //LCD初始化
  47. void SetWriteCmd(void);                                                                //设置写命令模式
  48. void SetReadCmd(void);                                                                //设置读命令模式
  49. void SetWriteData(void);                                                        //设置写数据模式
  50. void WriteCmd(char cmd);                                                        //写命令
  51. void WriteData(char ddata);                                                        //写数据
  52. void ExecuteCmd(void);                                                                //执行命令
  53. void SetXY(char x,char y);                                                        //定位显示地址
  54. void DisplaySingleChar(char x,char y,char cchar);                //显示单个字符
  55. void DisplayString(char x,char y,char *str);                         //显示一段字符串
  56. void Delay(unsigned int time);                                                //延时主程序
  57. void DelayUs(unsigned int time);                                                //延时子程序
  58. bit  IsBusy(void);                                                                        //判断忙标志函数
  59. void DisplayTime(void);                                                                //显示时间
  60. void DisplayAVGSpeed(void);                                                        //显示平均速度
  61. void DisplayDistance(void);                                                        //显示路程

  62. /*--------------------------  测速/测距/测时模块 -------------------------------*/                                                
  63. void INTInit(void);                                                          //所有中断初始化
  64. void SpeedINT(void);                                                                   //测速中断
  65. void ComputeTime(void);
  66. void ComputeSpeedANDDistance(void);                                        //计算速度和距离

  67. /*--------------------------------  控速模块 -----------------------------------*/
  68. void CtrSpeedINT(void);                                                     //控速中断
  69. void Time0INT(void);          
  70. void Time1INT(void);                                                               //控速单位时间中断
  71. void Clock0_Init(void);                                                                //时钟中断初始化
  72. void Clock1_Init(void);                                                        //时钟中断初始化
  73. void CtrSpeed(void);

  74. /********************************************************************************\
  75. **                                             全局变量区                                                                        **
  76. \********************************************************************************/

  77. float  SpeedCount = 0;                                                              //测速计数脉冲
  78. float  Speed = 0.0;                                                       
  79. float  Distance = 0.0;                                        
  80. char   Time1INTCount=0;                                                                //T1中断时间计时
  81. float  PassTime=0.00;                                                                //小车行走的时间
  82. short  IsT0INT=1;                                                                       
  83. bit           IsT1INT;                                                                        //判断T1是否已经响应中断
  84. short  IsT0INT2=1;

  85. char   Thx[5]={0xf4,0xf4,0xc5,0xf4,0xff};                                    //3ms,3ms,15ms,3ms
  86. char   Tlx[5]={0x48,0x48,0x68,0x48,0xff};                       
  87. char   Thx0=0xd8;
  88. char   Tlx0=0xf0;
  89. char   Thx1=0xb1;                                                                         //20ms
  90. char   Tlx1=0xe0;


  91. short  Round=0;
  92. short  Back=0;
  93. short  Back0=0;
  94. bit    Backid;
  95. bit    Stop=0;

  96. char   Area0=0;
  97. char   Area1=0;                                                                        //区域变量

  98. char   LowSpeedArea1StartTime;
  99. char   LowSpeedArea1EndTime;
  100. char   HighSpeedAreaEndTime;
  101. char   LowSpeedArea2EndTime;
  102. char   LowSpeedArea1PassTime=0;                                                 //第一个低速区通过时间
  103. char   HighSpeedAreaPassTime=0;                                                //高速区通过时间
  104. char   LowSpeedArea2PassTime=0;                                                //第二个低速区通过时间
  105. char   ReadyToGo=4;                                                                //倒计时

  106. char   flag;
  107. bit    Roundid=0;
  108. char   Nocurve=0;
  109. char   ChangeFlag;
  110. char   Mode;

  111. bit    Running;
  112. bit    SelectedAll;                                                                //模式和速度是否选择完毕标志
  113. bit          IsSelectingMode;                                                                //模式选择标志
  114. bit          IsSelectingSpeed;                                                        //速度选择标志
  115. bit    ModeSelected;                                                                //已经被选择的模式标志
  116. char   SelectedMode=10;                                                                //模式选择是否完毕标志
  117. bit    Next;                                                                                //Next键标志
  118. bit    SpeedSelected;                                                                //已经被选中的速度方案标志
  119. char   SelectedSpeed;                                                                //速度选择是否完毕标志

  120. bit    ChoosingDisplay;                                                                //人工选择菜单开始标志
  121. bit    SelectedShow;                                                                //显示选择标志
  122. bit          SelectedReturn;                                                                //返回选择标志
  123. bit    Selected;                                                                        //确定/返回键选择标志
  124. bit    ReturnSelection;                                                                //返回键启用标志
  125. bit    AVGSpeedShow;                                                                //平均速度显示标志
  126. bit    TotalDistanceShow;                                                        //总路程显示标志
  127. bit    ReturnMain;                                                                        //返回主菜单标志

  128. bit    AutoDisplay;                                                                //自动显示标志
  129. bit    GoToChoosingDisplay;                                                        //人工选择标志

  130. bit    AutoMode=0;
  131. char   PassLineID=0;
  132. char   PassLine=0;
  133. float  PrepareDistance;
  134. float  FirstDistance;
  135. float  SecondDistance;
  136. float  ThirdDistance;
  137. int    FirstHigh;
  138. int    SecondHigh;
  139. int    ThirdHigh;
  140. float  Rate=1.25;                                                                   //5ms时的速度
  141. float  Count=4;                                                                        //时间的倍数




  142. /********************************************************************************\
  143. **                                             全局函数实现区                                                        **
  144. \********************************************************************************/

  145. /*--------------------------------        主函数 ------------------------------------*/
  146. void main()
  147. {       
  148.     P01=0;
  149.         P02=0;
  150.         P03=0;
  151.         P04=0;
  152.         P31=1;                                                                                        //单片机复位,背光开

  153.         Delay(40);                                                                                //延时等待LCD启动
  154.         LCDInit();                                                                                //初始化LCD
  155.         DisplayString(0x0,0,"  Starting...  ");
  156.         DisplayString(0x0,1,"Designed By 202");
  157.         Delay(300);
  158.         WriteCmd(LCD_CLS);
  159.                                                        
  160.         EA=1;                                                                                          //开总中断
  161.         EX0=1;                                                                                        //开INT0中断
  162.         IT0=1;                                                                                        //INTO边沿触发
  163.         EX1=1;                                                                                     //开INT1中断
  164.         IT1=1;                                                                                         //INT1边沿触发       

  165.         SelectedAll=False;                                                                       //开始模式和速度选择
  166.        
  167.         /*------------------------------  模式选择 ---------------------------------*/
  168.         DisplayString(0x0,0,"Choose The Mode ");
  169.         DisplayString(0x0,1,"you want.       ");
  170.         Delay(50);
  171.         WriteCmd(LCD_CLS);
  172.        
  173.         IsSelectingMode=True;
  174.         while(1)
  175.         {                                                                                                  
  176.                 WriteCmd(LCD_CLS);
  177.                 DisplayString(0x0,0,"   Line Mode   ");
  178.                 DisplayString(0x0,1,"Next        Yes");

  179.                 Delay(300);                                                                //延时消除抖动

  180.                 while (1)                                                                           //不断检测中断,直到按确定键或是NEXT键
  181.                 {
  182.                         if (Next==True)                                                //如果按Next键则直接跳出
  183.                                 break;
  184.                         if (ModeSelected==True)                                        //如果按确定键则设置模式为Line并跳出
  185.                         {       
  186.                                 SelectedMode=Line;
  187.                                 break;
  188.                         }                                                                        //如果什么键都没有按下,那么一直显示等待
  189.                 }

  190.                 if (ModeSelected==True)                                                //按下了确定键,退出模式选择       
  191.                 {       
  192.                         IsSelectingMode=False;
  193.                         break;
  194.                 }
  195.                 if (Next==True)                                                        //按下了Next键,显示下一个菜单项
  196.                 {
  197.                         Next=False;
  198.                         WriteCmd(LCD_CLS);
  199.                         DisplayString(0x0,0,"  Curve Mode   ");
  200.                         DisplayString(0x0,1,"Next        Yes");                       
  201.                        
  202.                         Delay(300);                                                        //延时消除抖动

  203.                         while(1)                                                                //不断检测中断,直到按确定键或是Next键
  204.                     {
  205.                                 if (Next==True)                                        //如果再一次按下Next键,则跳出
  206.                                         break;
  207.                                 if (ModeSelected==True)                        //如果按下确定键,则设置模式为Curve,并跳出
  208.                                 {
  209.                                         SelectedMode=Curve;
  210.                                         break;
  211.                                 }
  212.                         }
  213.                 }
  214.             
  215.                 if (ModeSelected==True)                                            //按下了确定键,退出模式选择
  216.                 {
  217.                         IsSelectingMode=False;
  218.                         break;
  219.                 }

  220.                 if (Next==True)                                                        //再一次按下了Next键,则循环模式选择
  221.                 {
  222.                         Next=False;
  223.                         WriteCmd(LCD_CLS);
  224.                         DisplayString(0x0,0,"    AutoMode    ");
  225.                         DisplayString(0x0,1,"Next         Yes");

  226.                         Delay(300);                                                    //延时消除抖动

  227.                         while(1)
  228.                         {
  229.                                 if (Next==True)
  230.                                         break;
  231.                                 if (ModeSelected==True)
  232.                                 {
  233.                                         AutoMode=1;
  234.                                         break;       
  235.                                 }
  236.                         }
  237.                 }

  238.                 if (ModeSelected==True)
  239.                 {
  240.                         IsSelectingMode=False;
  241.                         break;
  242.                 }

  243.                 if (Next==True)
  244.                 {
  245.                         Next=False;
  246.                         continue;
  247.                 }
  248.         }
  249.        
  250.         Delay(50);
  251.         WriteCmd(LCD_CLS);   
  252.        
  253.         /*------------------------------  速度选择 ---------------------------------*/
  254.         if (SelectedMode==Line && AutoMode==0)
  255.         {
  256.                 DisplayString(0x0,0,"  Now Choose a  ");
  257.                 DisplayString(0x0,1,"  kind of Speed ");
  258.                 Delay(50);
  259.                 WriteCmd(LCD_CLS);
  260.                
  261.                 IsSelectingSpeed=True;
  262.                 while(1)                                                                                       
  263.                 {
  264.                         WriteCmd(LCD_CLS);
  265.                         DisplayString(0x0,0," Normal Speed   ");
  266.                         DisplayString(0x0,1,"Next         Yes");

  267.                         Delay(300);                                                         //延时消除抖动
  268.                        
  269.                         while(1)
  270.                         {
  271.                                 if (Next==True)                                         //如果按Next键则直接跳出
  272.                                         break;
  273.                                 if (SpeedSelected==True)                      //如果按确定键则设置速度为Normal并跳出
  274.                                 {       
  275.                                         Thx[0]=0xec;Tlx[0]=0x78;                  //5ms
  276.                                         Thx[1]=0xf0;Tlx[1]=0x60;                  //4ms
  277.                                         Thx[2]=0x8a;Tlx[2]=0xd0;                   //30ms
  278.                                         Thx[3]=0xf4;Tlx[3]=0x48;              //3ms
  279.                                         SelectedSpeed=Normal;
  280.                                         break;
  281.                                 }                                                                 //如果什么键都没有按下,那么一直显示等待                       
  282.                         }
  283.        
  284.                         if (SpeedSelected==True)                                  //按下了确定键,退出速度选择       
  285.                         {       
  286.                                 IsSelectingSpeed=False;
  287.                                 break;
  288.                         }
  289.        
  290.                         if (Next==True)
  291.                         {
  292.                                 Next=False;
  293.                                 WriteCmd(LCD_CLS);
  294.                                  DisplayString(0x0,0,"   Low  Speed   ");
  295.                                 DisplayString(0x0,1,"Next         Yes");
  296.                                
  297.                                 Delay(300);                                             //延时消除抖动

  298.                                 while(1)
  299.                                 {
  300.                                         if (Next==True)                                //如果再一次按下Next键,则跳出
  301.                                                 break;
  302.                                         if (SpeedSelected==True)                //如果按下确定键,则设置速度为Low,并跳出
  303.                                         {       
  304.                                                 SelectedSpeed=Low;                        //这里没有速度设置,因为默认速度就是Low
  305.                                                 break;
  306.                                         }                               
  307.                                 }                       
  308.                         }
  309.        
  310.                         if (SpeedSelected==True)                                //按下了确定键,退出速度选择
  311.                         {
  312.                                 IsSelectingSpeed=False;
  313.                                 break;
  314.                         }
  315.        
  316.                         if (Next==True)
  317.                         {
  318.                                 Next=False;
  319.                                 WriteCmd(LCD_CLS);
  320.                                 DisplayString(0x0,0,"  High  Speed   ");
  321.                                 DisplayString(0x0,1,"Next         Yes");

  322.                                 Delay(300);                                         //延时消除抖动
  323.        
  324.                                 while(1)
  325.                                 {
  326.                                         if (Next==True)                         //如果再一次按下Next键,则跳出
  327.                                                 break;
  328.                                         if (SpeedSelected==True)         //如果按下确定键,则设置速度为High,并跳出
  329.                                         {
  330.                                                 Thx[0]=0xe0;Tlx[0]=0xc0; //8ms
  331.                                                 Thx[1]=0xe0;Tlx[1]=0xc0;  //8ms
  332.                                             Thx[2]=0x63;Tlx[2]=0xc0;  //40ms
  333.                                             Thx[3]=0xec;Tlx[3]=0x78;  //5ms
  334.                                                 SelectedSpeed=High;
  335.                                                 break;
  336.                                         }                               
  337.                                 }                       
  338.                         }
  339.        
  340.                         if (SpeedSelected==True)                                  //按下了确定键,退出速度选择
  341.                         {
  342.                                 IsSelectingSpeed=False;
  343.                                 break;
  344.                         }
  345.        
  346.                         if (Next==True)                                           //再一次按下了Next键,则循环速度选择
  347.                         {
  348.                                 Next=False;
  349.                                 continue;
  350.                         }
  351.        
  352.                 }
  353.         }

  354.         SelectedAll=True;                                 //标志模式选择和速度选择完毕
  355.        
  356.         Running=True;
  357.         Delay(50);
  358.         WriteCmd(LCD_CLS);

  359.        
  360.         /*-------------------------  显示所选择的模式和速度方案 -------------------------*/
  361.         if (SelectedMode==Line)
  362.         {       
  363.                 DisplayString(0x0,0,"Choosen Mode is ");
  364.                 DisplayString(0x0,1,"      Line      ");
  365.                 Delay(50);
  366.                 WriteCmd(LCD_CLS);
  367.         }
  368.         if (SelectedMode==Curve)
  369.         {
  370.                
  371.                 DisplayString(0x0,0,"Choosen Mode is ");
  372.                 DisplayString(0x0,1,"     Curve      ");
  373.                 Delay(50);
  374.                 WriteCmd(LCD_CLS);
  375.         }
  376.         if (AutoMode==1)
  377.         {
  378.                 DisplayString(0x0,0,"Choosen Mode is ");
  379.                 DisplayString(0x0,1,"    AutoMode    ");
  380.                 Delay(50);
  381.                 WriteCmd(LCD_CLS);
  382.         }                                  

  383.         if (SelectedMode==Line)
  384.         {
  385.                 if (SelectedSpeed==Normal)
  386.                 {
  387.                         DisplayString(0x0,0,"Choosen Speed is");
  388.                         DisplayString(0x0,1,"     Normal     ");
  389.                         Delay(50);
  390.                         WriteCmd(LCD_CLS);
  391.                 }
  392.        
  393.                 if (SelectedSpeed==Low)
  394.                 {
  395.                         DisplayString(0x0,0,"Choosen Speed is");
  396.                         DisplayString(0x0,1,"      Low       ");
  397.                         Delay(50);
  398.                         WriteCmd(LCD_CLS);
  399.                 }
  400.        
  401.                 if (SelectedSpeed==High)
  402.                 {
  403.                         DisplayString(0x0,0,"Choosen Speed is");
  404.                         DisplayString(0x0,1,"      High      ");
  405.                         Delay(50);
  406.                         WriteCmd(LCD_CLS);
  407.                 }
  408.         }

  409.         INTInit();                                                                                           //初始化所有中断
  410.         DisplayString(0x0,0,"Left Times To Go");
  411.         while (ReadyToGo--)
  412.     {
  413.                 DisplaySingleChar(0x7,1,ReadyToGo+0x30);
  414.                 DisplaySingleChar(0x09,1,'s');
  415.                 Delay(300);               
  416.         }
  417.         WriteCmd(LCD_CLS);
  418.         DisplayString(0x05,0,"Go!!!");
  419.         Delay(100);
  420.         WriteCmd(LCD_CLS);
  421.         DisplayString(0x0,0,"   Living...   ");
  422.         DisplayString(0x0,1,"Designed by 202");

  423.        
  424.         if (SelectedMode==Line&&AutoMode==0)
  425.                 flag=Area0;
  426.         else
  427.             flag=1;
  428.        
  429.         while(flag<5)
  430.         {  
  431.                 if(AutoMode==1)                                                                          //自动模式
  432.             {
  433.                         switch(PassLineID)
  434.                     {
  435.                            case 0  :{
  436.                                                            if(IsT0INT==1)
  437.                                                                 {P01=P02=P04=0;P03=1;}             
  438.                                                          else
  439.                                                                {P01=P02=P03=P04=0;}               
  440.                                                 }break;
  441.                            case 1  :{
  442.                                       P01=P02=P03=0;P04=1;
  443.                                     }break;
  444.                            case 2  :{
  445.                                              P01=P02=P04=0;P03=1;             
  446.                                     }break;
  447.                            default :break;
  448.                     }
  449.                 }
  450.            else
  451.            {                       
  452.                         if(SelectedMode==Line)                                                      //直线模式
  453.                     {
  454.                                   flag=Area0;
  455.                                   if(IsT0INT==1)       
  456.                                       {P03=1;P04=0;P01=P02=0;}
  457.                             else
  458.                                         {P03=0;P04=0;P01=P02=0;}
  459.                     }
  460.                            else                                                                          
  461.                     {                                                                                       //S型模式
  462.                                  if((Nocurve<2)&&Round!=0&&(Back0>0)&&Back!=0)
  463.                               {
  464.                                             if(Backid==1)
  465.                                              {P01=1;P02=0;P03=0;P04=1;}
  466.                                           else
  467.                                           {P01=0;P02=1;P03=0;P04=1;}
  468.                                       Back=1;           
  469.                           }          
  470.                                   else
  471.                               {
  472.                                             if(Round==0)
  473.                                           {
  474.                                                      if(IsT0INT2==1)
  475.                                                         {P01=0;P02=0;P03=1;P04=0;}
  476.                                                else
  477.                                                         {P01=0;P02=0;P03=0;P04=0;}
  478.                                       }
  479.                                           else  
  480.                                           {       
  481.                                                      if(P33==0)
  482.                                                      {
  483.                                                                   if(IsT0INT2==1)
  484.                                                                         {P01=0;P02=0;P03=1;P04=0;}
  485.                                                                    else
  486.                                                                     {P01=0;P02=0;P03=0;P04=0;}
  487.                                                }
  488.                                                else
  489.                                {
  490.                                                                    EX1=1;
  491.                                                                     if(Round%2)
  492.                                                    {  
  493.                                                                           if(IsT0INT2==1)
  494.                                                                 {P01=1;P02=0;P03=1;P04=0;Backid=1;}
  495.                                                             else
  496.                                                                 {P01=1;P02=0;P03=0;P04=0;}
  497.                                                                    }
  498.                                                        else
  499.                                                                    {
  500.                                                                            if(IsT0INT2==1)
  501.                                                      {P01=0;P02=1;P03=1;P04=0;Backid=0;}
  502.                                                                            else
  503.                                                                     {P01=0;P02=1;P03=0;P04=0;}
  504.                                                         }
  505.                                            }
  506.                                            }
  507.                           }  
  508.                     }                       
  509.                 }
  510.                
  511.                 if (IsT1INT==1)
  512.                 {
  513.                         IsT1INT=0;
  514.                         ComputeTime();
  515.                         ComputeSpeedANDDistance();
  516.                 }
  517.         }
  518.        
  519.         //补中断路程,加上最后一次中断缺失的路程
  520.         ComputeSpeedANDDistance();
  521.         P04=1;P03=0;P01=P02=0;Delay(90);
  522.         P03=0;P04=0;                                                                                //行程结束,小车停止
  523.         P31=1;                                                                                            //行程结束,背光开
  524.         ET0=0x0;                                                                            //关T0中断
  525.         ET1=0x0;                                                                                       //关T1中断
  526.         EX1=0x01;                                                                                          //开INT1中断
  527.         Running=False;
  528.        
  529.        
  530.         AutoDisplay=True;                                                //默认情况下直线模式会自动显示各个区域经过的时间
  531.         WriteCmd(LCD_CLS);
  532.        
  533.         if (SelectedMode==Line)                                                            //直线模式才显示
  534.         {
  535.                 while(1)
  536.                 {
  537.                         if (GoToChoosingDisplay==True)
  538.                                 break;
  539.                         Delay(200);
  540.                         WriteCmd(LCD_CLS);
  541.                         Delay(200);
  542.                         DisplayString(0,0," LowSpeedArea1");
  543.                         DisplayString(0,1," Costed ");
  544.                         DisplaySingleChar(0x0C,1,'s');
  545.                         LowSpeedArea1PassTime=LowSpeedArea1EndTime-LowSpeedArea1StartTime;
  546.                         DisplaySingleChar(0x0A,1,LowSpeedArea1PassTime%10+0x30);
  547.                         if (LowSpeedArea1PassTime > 9)                        //通过第一个低速区的时间超过s
  548.                                 DisplaySingleChar(0x0B,1,LowSpeedArea1PassTime/10+0x30);
  549.                                
  550.                         if (GoToChoosingDisplay==True)
  551.                                  break;
  552.                         Delay(200);
  553.                         WriteCmd(LCD_CLS);
  554.                         Delay(200);
  555.                         DisplayString(0,0," HighSpeedArea ");
  556.                         DisplayString(0,1," Costed ");
  557.                         DisplaySingleChar(0x0C,1,'s');
  558.                         HighSpeedAreaPassTime=HighSpeedAreaEndTime-LowSpeedArea1EndTime;
  559.                         DisplaySingleChar(0x0A,1,HighSpeedAreaPassTime%10+0x30);
  560.                         if ( HighSpeedAreaPassTime> 9)                             //通过高速区的时间超过s
  561.                                 DisplaySingleChar(0x0B,1,HighSpeedAreaPassTime/10+0x30);
  562.        

  563.                         if (GoToChoosingDisplay==True)
  564.                                 break;
  565.                         Delay(200);
  566.                         WriteCmd(LCD_CLS);
  567.                         Delay(200);
  568.                         DisplayString(0,0," LowSpeedArea2 ");
  569.                         DisplayString(0,1," Costed ");
  570.                         DisplaySingleChar(0x0C,1,'s');
  571.                         LowSpeedArea2PassTime=LowSpeedArea2EndTime-HighSpeedAreaEndTime;
  572.                         DisplaySingleChar(0x0A,1,LowSpeedArea2PassTime%10+0x30);
  573.                         if ( LowSpeedArea2PassTime> 9)                             //通过第二个低速区的时间超过s
  574.                                 DisplaySingleChar(0x0B,1,LowSpeedArea2PassTime/10+0x30);       

  575.                 }
  576.         }
  577.        
  578.         AutoDisplay=False;

  579.         /*----------------  菜单选择你想要看的内容--总时间、总路程以及平均速度 --------------*/
  580.         ChoosingDisplay=True;                                                                  
  581.         WriteCmd(LCD_CLS);

  582.         /*首先显示主菜单,然后显示第一个选项*/
  583.         DisplayString(0x0,0,"Now Choose what ");
  584.         DisplayString(0x0,1,"you want to see ");
  585.         Delay(100);

  586.         while(1)
  587.         {
  588.                
  589.                 WriteCmd(LCD_CLS);
  590.                 DisplayString(0x0,0,"   Costed Time  ");
  591.                 DisplayString(0x0,1,"Next        Show");

  592.                 Delay(250);                                                                                //延时消除抖动

  593.     /*------------------------------------第一次按键--------------------------------------*/
  594.                
  595.                 /*不断检测确定键和Next键*/
  596.                 while(1)
  597.                 {
  598.                         if (Next==True)
  599.                                 break;
  600.                         if (SelectedShow==True)
  601.                                 break;
  602.                 }

  603.                 /*按下了确定键,显示第一个选项的内容*/
  604.                 if (SelectedShow==True)          
  605.                 {
  606.                         SelectedShow=False;
  607.                         SelectedReturn=False;
  608.                         Selected=False;
  609.                         WriteCmd(LCD_CLS);
  610.                         DisplayString(0,0,"Costed Time is");                                  
  611.                         DisplayTime();
  612.                         DisplayString(0x0A,1,"s");
  613.                         ReturnSelection=True;                                 //按下了确定键,那么这个时候开启返回键的功能               
  614.                         AVGSpeedShow=False;               

  615.                         Delay(250);                                                //延时消除抖动
  616.                 }

  617.                 /**按下了Next键,则显示第二个选项*/
  618.                 if (Next==True)                                                //按下Next键,显示AVGSpeed菜单项
  619.                 {
  620.                         Next=False;
  621.                         WriteCmd(LCD_CLS);
  622.                         DisplayString(0x0,0,"    AVGSpeed    ");
  623.                         DisplayString(0x0,1,"Next        Show");                                       
  624.                         ReturnMain=False;
  625.                         ReturnSelection=False;                              //按下了Next键,那么这个时候关闭返回键的功能
  626.                         AVGSpeedShow=True;                                         //表明AVGSpeed选项已经显示过了

  627.                         Delay(250);                                                 //延时消除抖动
  628.                 }

  629.         /*------------------------------------第二次按键--------------------------------------*/
  630.                 /*显示第一个选项的内容后又不断检测返回键(确定键)和Next键*/
  631.                 while(1)
  632.                 {
  633.                         if (Next==True)
  634.                                 break;
  635.                         if (Selected==True)
  636.                                  break;
  637.                 }
  638.                                
  639.                 if (Next==True)               
  640.                 {
  641.                         Next=False;
  642.                         ReturnMain=False;
  643.                         ReturnSelection=False;                             //按下了Next键,那么这个时候关闭返回键的功能       
  644.                         if (AVGSpeedShow==False)                     //还没有显示AVGSpeed选项,显示它
  645.                         {                                                                //即第一次选择了确定键
  646.                                 WriteCmd(LCD_CLS);
  647.                                 DisplayString(0x0,0,"    AVGSpeed    ");
  648.                                 DisplayString(0x0,1,"Next        Show");
  649.                                 TotalDistanceShow=False;        //显示了AVGSpeed,则表明TotalDistance还没有显示
  650.                                
  651.                                 Delay(250);                                //延时消除抖动                                                                       
  652.                         }       
  653.                         if (AVGSpeedShow==True)                        //已经显示过AVGSpeed选项了,则显示下一个选项
  654.                         {                                                        //即第一次选择了Next键
  655.                                 WriteCmd(LCD_CLS);
  656.                                 DisplayString(0x0,0," Total Distance ");
  657.                                 DisplayString(0x0,1,"Next        Show");
  658.                                 TotalDistanceShow=True;                                    //表明显示了TotalDistance选项       

  659.                                 Delay(250);                                                        //延时消除抖动
  660.                         }
  661.                 }       

  662.                 if (Selected==True)                                                     //按下了确定键或返回键
  663.                 {
  664.                         SelectedShow=False;
  665.                         SelectedReturn=False;
  666.                         Selected=False;
  667.                         if (ReturnSelection==True)               //第一次选择了确定键,故这次按下的是返回键
  668.                                 ReturnMain=True;
  669.                         if (ReturnSelection==False)   
  670.                         {
  671.                                 WriteCmd(LCD_CLS);
  672.                                 DisplayString(0,0,"The AVGSpeed is");                                       
  673.                                 DisplayAVGSpeed();
  674.                                 DisplayString(0x0A,1,"m/s");
  675.                                 ReturnSelection=True;                         //按下了确定键,那么这个时候开启返回键的功能
  676.                                
  677.                                 Delay(250);                                        //延时消除抖动                               
  678.                         }
  679.                         TotalDistanceShow=False;                                       
  680.                 }

  681.                 if (ReturnMain==True)                                        //按下了返回键,返回主菜单
  682.                 {
  683.                         ReturnMain=False;
  684.                         continue;
  685.                 }                                               

  686.         /*------------------------------------第三次按键--------------------------------------*/

  687.                 /*如果没有返回主菜单,则继续检测Next键和确定键*/
  688.         
  689.                 while(1)
  690.                 {                            
  691.                         if (Next==True)
  692.                                 break;
  693.                         if (SelectedShow==True)
  694.                                 break;
  695.                 }
  696.                
  697.                 /*按下Next键,显示下一个选项*/
  698.                 if (Next==True)
  699.                 {
  700.                         Next=False;
  701.                         ReturnMain=False;
  702.                         ReturnSelection=False;                             //按下了Next键,那么这个时候关闭返回键的功能       
  703.                         if (TotalDistanceShow==True)
  704.                                 ReturnMain=True;
  705.                         if (TotalDistanceShow==False)                //还没有显示TotalDistance选项,显示它
  706.                         {                                                                               
  707.                                 WriteCmd(LCD_CLS);
  708.                                 DisplayString(0x0,0," Total Distance ");
  709.                                 DisplayString(0x0,1,"Next        Show");
  710.                                 TotalDistanceShow=True;                                        
  711.                                
  712.                                 Delay(250);                                                //延时消除抖动                                               
  713.                         }       
  714.                 }

  715.                 if (Selected==True)                                                //按下了确定键或返回键
  716.                 {
  717.                         SelectedShow=False;
  718.                         SelectedReturn=False;
  719.                         Selected=False;
  720.                         if (ReturnSelection==True)                           //按下的是返回键
  721.                                 ReturnMain=True;
  722.                         if (ReturnSelection==False)                         
  723.                         {
  724.                                 if (TotalDistanceShow==False)                 //表明AVGSpeed选项的内容还没有显示
  725.                                 {
  726.                                         WriteCmd(LCD_CLS);
  727.                                         DisplayString(0,0,"The AVGSpeed is");                                       
  728.                                         DisplayAVGSpeed();
  729.                                         DisplayString(0x0A,1,"m/s");
  730.                                         ReturnSelection=True;        

  731.                                         Delay(250);                                        //延时消除抖动
  732.                                 }
  733.                                 if (TotalDistanceShow==True)
  734.                                 {
  735.                                         WriteCmd(LCD_CLS);
  736.                                         DisplayString(0,0,"Total Distance");
  737.                                         DisplayDistance();
  738.                                         DisplayString(0x0A,1,"m");
  739.                                         ReturnSelection=True;                 //按下了确定键,那么这个时候开启返回键的功能

  740.                                         Delay(250);                                        //延时消除抖动
  741.                                 }
  742.                         }
  743.                 }

  744.                 if (ReturnMain==True)                                                 //按下了返回键,返回主菜单
  745.                 {
  746.                         ReturnMain=False;
  747.                         continue;                               
  748.                 }

  749.         /*------------------------------------第四次按键--------------------------------------*/
  750.                 while(1)
  751.                 {                            
  752.                         if (Next==True)
  753.                                 break;
  754.                         if (SelectedShow==True)
  755.                                 break;
  756.                 }
  757.                
  758.                 if (Next==True)                                                            //所有菜单项已经显示完毕,返回主菜单
  759.                 {
  760.                         Next=False;
  761.                         ReturnMain=False;
  762.                         ReturnSelection=False;                                
  763.                         if (TotalDistanceShow==False)               
  764.                         {                                                                               
  765.                                 WriteCmd(LCD_CLS);
  766.                                 DisplayString(0x0,0," Total Distance ");
  767.                                 DisplayString(0x0,1,"Next        Show");
  768.                                 TotalDistanceShow=True;                                
  769.                                
  770.                                 Delay(250);                                                //延时消除抖动                                                       
  771.                         }       
  772.                 }

  773.                 if (SelectedShow==True)
  774.                 {
  775.                         SelectedShow=False;
  776.                         SelectedReturn=False;
  777.                         Selected=False;
  778.                         if (ReturnSelection==True)                           //按下的是返回键
  779.                                 ReturnMain=True;
  780.                         if (ReturnSelection==False)                         
  781.                         {
  782.                                 if (TotalDistanceShow==True)
  783.                                 {
  784.                                         WriteCmd(LCD_CLS);
  785.                                         DisplayString(0,0,"Total Distance");
  786.                                         DisplayDistance();
  787.                                         DisplayString(0x0A,1,"m");
  788.                                         ReturnSelection=True; //按下了确定键,那么这个时候开启返回键的功能

  789.                                         Delay(250);                                        //延时消除抖动
  790.                                 }
  791.                         }                       
  792.                 }
  793.                
  794.                 if (ReturnMain==True)                                                 //按下了返回键,返回主菜单
  795.                 {
  796.                         ReturnMain=False;
  797.                         continue;                               
  798.                 }



  799.         /*------------------------------------第五次按键--------------------------------------*/
  800.                 while(1)
  801.                 {                            
  802.                         if (Next==True)
  803.                                 break;
  804.                         if (SelectedShow==True)
  805.                                 break;
  806.                 }

  807.                 if (Next==True)                                                     //所有菜单项已经显示完毕,返回主菜单
  808.                 {
  809.                         Next=False;
  810.                         ReturnMain=False;
  811.                         ReturnSelection=False;
  812.                         if (TotalDistanceShow==True)                        //最后一个选项已经显示完毕,返回主菜单
  813.                         {
  814.                                 ReturnMain=True;
  815.                         }                                
  816.                 }
  817.        
  818.                 if (SelectedShow==True)
  819.                 {
  820.                         SelectedShow=False;
  821.                         SelectedReturn=False;
  822.                         Selected=False;
  823.                         if (ReturnSelection==True)                           //按下的是返回键
  824.                                 ReturnMain=True;
  825.                         if (ReturnSelection==False)                         
  826.                         {
  827.                                 if (TotalDistanceShow==True)
  828.                                 {
  829.                                         WriteCmd(LCD_CLS);
  830.                                         DisplayString(0,0,"Total Distance");
  831.                                         DisplayDistance();
  832.                                         DisplayString(0x0A,1,"m");
  833.                                         ReturnSelection=True;                 //按下了确定键,那么这个时候开启返回键的功能

  834.                                         Delay(250);                                        //延时消除抖动
  835.                                 }
  836.                         }                       
  837.                 }
  838.         /*------------------------------------第六次按键--------------------------------------*/               
  839.                 while(1)
  840.                 {                            
  841.                         if (Next==True)
  842.                                 break;
  843.                         if (SelectedShow==True)
  844.                                 break;
  845.                 }

  846.                 if (Next==True)
  847.                 {
  848.                         Next=False;
  849.                         ReturnMain=False;
  850.                         ReturnSelection=False;                       
  851.                 }
  852.                 if (SelectedShow==True)
  853.                 {
  854.                         SelectedShow=False;
  855.                         SelectedReturn=False;
  856.                         Selected=False;
  857.                 }
  858.                 continue;       
  859.         }
  860.         while(1);
  861. }


  862. /****************************************************************************************\
  863. **                                                                   LCD驱动模块                                                                **
  864. \****************************************************************************************/

  865. /*---------------------------------  LCD初始化函数--------------------------------------*/

  866. void LCDInit(void)
  867. {
  868.     //三次显示模式设置
  869.         LCD_Data=0;
  870.         LCD_E=Disable;
  871.         Delay(5);
  872.         WriteCmd(LCD_Init);
  873.         Delay(5);
  874.         WriteCmd(LCD_Init);
  875.         Delay(5);
  876.         WriteCmd(LCD_Init);

  877.         WriteCmd(LCD_Init);                                                           //初始化
  878.         WriteCmd(LCD_CloseCtr);                                                        //关显示
  879.         WriteCmd(LCD_CLS);                                                                //清屏幕
  880.         WriteCmd(LCD_EnterSet);                                                        //光标移动设置
  881.         WriteCmd(LCD_DispCtr);                                                        //显示开以及光标设置
  882.        
  883. }

  884. /*---------------------------------  LCD模式设置函数--------------------------------------*\
  885.        
  886.         SetWriteCmd()                                  设置LCD为写命令模式
  887.         SetReadCmd()                                       设置LCD为读命令模式
  888.         SetWriteData()                                设置LCD为写数据模式
  889.        
  890. \*----------------------------------------------------------------------------------------*/
  891. void SetWriteCmd(void)
  892. {
  893.         LCD_RW=Write;
  894.         LCD_RS=Cmd;
  895. }

  896. void SetReadCmd(void)
  897. {
  898.         LCD_RW=Read;
  899.         LCD_RS=Cmd;
  900. }

  901. void SetWriteData(void)
  902. {
  903.         LCD_RW=Write;
  904.         LCD_RS=Data;
  905. }

  906. /*---------------------------------  LCD功能执行函数--------------------------------------*\
  907.        
  908.         WriteCmd()                                        写命令
  909.         WriteData()                                        写数据
  910.         ExecuteCmd()                                        执行命令
  911.         SetXY()                                                显示定位
  912.         DisplaySingleChar()                        显示单个字符
  913.         DisplayString()                                显示一串字符
  914.         IsBusy()                                                忙标志检测
  915. \*----------------------------------------------------------------------------------------*/
  916. void WriteCmd(char cmd)
  917. {
  918.         while(IsBusy());
  919.         LCD_Data=cmd;       
  920.         SetWriteCmd();
  921.         ExecuteCmd();
  922. }

  923. void WriteData(char ddata)
  924. {
  925.         while(IsBusy());
  926.         LCD_Data=ddata;
  927.         SetWriteData();       
  928.         ExecuteCmd();
  929. }

  930. void ExecuteCmd(void)
  931. {
  932.         LCD_E=Enable;
  933.         LCD_E=Disable;
  934. }

  935. void SetXY(char x,char y)
  936. {
  937.         if (y)
  938.                 x|=0x40;
  939.         x|=0x80;
  940.         Delay(5);
  941.         WriteCmd(x);

  942. }

  943. void DisplaySingleChar(char x,char y,char cchar)
  944. {
  945.         SetXY(x,y);
  946.         WriteData(cchar);       
  947. }

  948. void DisplayString(char x,char y,char *str)
  949. {
  950.         while(*str)
  951.         {
  952.                 Delay(5);
  953.                 DisplaySingleChar(x++,y,*str);
  954.                 str++;
  955.         }
  956. }

  957. bit IsBusy(void)
  958. {
  959.         LCD_Data=0xFF;
  960.         SetReadCmd();
  961.         ExecuteCmd();
  962.         return (bit)(P1 & 0x80);       
  963. }

  964. /*-------------------------------------    延时函数  -------------------------------------*/
  965. void Delay(unsigned int time)
  966. {
  967.     unsigned int timeCounter = 0;
  968.         for (timeCounter = time;timeCounter > 0 ;timeCounter --)
  969.                 DelayUs(255);
  970. }

  971. void DelayUs(unsigned int time)
  972. {
  973.         unsigned int timeCounter = 0;
  974.         for (timeCounter = 0;timeCounter < time;timeCounter ++)
  975.                 _nop_();
  976. }

  977. /*******************************************************************************************\
  978. **                                    LCD显示模块                                         **
  979. \*******************************************************************************************/

  980. void ComputeTime(void)
  981. {
  982.         if (Area0 < 5)
  983.                 PassTime+=0.5;
  984. }

  985. void ComputeSpeedANDDistance(void)
  986. {
  987.         Speed=SpeedCount/4*CircleLength;                                        //计算瞬时速度
  988.         Distance+=Speed;                                                                //计算距离                                               
  989.         SpeedCount=0;
  990.        
  991. }
  992. /*-------------------------------------  显示时间 ----------------------------------------*/
  993. void DisplayTime(void)
  994. {
  995.         char PassTime1=0x30;
  996.         char PassTime2=0x30;
  997.         char PassTime3=0x30;
  998.         char PassTime4=0x30;
  999.        
  1000.         if ((int)PassTime*100<100)                                  //时间未够1s
  1001.         {
  1002.                 PassTime1+=0;      
  1003.                 PassTime2+=(int)(PassTime*100)/10;
  1004.                 PassTime3+=(int)(PassTime*100)%10;
  1005.         }
  1006.         else if ((int)(PassTime*100) > 100  && (int)(PassTime*100) < 1000) //够1s而未够10s
  1007.         {
  1008.                 PassTime1+=(int)(PassTime*100)/100;
  1009.                 PassTime2+=(int)(PassTime*100)/10%10;
  1010.                 PassTime3+=(int)(PassTime*100)%10;
  1011.         }
  1012.         else
  1013.         {
  1014.                 PassTime1+=(int)(PassTime*100)/1000;
  1015.                 PassTime2+=(int)(PassTime*100)/100%10;
  1016.                 PassTime3+=(int)(PassTime*100)/10%10;
  1017.                 PassTime4+=(int)(PassTime*100)%10;
  1018.         }

  1019.         if ((int)(PassTime*100) < 1000)
  1020.         {       
  1021.                 DisplaySingleChar(0x05,1,PassTime1);
  1022.                 DisplaySingleChar(0x06,1,'.');
  1023.                 DisplaySingleChar(0x07,1,PassTime2);
  1024.                 DisplaySingleChar(0x08,1,PassTime3);
  1025.         }
  1026.         else
  1027.         {
  1028.                 DisplaySingleChar(0x04,1,PassTime1);
  1029.                 DisplaySingleChar(0x05,1,PassTime2);
  1030.                 DisplaySingleChar(0x06,1,'.');
  1031.                 DisplaySingleChar(0x07,1,PassTime3);
  1032.                 DisplaySingleChar(0x08,1,PassTime4);
  1033.         }
  1034.        
  1035.        
  1036. }
  1037. /*------------------------------------ 显示平均速度----------------------------------------*/

  1038. void DisplayAVGSpeed(void)
  1039. {
  1040.         int Speed1=0x30;                                                                        //初始化为0的ASCII码
  1041.         int Speed2=0x30;
  1042.         int Speed3=0x30;

  1043.         if ((int)(Distance/PassTime*100)< 100)
  1044.         {
  1045.                 Speed1+=0;
  1046.                 Speed2+=(int)(Distance/PassTime*100)/10;
  1047.                 Speed3+=(int)(Distance/PassTime*100)%10;
  1048.         }
  1049.         else
  1050.         {
  1051.                 Speed1+=(int)(Distance/PassTime*100)/100;
  1052.                 Speed2+=(int)(Distance/PassTime*100)/10%10;
  1053.                 Speed3+=(int)(Distance/PassTime*100)%10;
  1054.         }

  1055.         DisplaySingleChar(0x05,1,Speed1);
  1056.         DisplaySingleChar(0x06,1,'.');
  1057.         DisplaySingleChar(0x07,1,Speed2);
  1058.         DisplaySingleChar(0x08,1,Speed3);
  1059. }
  1060. /*-------------------------------------  显示路程 ----------------------------------------*/

  1061. void DisplayDistance(void)
  1062. {
  1063.         int Distance1=0x30;
  1064.         int Distance2=0x30;
  1065.         int Distance3=0x30;
  1066.         int Distance4=0x30;

  1067.         if ((int)(Distance*100) < 100)
  1068.         {
  1069.                 Distance1+=0;
  1070.                 Distance2+=(int)(Distance*100)/10;
  1071.                 Distance3+=(int)(Distance*100)%10;
  1072.         }
  1073.         else if ((int)(Distance*100) > 100  && (int)(Distance*100) < 1000)
  1074.         {
  1075.                 Distance1+=(int)(Distance*100)/100;
  1076.                 Distance2+=(int)(Distance*100)/10%10;
  1077.                 Distance3+=(int)(Distance*100)%10;
  1078.         }
  1079.         else
  1080.         {
  1081.                 Distance1+=(int)(Distance*100)/1000;
  1082.                 Distance2+=(int)(Distance*100)/100%10;
  1083.                 Distance3+=(int)(Distance*100)/10%10;
  1084.                 Distance4+=(int)(Distance*100)%10;
  1085.         }
  1086.        

  1087.         if ((int)(Distance*100) < 1000)
  1088.         {       
  1089.                 DisplaySingleChar(0x05,1,Distance1);
  1090.                 DisplaySingleChar(0x06,1,'.');
  1091.                 DisplaySingleChar(0x07,1,Distance2);
  1092.                 DisplaySingleChar(0x08,1,Distance3);
  1093.         }
  1094.         else
  1095.         {
  1096.                 DisplaySingleChar(0x04,1,Distance1);
  1097.                 DisplaySingleChar(0x05,1,Distance2);
  1098.                 DisplaySingleChar(0x06,1,'.');
  1099.                 DisplaySingleChar(0x07,1,Distance3);
  1100.                 DisplaySingleChar(0x08,1,Distance4);
  1101.         }
  1102. }
  1103. /*-------------------------------------  中断初始化  -------------------------------------*/

  1104. void INTInit(void)
  1105. {                                               
  1106.         EA=1;                                                                          //开总中断
  1107.         IT0=1;                                                                          //INTO边沿触发
  1108.         PX0=1;                                                                    //INTO优先级为高级
  1109.         EX1=1;                                                                          //开INT1中断
  1110.         IT1=1;                                                                          //INT1边沿触发
  1111.         PX1=1;                                                                    //INT1优先级为高级
  1112.         Clock0_Init();                                                   //初始化时钟中断
  1113.         TMOD=0x11;                                                                  //T0/T1定时方式1
  1114.         ET0=0x01;                                                                //开T0中断
  1115.         ET1=0x01;                                                               //开T1中断
  1116. }

  1117. void Clock0_Init(void)
  1118. {
  1119.         TR0=0x01;                                                                 //启动T0
  1120.         TH0=Thx0;                                                                       //定时初值
  1121.         TL0=Tlx0;

  1122. }
  1123. void Clock1_Init(void)
  1124. {
  1125.         TR1=0x01;                                                                //启动T1
  1126.         TH1=0x3C;                                                                          //定时初值-50ms中断一次
  1127.         TL1=0x0B0;
  1128. }

  1129. /*******************************************************************************************\
  1130. **                                                                           中断处理程序                                  **
  1131. \*******************************************************************************************/

  1132. /*-----------------------------------   外部中断0 ----------------------------------------*\

  1133.         外部中断0有两个功能
  1134.         (1)作为菜单选择的Next键
  1135.         (2)作为测速的计数器

  1136. \*-----------------------------------------------------------------------------------------*/
  1137. void SpeedINT(void) interrupt 0                          //中断INT0
  1138. {
  1139.         if (SelectedAll==False)                                //如果模式和速度还没有选择完毕,则此中断作为Next键
  1140.                 Next=True;                                                                       
  1141.         if (Running==True)                                         //如果模式和速度已经选择完毕,则此中断作为测速中断
  1142.                 SpeedCount++;
  1143.         if (ChoosingDisplay==True)                        //如果是在选择要显示的内容
  1144.                 Next=True;                         
  1145. }




  1146. /*-----------------------------------   外部中断1 ----------------------------------------*\

  1147.         外部中断1有两个功能
  1148.         (1)作为菜单选择的确定键/返回键
  1149.         (2)控速

  1150. \*-----------------------------------------------------------------------------------------*/
  1151. void CtrSpeedINT(void) interrupt 2                           //中断INT1
  1152. {                             
  1153.        
  1154.         if (SelectedAll==False)                                        //如果模式和速度还没有选择完毕,则此中断作为确定键
  1155.         {
  1156.                 if (IsSelectingMode==True)                                  //模式选择标志
  1157.                                 ModeSelected=True;
  1158.                 if (IsSelectingSpeed==True)                                  //速度选择标志
  1159.                                 SpeedSelected=True;
  1160.         }

  1161.         if (Running==True)                                         //如果模式和速度选择已经完毕,则此中断作为控速中断
  1162.         {
  1163.                 if (Area0==0)                                        //经过第一条铁线(即起跑线),开始计时,开始测速
  1164.                 {
  1165.                         EX0=1;
  1166.                         Clock1_Init();
  1167.                          P31=0;                                                                  //过起跑线,背光灭
  1168.                 }
  1169.                 if (Area0==1)
  1170.                         LowSpeedArea1StartTime=PassTime;    //读取进入第一个低速区的时刻
  1171.                 if (Area0==2)
  1172.                         LowSpeedArea1EndTime=PassTime;//读取离开第一个低速区的时刻,也就是进入高速区的时刻
  1173.                 if (Area0==3)
  1174.                         HighSpeedAreaEndTime=PassTime;//读取离开高速区的时刻,也就是进入第二个低速区的时刻
  1175.                 if (Area0==4)
  1176.                         LowSpeedArea2EndTime=PassTime;       //读取离开第二个低速去的时刻
  1177.                
  1178.                 if(AutoMode==1)                                                            //自动模式
  1179.                 {  
  1180.                            PassLine++;
  1181.                            switch(PassLine)
  1182.                            {
  1183.                                 case 5  :PassLineID=1;break;
  1184.                             case 10 :PassLineID=2;break;
  1185. ……………………

  1186. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码

所有资料51hei提供下载:
chengxu.docx (38.44 KB, 下载次数: 130)
回复

使用道具 举报

ID:203943 发表于 2017-7-27 16:17 | 显示全部楼层
谢谢分享 再学习中
回复

使用道具 举报

ID:223374 发表于 2017-7-30 22:15 | 显示全部楼层
厉害 哈哈哈
回复

使用道具 举报

ID:225338 发表于 2017-8-7 04:41 来自手机 | 显示全部楼层
太高端了
回复

使用道具 举报

ID:265318 发表于 2018-1-11 13:11 来自手机 | 显示全部楼层
学习下
回复

使用道具 举报

ID:254856 发表于 2018-1-27 15:16 | 显示全部楼层
谢谢啊
回复

使用道具 举报

ID:419428 发表于 2018-11-1 22:18 | 显示全部楼层
厉害,厉害
回复

使用道具 举报

ID:418342 发表于 2018-11-2 17:28 | 显示全部楼层
谢谢分享
回复

使用道具 举报

ID:415420 发表于 2018-11-7 19:34 | 显示全部楼层
恩,骗子一个,原理图?在哪?
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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