下面这个程序里面有你要的东西,自己找找。
#include"reg51.h"
void delay(int n);
sbit K1=P3^3; //LED左移按键
sbit K2=P3^5; //LED右移按键
sbit K3=P3^6; //开启手动按键
sbit K4=P3^7; //开启自动按键
bit mark1=0;
bit mark2=0;
unsigned char a,b,c,d;
int x;
void pulse(void);
void main()
{
a=0xfe;b=0xff;
c=0x7f;d=0xff;
while(K4)
{P2=a; P0=b;
if(!K1&!mark1) //如果K1按下且mark1=0
{delay(10); //延时
if(!K1) //检查K1还是按下
{
mark1=1; //mark1=1
if((a&0x80)&&(a!=0xff)) //如果a=1*******("*"号为0或者1(最高位为1))并且a不等于0xff
{ a=(a<<1)|0x01;pulse();} //让a向左移后边会拉出0,然后与00000001相与(最后一位补1)
else if(a==0x7f)
{a=0xff;b=0xfe;pulse();}
else if((b&0x80)&&(b!=0xff))
{b=(b<<1)|0x01;pulse();}
else if(b==0x7f)
{a=0xfe;b=0xff;pulse();}
// {a<<=1;} //a左移一位让P2^7的值跳到P2^0上
}
}
else if(K1)
{mark1=0;}
if(!K2&!mark2)
{ delay(10);
if(!K2)
{
mark2=1;
if((a!=0xff)&&(a!=0xfe))
{
if(a&0x01)
{ a=(a>>1)|0x80;pulse();}
}
else if(a==0xfe)
{a=0xff;b=0x7f;pulse();}
if((b!=0xff)&&(b!=0xfe))
{
if(b&0x01)
{ b=(b>>1)|0x80;pulse();}
}
else if(b==0xfe)
{a=0x7f;b=0xff;pulse();}
}
}
else if(K2)
mark2=0;
}
while(K3)
{
if(!K1&!mark1)
{delay(10);
if(!K1)
{mark1=1;
for(x=0;x<=16;x++)
{ P0=a;P2=b;
delay(100);
if((a&0x80)&&(a!=0xff))
{a=(a<<1)|0x01;}
else if(a==0x7f)
{a=0xff;b=0xfe;}
else if((b&0x80)&&(b!=0xff))
{b=(b<<1)|0x01;}
else if(b==0x7f)
{b=0xff;a=0xff;}
}
}
}
else if(K1)
{mark1=0;}
if(!K2&!mark2)
{delay(10);
if(!K2)
{mark2=1;
for(x=0;x<=16;x++)
{P0=c;P2=d;
delay(100);
if((c&0x01)&&(c!=0xff))
{c=(c>>1)|0x80;}
else if(c==0xfe)
{c=0xff;d=0x7f;}
else if((d&0x01)&&(d!=0xff))
{d=(d>>1)|0x80;}
else if(d==0xfe)
{d=0xff;c=0xff;}
}
}
}
else if(K2)
{mark2=0;}
}
}
void delay(int n)
{
int i,j;
for(i=0;i<=n;i++)
for(j=0;j<=320;j++);
}
void pulse(void)
{
P1=0xfe;
delay(100);
P1=0xfd;
delay(100);
P1=0xfb;
delay(100);
P1=0xf7;
delay(100);
P1=0xff;
}
51单片机怎么用一个按键控制P0,P2顺序输出高电平
这个问题我知道
推荐您使用“赛思QQ陌生人推广小助手 ”
不用加好友 直接发消息
日引1万独立IP 绝对没有问题
C还是汇编?