标题:精通break语句的看帖
取消只看楼主
w天然呆x
Rank: 1
等 级:新手上路
帖 子:30
专家分:5
注 册:2013-4-20
结帖率:66.67%
 问题点数:0 回复次数:0 
精通break语句的看帖
#include<reg52.h>
sbit P1_1=P1^1;//左
sbit P1_0=P1^0;
sbit left=P2^0;
sbit middle=P2^1;
sbit right=P2^2;
void delay_nus(unsigned int i)
{
   i=i/10;
   while(--i);
}
void delay_nms(unsigned int n)
{
  n=n+1;
  while(--n)
  delay_nus(900);
}
void initial(void)
{
  IE=0x82;
  TCON=0x00;
  TMOD=0x02;
  TH0=0x38;
  TL0=0x38;
  TR0=1;
}
void left_turn()//大转
{
    P1_1=1;
    delay_nus(1300);
    P1_1=0;
    P1_0=1;
    delay_nus(1300);
    P1_0=0;
    delay_nms(20);
}
void leftturn()//小转
{
    P1_1=1;
    delay_nus(1550);
    P1_1=0;
    P1_0=1;
    delay_nus(1300);
    P1_0=0;
    delay_nms(20);
}
void right_turn()
{
    P1_1=1;
    delay_nus(1700);
    P1_1=0;
    P1_0=1;
    delay_nus(1700);
    P1_0=0;
    delay_nms(20);
}
void rightturn()
{
    P1_1=1;
    delay_nus(1700);
    P1_1=0;
    P1_0=1;
    delay_nus(1450);
    P1_0=0;
    delay_nms(20);
}
void forward()
{
    P1_1=1;
    delay_nus(1700);
    P1_1=0;
    P1_0=1;
    delay_nus(1300);
    P1_0=0;
    delay_nms(20);
}
void backward()
{
    P1_1=1;
    delay_nus(1300);
    P1_1=0;
    P1_0=1;
    delay_nus(1700);
    P1_0=0;
    delay_nms(20);
}

int main()
{
    initial();
    while(1)
    {
        switch(P2&0x07)
        {
        case 0:
        
            do
            {
            backward();
            left_turn();//打转}
            while(P2&0x07==0)
                    
             break;
        case 1:
            
                do                    
            left_turn();
            while(!P2&0x02)
            break;
        
        case 2:
            
                do
            forward();
            while(P2&0x02)
        
             break;
        case 3:
        
                do
            leftturn();
            while(P2&0X01)
              break;
                    
        case 4:
            do
            right_turn();
            while(!P2&0x02)
              break;
        case 5:
                do
            {
            backward();
            left_turn();//打转}
            while(P2&0x07==0)
            break;
           
        case 6:
   
                do
            rightturn();
            while(P2&0x02)
              break;
        case 7:
   
                do
            forward();
            while(!P2&0x02)
            break;
      }
   }
}
//报错如下:
 #include<reg52.h>
sbit P1_1=P1^1;//左
sbit P1_0=P1^0;
sbit left=P2^0;
sbit middle=P2^1;
sbit right=P2^2;
void delay_nus(unsigned int i)
{
   i=i/10;
   while(--i);
}
void delay_nms(unsigned int n)
{
  n=n+1;
  while(--n)
  delay_nus(900);
}
void initial(void)
{
  IE=0x82;
  TCON=0x00;
  TMOD=0x02;
  TH0=0x38;
  TL0=0x38;
  TR0=1;
}
void left_turn()//大转
{
    P1_1=1;
    delay_nus(1300);
    P1_1=0;
    P1_0=1;
    delay_nus(1300);
    P1_0=0;
    delay_nms(20);
}
void leftturn()//小转
{
    P1_1=1;
    delay_nus(1550);
    P1_1=0;
    P1_0=1;
    delay_nus(1300);
    P1_0=0;
    delay_nms(20);
}
void right_turn()
{
    P1_1=1;
    delay_nus(1700);
    P1_1=0;
    P1_0=1;
    delay_nus(1700);
    P1_0=0;
    delay_nms(20);
}
void rightturn()
{
    P1_1=1;
    delay_nus(1700);
    P1_1=0;
    P1_0=1;
    delay_nus(1450);
    P1_0=0;
    delay_nms(20);
}
void forward()
{
    P1_1=1;
    delay_nus(1700);
    P1_1=0;
    P1_0=1;
    delay_nus(1300);
    P1_0=0;
    delay_nms(20);
}
void backward()
{
    P1_1=1;
    delay_nus(1300);
    P1_1=0;
    P1_0=1;
    delay_nus(1700);
    P1_0=0;
    delay_nms(20);
}

int main()
{
    initial();
    while(1)
    {
        switch(P2&0x07)
        {
        case 0:
        
            do
            {
            backward();
            left_turn();//打转}
            while(P2&0x07==0)
                    
             break;
        case 1:
            
                do                    
            left_turn();
            while(!P2&0x02)
            break;
        
        case 2:
            
                do
            forward();
            while(P2&0x02)
        
             break;
        case 3:
        
                do
            leftturn();
            while(P2&0X01)
              break;
                    
        case 4:
            do
            right_turn();
            while(!P2&0x02)
              break;
        case 5:
                do
            {
            backward();
            left_turn();//打转}
            while(P2&0x07==0)
            break;
           
        case 6:
   
                do
            rightturn();
            while(P2&0x02)
              break;
        case 7:
   
                do
            forward();
            while(!P2&0x02)
            break;
      }
   }
}
// #include<reg52.h>
sbit P1_1=P1^1;//左
sbit P1_0=P1^0;
sbit left=P2^0;
sbit middle=P2^1;
sbit right=P2^2;
void delay_nus(unsigned int i)
{
   i=i/10;
   while(--i);
}
void delay_nms(unsigned int n)
{
  n=n+1;
  while(--n)
  delay_nus(900);
}
void initial(void)
{
  IE=0x82;
  TCON=0x00;
  TMOD=0x02;
  TH0=0x38;
  TL0=0x38;
  TR0=1;
}
void left_turn()//大转
{
    P1_1=1;
    delay_nus(1300);
    P1_1=0;
    P1_0=1;
    delay_nus(1300);
    P1_0=0;
    delay_nms(20);
}
void leftturn()//小转
{
    P1_1=1;
    delay_nus(1550);
    P1_1=0;
    P1_0=1;
    delay_nus(1300);
    P1_0=0;
    delay_nms(20);
}
void right_turn()
{
    P1_1=1;
    delay_nus(1700);
    P1_1=0;
    P1_0=1;
    delay_nus(1700);
    P1_0=0;
    delay_nms(20);
}
void rightturn()
{
    P1_1=1;
    delay_nus(1700);
    P1_1=0;
    P1_0=1;
    delay_nus(1450);
    P1_0=0;
    delay_nms(20);
}
void forward()
{
    P1_1=1;
    delay_nus(1700);
    P1_1=0;
    P1_0=1;
    delay_nus(1300);
    P1_0=0;
    delay_nms(20);
}
void backward()
{
    P1_1=1;
    delay_nus(1300);
    P1_1=0;
    P1_0=1;
    delay_nus(1700);
    P1_0=0;
    delay_nms(20);
}

int main()
{
    initial();
    while(1)
    {
        switch(P2&0x07)
        {
        case 0:
        
            do
            {
            backward();
            left_turn();//打转}
            while(P2&0x07==0)
                    
             break;
        case 1:
            
                do                    
            left_turn();
            while(!P2&0x02)
            break;
        
        case 2:
            
                do
            forward();
            while(P2&0x02)
        
             break;
        case 3:
        
                do
            leftturn();
            while(P2&0X01)
              break;
                    
        case 4:
            do
            right_turn();
            while(!P2&0x02)
              break;
        case 5:
                do
            {
            backward();
            left_turn();//打转}
            while(P2&0x07==0)
            break;
           
        case 6:
   
                do
            rightturn();
            while(P2&0x02)
              break;
        case 7:
   
                do
            forward();
            while(!P2&0x02)
            break;
      }
   }
}
// #include<reg52.h>
sbit P1_1=P1^1;//左
sbit P1_0=P1^0;
sbit left=P2^0;
sbit middle=P2^1;
sbit right=P2^2;
void delay_nus(unsigned int i)
{
   i=i/10;
   while(--i);
}
void delay_nms(unsigned int n)
{
  n=n+1;
  while(--n)
  delay_nus(900);
}
void initial(void)
{
  IE=0x82;
  TCON=0x00;
  TMOD=0x02;
  TH0=0x38;
  TL0=0x38;
  TR0=1;
}
void left_turn()//大转
{
    P1_1=1;
    delay_nus(1300);
    P1_1=0;
    P1_0=1;
    delay_nus(1300);
    P1_0=0;
    delay_nms(20);
}
void leftturn()//小转
{
    P1_1=1;
    delay_nus(1550);
    P1_1=0;
    P1_0=1;
    delay_nus(1300);
    P1_0=0;
    delay_nms(20);
}
void right_turn()
{
    P1_1=1;
    delay_nus(1700);
    P1_1=0;
    P1_0=1;
    delay_nus(1700);
    P1_0=0;
    delay_nms(20);
}
void rightturn()
{
    P1_1=1;
    delay_nus(1700);
    P1_1=0;
    P1_0=1;
    delay_nus(1450);
    P1_0=0;
    delay_nms(20);
}
void forward()
{
    P1_1=1;
    delay_nus(1700);
    P1_1=0;
    P1_0=1;
    delay_nus(1300);
    P1_0=0;
    delay_nms(20);
}
void backward()
{
    P1_1=1;
    delay_nus(1300);
    P1_1=0;
    P1_0=1;
    delay_nus(1700);
    P1_0=0;
    delay_nms(20);
}

int main()
{
    initial();
    while(1)
    {
        switch(P2&0x07)
        {
        case 0:
        
            do
            {
            backward();
            left_turn();//打转}
            while(P2&0x07==0)
                    
             break;
        case 1:
            
                do                    
            left_turn();
            while(!P2&0x02)
            break;
        
        case 2:
            
                do
            forward();
            while(P2&0x02)
        
             break;
        case 3:
        
                do
            leftturn();
            while(P2&0X01)
              break;
                    
        case 4:
            do
            right_turn();
            while(!P2&0x02)
              break;
        case 5:
                do
            {
            backward();
            left_turn();//打转}
            while(P2&0x07==0)
            break;
           
        case 6:
   
                do
            rightturn();
            while(P2&0x02)
              break;
        case 7:
   
                do
            forward();
            while(!P2&0x02)
            break;
      }
   }
}
//********************************************************************************
 #include<reg52.h>
sbit P1_1=P1^1;//左
sbit P1_0=P1^0;
sbit left=P2^0;
sbit middle=P2^1;
sbit right=P2^2;
void delay_nus(unsigned int i)
{
   i=i/10;
   while(--i);
}
void delay_nms(unsigned int n)
{
  n=n+1;
  while(--n)
  delay_nus(900);
}
void initial(void)
{
  IE=0x82;
  TCON=0x00;
  TMOD=0x02;
  TH0=0x38;
  TL0=0x38;
  TR0=1;
}
void left_turn()//大转
{
    P1_1=1;
    delay_nus(1300);
    P1_1=0;
    P1_0=1;
    delay_nus(1300);
    P1_0=0;
    delay_nms(20);
}
void leftturn()//小转
{
    P1_1=1;
    delay_nus(1550);
    P1_1=0;
    P1_0=1;
    delay_nus(1300);
    P1_0=0;
    delay_nms(20);
}
void right_turn()
{
    P1_1=1;
    delay_nus(1700);
    P1_1=0;
    P1_0=1;
    delay_nus(1700);
    P1_0=0;
    delay_nms(20);
}
void rightturn()
{
    P1_1=1;
    delay_nus(1700);
    P1_1=0;
    P1_0=1;
    delay_nus(1450);
    P1_0=0;
    delay_nms(20);
}
void forward()
{
    P1_1=1;
    delay_nus(1700);
    P1_1=0;
    P1_0=1;
    delay_nus(1300);
    P1_0=0;
    delay_nms(20);
}
void backward()
{
    P1_1=1;
    delay_nus(1300);
    P1_1=0;
    P1_0=1;
    delay_nus(1700);
    P1_0=0;
    delay_nms(20);
}

int main()
{
    initial();
    while(1)
    {
        switch(P2&0x07)
        {
        case 0:
        
            do
            {
            backward();
            left_turn();//打转}
            while(P2&0x07==0)
                    
             break;
        case 1:
            
                do                    
            left_turn();
            while(!P2&0x02)
            break;
        
        case 2:
            
                do
            forward();
            while(P2&0x02)
        
             break;
        case 3:
        
                do
            leftturn();
            while(P2&0X01)
              break;
                    
        case 4:
            do
            right_turn();
            while(!P2&0x02)
              break;
        case 5:
                do
            {
            backward();
            left_turn();//打转}
            while(P2&0x07==0)
            break;
           
        case 6:
   
                do
            rightturn();
            while(P2&0x02)
              break;
        case 7:
   
                do
            forward();
            while(!P2&0x02)
            break;
      }
   }
}























搜索更多相关主题的帖子: initial include void middle 
2013-05-29 15:21



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-412505-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.045173 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved