#include <reg51.h>
#include <string.h>
#define uchar unsigned char
#define uint unsigned int
//uchar code fasong[]="abcd";//h1 h2 d1 d2
uchar count,flag,g,h,k,l,i,x;
sbit a=P2^3;//h1
sbit b=P2^2;//h2
sbit c=P2^1;//d1
sbit d=P2^0;//d2
sbit led0=P0^0;//ºìÂ̵Æ1
sbit led1=P0^1;//ºìÂ̵Æ2
sbit led2=P0^2;//µÀÕ¢1¿ª
sbit led3=P0^3;//µÀÕ¢1¹Ø
sbit led4=P0^4;//µÀÕ¢2¿ª
sbit led5=P0^5;//µÀÕ¢2¹Ø
sbit e=P1^3;
void init()
{
TMOD=0x20;
SCON=0x50;
TH1=0xfd;
TL1=0xfd;
TR1=1;
EA=1;
ES=1;
}
void delaya()
{
unsigned char i;
for(i=0;i<0x14;i++)
{
TH1=0x3c;
TL1=0xb0;
TR1=1;
while(!TF1);
TF1=0;
}
}
void zijian()
{
unsigned char i,w;
TMOD=0x10;
while(1)
{
if(e==0)
{
w=0x01;
for(i=0;i<8;i++)
{
P0=w;
w<<=1;
delaya();
P0=0x00;
delaya();
while(e==1)
{
P0=0x00;
w=0x01;
i=8;
}
}
}
}
}
void main()
{
init();
TMOD=0x10;
P0=0x00;
delaya();
P0=0x02;
delaya();
P0=0x00;
delaya();
P0=0x08;
delaya();
P0=0x00;
delaya();
init();
while(1)
{ g=h=k=l=1;
if(x==1)
{
while(1)//youdaigaizheng
{
led2=1;
led0=1;
if(c==0)
{
while(1)
{if(a==0)
{ while(1)
{if(c==1&&a==1)
{
led2=0;
delaya();
led3=1;
delaya();
led0=0;
g=0;
}
}
}}
}
}
}
if(x==2)
{
while(h)
{
led4=1;
led1=1;
if(b==0)
{
while(1)
{if(d==0)
{ while(h)
{if((b==1)&&(d==1))
{
led4=0;
delaya();
led5=1;
delaya();
led0=0;
h=0;
}
}
}}
}
}
}
if(x==3&&flag==1)
{
ES=0;
flag=0;
// SBUF=P1&0x1f;
SBUF=P2;
while(!
ti);
TI=0;
ES=1;
// P2=~(P2&0x1f);
// P1=~(P1&0x1f);
}
if(e==0) zijian();
}
}
void ver() interrupt 4
{
RI=0;
x=SBUF;
flag=1;
}
void zijian()
{
unsigned char i,w;
TMOD=0x10;
//while(1)
//{
if(e==0)
{
w=0x01;
for(i=0;i<8;i++)
{
P0=w;
w<<=1;
delaya();
P0=0x00;
delaya();
if(e==1)
{
P0=0x00;
w=0x01;
i=8;
}
}
}
//}
怎么跳回到主函数
{
unsigned char i,w;
TMOD=0x10;
while(1)
{
if(e==0)
{
w=0x01;
for(i=0;i<8;i++)
{
P0=w;
w<<=1;
delaya();
P0=0x00;
delaya();
while(e==1)
{
P0=0x00;
w=0x01;
i=8;
}
}
}
}
}
你上面写的这个函数,程序会一直等e==1
一周热门 更多>