| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 579 人关注过本帖
标题:精通break语句的看帖
只看楼主 加入收藏
w天然呆x
Rank: 1
等 级:新手上路
帖 子:30
专家分:5
注 册:2013-4-20
结帖率:66.67%
收藏
 问题点数:0 回复次数:3 
精通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
peach5460
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:武汉
等 级:贵宾
威 望:30
帖 子:2780
专家分:6060
注 册:2008-1-28
收藏
得分:0 

我总觉得授人以鱼不如授人以渔...
可是总有些SB叫嚣着:要么给代码给答案,要么滚蛋...
虽然我知道不要跟SB一般见识,但是我真的没修炼到宠辱不惊...
2013-05-29 17:08
ydown
Rank: 2
等 级:论坛游民
帖 子:31
专家分:92
注 册:2013-5-27
收藏
得分:0 
单片机控制马达啊!
2013-05-29 17:56
ydown
Rank: 2
等 级:论坛游民
帖 子:31
专家分:92
注 册:2013-5-27
收藏
得分:0 
2013-05-29 20:49
快速回复:精通break语句的看帖
数据加载中...
 
   



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

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