精通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;
}
}
}