標題:
單片機心形流水燈
[打印本頁]
作者:
天佑白眉雪
時間:
2024-5-5 22:11
標題:
單片機心形流水燈
通過本站學習單片機有一段時間了,按照自己的理解,做了個心形流水燈,寫了個花樣流水的程序。嗯,有三四個花樣吧,感覺程序有點繁瑣,還有每個花樣流水燈循環(huán)次數怎么控制,流星燈,呼吸燈程序怎么寫等好多問題,目前本人的水平就這樣了,發(fā)出來和剛學單片機的朋友交流交流寫出更多的花樣來,更好的程序。有路過的大神們也給指點指點,在此先謝過。
#include <REGX51.H>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
void delayms(uint);
void liushui0();
void liushui1();
void liushui2();
void liushui3();
void liushui4();
uchar aa;
uchar bb;
uchar i;
void main()
{
while(1)
{aa=0xfe;
bb=0x7f;
liushui0();
P0=0xff;
delayms(500);
liushui1();
P0=0xff;
P1=0xff;
P2=0xff;
P3=0xff;
delayms(1500);
liushui2();
liushui3();
liushui4();
delayms(500);
}
}
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void liushui0()
{
for(i=0;i<8;i++)
{
P0=aa;
delayms(500);
aa=_crol_(aa,1);
P0=0xff;
}
for(i=0;i<8;i++)
{
P1=aa;
delayms(500);
aa=_crol_(aa,1);
P1=0xff;
}
for(i=0;i<8;i++)
{
P2=aa;
delayms(500);
aa=_crol_(aa,1);
P2=0xff;
}
for(i=0;i<8;i++)
{
P3=aa;
delayms(500);
aa=_crol_(aa,1);
P3=0xff;
}
for(i=0;i<8;i++)
{
P3=bb;
delayms(500);
bb=_cror_(bb,1);
P3=0xff;
}
for(i=0;i<8;i++)
{
P2=bb;
delayms(500);
bb=_cror_(bb,1);
P2=0xff;
}
for(i=0;i<8;i++)
{
P1=bb;
delayms(500);
bb=_cror_(bb,1);
P1=0xff;
}
for(i=0;i<8;i++)
{
P0=bb;
delayms(500);
bb=_cror_(bb,1);
P0=0xff;
}
}
void liushui1()
{
for(i=0;i<8;i++)
{P0=aa;
P1=P0;
P2=P0;
P3=P0;
delayms(500);
aa=_crol_(aa,1);
}
for(i=0;i<8;i++)
{
P0=aa;
P1=P0;
P2=P0;
P3=P0;
delayms(500);
aa=_cror_(aa,1);
P0=0xff;
P1=0xff;
P2=0xff;
P3=0xff;
}
}
void liushui2()
{
P0=0xfe;
P3=0x7f;
delayms(500);
P0=0xfc;
P3=0x3f;
delayms(500);
P0=0xf8;
P3=0x1f;
delayms(500);
P0=0xf0;
P3=0x0f;
delayms(500);
P0=0xe0;
P3=0x07;
delayms(500);
P0=0xc0;
P3=0x03;
delayms(500);
P0=0x80;
P3=0x01;
delayms(500);
P0=0x00;
P3=0x00;
delayms(500);
P1=0xfe;
P2=0x7f;
delayms(500);
P1=0xfc;
P2=0x3f;
delayms(500);
P1=0xf8;
P2=0x1f;
delayms(500);
P1=0xf0;
P2=0x0f;
delayms(500);
P1=0xe0;
P2=0x07;
delayms(500);
P1=0xc0;
P2=0x03;
delayms(500);
P1=0x80;
P2=0x01;
delayms(500);
P1=0x00;
P2=0x00;
delayms(500);
P1=0x00;
P2=0x00;
delayms(500);
P1=0x80;
P2=0x01;
delayms(500);
P1=0xc0;
P2=0x03;
delayms(500);
P1=0xe0;
P2=0x07;
delayms(500);
P1=0xf0;
P2=0x0f;
delayms(500);
P1=0xf8;
P2=0x1f;
delayms(500);
P1=0xfc;
P2=0x3f;
delayms(500);
P1=0xfe;
P2=0x7f;
delayms(500);
P1=0xff;
P2=0xff;
delayms(400);
P0=0x00;
P3=0x00;
delayms(500);
P0=0x80;
P3=0x01;
delayms(500);
P0=0xc0;
P3=0x03;
delayms(500);
P0=0xe0;
P3=0x07;
delayms(500);
P0=0xf0;
P3=0x0f;
delayms(500);
P0=0xf8;
P3=0x1f;
delayms(500);
P0=0xfc;
P3=0x3f;
delayms(500);
P0=0xfe;
P3=0x7f;
delayms(500);
P0=0xff;
P3=0xff;
delayms(500);
}
void liushui3()
{
P3=0x7f;
delayms(500);
P3=0x3f;
delayms(500);
P3=0x1f;
delayms(500);
P3=0x0f;
delayms(500);
P3=0x07;
delayms(500);
P3=0x03;
delayms(500);
P3=0x01;
delayms(500);
P3=0x00;
delayms(500);
P2=0x7f;
delayms(500);
P2=0x3f;
delayms(500);
P2=0x1f;
delayms(500);
P2=0x0f;
delayms(500);
P2=0x07;
delayms(500);
P2=0x03;
delayms(500);
P2=0x01;
delayms(500);
P2=0x00;
delayms(500);
P1=0x7f;
delayms(500);
P1=0x3f;
delayms(500);
P1=0x1f;
delayms(500);
P1=0x0f;
delayms(500);
P1=0x07;
delayms(500);
P1=0x03;
delayms(500);
P1=0x01;
delayms(500);
P1=0x00;
delayms(500);
P0=0x7f;
delayms(500);
P0=0x3f;
delayms(500);
P0=0x1f;
delayms(500);
P0=0x0f;
delayms(500);
P0=0x07;
delayms(500);
P0=0x03;
delayms(500);
P0=0x01;
delayms(500);
P0=0x00;
delayms(500);
P0=0x00;
delayms(500);
P0=0x01;
delayms(500);
P0=0x03;
delayms(500);
P0=0x07;
delayms(500);
P0=0x0f;
delayms(500);
P0=0x1f;
delayms(500);
P0=0x3f;
delayms(500);
P0=0x7f;
delayms(500);
P0=0xff;
delayms(500);
P1=0x00;
delayms(500);
P1=0x01;
delayms(500);
P1=0x03;
delayms(500);
P1=0x07;
delayms(500);
P1=0x0f;
delayms(500);
P1=0x1f;
delayms(500);
P1=0x3f;
delayms(500);
P1=0x7f;
delayms(500);
P1=0xff;
delayms(500);
P2=0x00;
delayms(500);
P2=0x01;
delayms(500);
P2=0x03;
delayms(500);
P2=0x07;
delayms(500);
P2=0x0f;
delayms(500);
P2=0x1f;
delayms(500);
P2=0x3f;
delayms(500);
P2=0x7f;
delayms(500);
P2=0xff;
delayms(500);
P3=0x00;
delayms(500);
P3=0x01;
delayms(500);
P3=0x03;
delayms(500);
P3=0x07;
delayms(500);
P3=0x0f;
delayms(500);
P3=0x1f;
delayms(500);
P3=0x3f;
delayms(500);
P3=0x7f;
delayms(500);
P3=0xff;
delayms(500);
}
void liushui4()
{
P0=0x00;
P1=0x00;
P2=0x00;
P3=0x00;
delayms(500);
P0=0x00;
P1=0x00;
P2=0x00;
P3=0x00;
delayms(500);
P0=0xff;
P1=0xff;
P2=0xff;
P3=0xff;
delayms(500);
P0=0xff;
P1=0xff;
P2=0xff;
P3=0xff;
delayms(500);
}
復制代碼
作者:
天佑白眉雪
時間:
2024-5-5 22:13
圖片不會發(fā)啊,成了這樣了
作者:
白水大蝦2016
時間:
2024-5-10 21:56
這個程序太好了,全部I/O 口都有賦能,如果移植到32上做個立體LED(如小蠻腰)一定非常好看!
作者:
白水大蝦2016
時間:
2024-5-20 16:27
這個程序真的太好了,全部I/O 口都有賦能,還有一些花樣。如果將每一項花樣由慢到快直到瞎眼就更好了!我將這個程序寫進了STC11并用洞洞板焊接了一塊多用板(可以看到51系列工作狀態(tài)和擴展應用),實際就是每個I/O口有兩個針孔用起來非常方便。實乃不才程序移植不到32系統(tǒng)中。
作者:
天佑白眉雪
時間:
2024-5-23 21:58
白水大蝦2016 發(fā)表于 2024-5-20 16:27
這個程序真的太好了,全部I/O 口都有賦能,還有一些花樣。如果將每一項花樣由慢到快直到瞎眼就更好了!我將 ...
想法不錯努力學習中
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1