這個就是把 先奇數(shù)亮再偶數(shù)亮,循環(huán)三次;一個燈上下循環(huán)三次;兩個分別從兩邊往中間流動三次;再從中間往兩邊流動三次;不過這個程序?qū)崿F(xiàn)的 應(yīng)該是這樣的 先奇數(shù)亮再偶數(shù)亮,循環(huán)三次;一個燈上下循環(huán)三次;兩個分別從兩邊往中間流動;再從中間往兩邊流動;
#include< reg52.h>
#include< intrins.h>
#define uint unsigned int
#define uchar unsigned char
void delay();
void main()
{ uchar temp,temp1,temp2,a,b;
P3=0xff;
while(1)
{ for(b=3;b>0;b--)
{ temp=0xaa;
P1=temp;
delay();
temp=0x55;
P1=temp;
delay();
}
for(a=3;a>0;a--)
{ temp=0xfe;
for(b=7;b>0;b--)
{ P1=temp;
temp=_crol_(temp,1);
delay();
P1=temp;
delay();
}
}
temp1=0xfe;
temp2=0x7f;
for(a=8;a>0;a--)
{
temp=temp1&temp2;
P1=temp;
delay();
temp1=_crol_(temp1,1);
temp2=_cror_(temp2,1);
}
}
}
void delay()
{ uint a,b;
for(a=100;a>0;a--)
for(b=600;b>0;b--);
}
程序?qū)崿F(xiàn)的第2種方法:下面是http://www.torrancerestoration.com單片機12群里的朋友木信大俠提出的,實現(xiàn)單片機led流水燈從中間向兩邊,從兩邊向中間的效果,下面的程序就是實現(xiàn)思路,這個是直接調(diào)用,應(yīng)該明白吧,數(shù)組那其實也可以改一下,如采用一維數(shù)組,在多次調(diào)用;也可以采用二維數(shù)組。主要看個人喜好.
-----------------------------------------------------
#include< reg52.h>
unsigned char code TABLE[]={
0xFF,0xE7,0xC3,0x81,0x00, //從中間向兩側(cè)點亮
0xFF,0xE7,0xC3,0x81,0x00,
0xFF,0xE7,0xC3,0x81,0x00,
0xFF,0x7E,0x3C,0x18,0x00, //從兩側(cè)向中間點亮
0xFF,0x7E,0x3C,0x18,0x00,
0xFF,0x7E,0x3C,0x18,0x00
};
unsigned char i;
DELAY()
{
unsigned int s;
for(s=0;s<30000;s++);
}
main()
{
while(1)
{
if(TABLE[i]!=0x01)
{
P1=TABLE[i];
i++;
DELAY();
}
else
{
i=0;
}
}
}