找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 8860|回復: 5
收起左側

while循環(huán)中的語句只運行了一次后停止,死循環(huán)為什么會這樣?

[復制鏈接]
ID:65770 發(fā)表于 2014-10-21 23:47 | 顯示全部樓層 |閱讀模式
#include<reg51.h>
sbit ceng1=P2^0;
sbit ceng2=P2^1;
sbit ceng3=P2^2;
sbit ceng4=P2^3;
sbit p10=P1^0;
sbit p11=P1^1;
sbit p12=P1^2;
sbit p13=P1^3;
sbit p14=P1^4;
sbit p15=P1^5;
sbit p16=P1^6;
sbit p17=P1^7;
sbit p30=P3^0;
sbit p31=P3^1;
sbit p32=P3^2;
sbit p33=P3^3;
sbit p34=P3^4;
sbit p35=P3^5;
sbit p36=P3^6;
sbit p37=P3^7;

void delay(unsigned char i);
void main()
{  

  
  P1=0x00;
  P3=0x00;
   
   
  ceng1=1;
  ceng2=1;
  ceng3=1;
  ceng4=0;
   
   while(1)
   {
   p34=1;
    delay(2);
     p35=1;
    delay(2);
    p36=1;
    delay(2);
     p37=1;
    delay(2);
    p33=1;
    delay(2);
     p17=1;
    delay(2);
    p13=1;
    delay(2);
    p12=1;
    delay(2);
    p11=1;
    delay(2);
     p10=1;
    delay(2);
    p14=1;
    delay(2);
     p30=1;
    delay(2);
    p34=1;
    delay(2);
   

     //第一層運行完
    ceng1=1;
  ceng2=1;
  ceng3=0;
  ceng4=0;
   
   p34=1;
    delay(2);
     p35=1;
    delay(2);
    p36=1;
    delay(2);
     p37=1;
    delay(2);
    p33=1;
    delay(2);
     p17=1;
    delay(2);
    p13=1;
    delay(2);
    p12=1;
    delay(2);
    p11=1;
    delay(2);
     p10=1;
    delay(2);
    p14=1;
    delay(2);
     p30=1;
    delay(2);
    p34=1;
    delay(2);
   

   
     }

   
   }
void delay(unsigned char i)
{
unsigned int i1,a;
for(i1=i;i1>0;i1--)
{         
  for(a=5000;a>0;a--);
}
}

回復

使用道具 舉報

ID:51348 發(fā)表于 2014-10-22 12:02 | 顯示全部樓層
你的第一層是不是要把
//第一層運行完
    ceng1=1;
  ceng2=1;
  ceng3=0;
  ceng4=0;
這段也包括經去呀
回復

使用道具 舉報

ID:51348 發(fā)表于 2014-10-22 12:03 | 顯示全部樓層
T29 發(fā)表于 2014-10-22 12:02
你的第一層是不是要把
//第一層運行完
    ceng1=1;

錯了,是
ceng1=1;
  ceng2=1;
  ceng3=1;
  ceng4=0;
這段
回復

使用道具 舉報

ID:2318 發(fā)表于 2014-10-22 12:38 來自觸屏版 | 顯示全部樓層
歷害,又學習了,mark一下
回復

使用道具 舉報

ID:66501 發(fā)表于 2014-10-24 14:04 | 顯示全部樓層
掘墓高手,專挖古墓,一挖一個坑,坑坑見墓。。
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表