標(biāo)題:
愛心燈程序加仿真
[打印本頁]
作者:
esllca
時間:
2017-8-2 11:23
標(biāo)題:
愛心燈程序加仿真
0.png
(27.58 KB, 下載次數(shù): 59)
下載附件
2017-8-2 17:05 上傳
單片機愛心燈源程序如下:
#include<reg52.h> //頭文件
#include <intrins.h>
#define uint unsigned int //宏定義
#define uchar unsigned char
void delay(uint k) //延時,大約1ms
{
uint i,j;
for(i=k;i--;i>0)
for(j=100;j--;j>0);
}
/***********這個設(shè)計的LED是正極接電源,負(fù)極接單片機的IO口,
當(dāng)單片機IO口輸出低電平時,LED就會點亮***********/
void main() //主函數(shù)
{
uchar temp0,temp1; //定義變量用于LED的閃爍
uchar yi;
uchar yi0,yi1;
uint i,j,k,a,b;
j=k=a=b=3;
//全部亮
P0=P1=P2=P3=0x00;
delay(700);
P0=P1=P2=P3=0xff;
//每個io口獨自亮
for(i=2;i--;i>0)
{
P1=P0=0x00;
delay(500);
P1=P0=0xff;
P3=P2=0x00;
delay(500);
P3=P2=0xff;
}
//全部亮,閃三次
for(i=2;i--;i>0)
{
P0=P1=P2=P3=0x00;
delay(100);
P0=P1=P2=P3=0xff;
delay(100);
}
//P1、P2亮,P3、P0暗
for(i=3;i--;i>0)
{
P1=0x00,P2=0x00; P3=0xff,P0=0xff;
delay(500);
P1=0xff,P2=0xff,P3=0x00,P0=0x00;
delay(500);
}
//四個點的流水
while(j>0)
{
temp0=0xfe,temp1=0x7f;
P1=P3=temp0,P2=P0=temp1;
delay(100);
for(i=7;i--;i>0)
{
temp0=_crol_(temp0,1),temp1=_cror_(temp1,1);
P1=P3=temp0,P2=P0=temp1;
delay(100);
}
j--;
}
//全部亮,閃三次
for(i=3;i--;i>0)
{
P0=P1=P2=P3=0x00;
delay(300);
P0=P1=P2=P3=0xff;
delay(300);
}
//四個IO口同樣跟蹤流水
while(k>0)
{
temp0=0xfe,temp1=0x7f;
P1=P3=temp0,P2=P0=temp1;
delay(60);
for(i=7;i--;i>0)
{
temp0=temp0<<1,temp1=temp1>>1;
P1=P3=temp0,P2=P0=temp1;
delay(60);
}
k--;
}
P0=P1=P3=P2=0xff;
while(k<3)
{
temp0=0x7f,temp1=0xfe;
P1=P3=temp0,P2=P0=temp1;
delay(60);
for(i=7;i--;i>0)
{
temp0=temp0>>1,temp1=temp1<<1;
P1=P3=temp0,P2=P0=temp1;
delay(60);
}
k++;
}
P3=P2=0xff;
//兩邊單個從上向下流水
yi=0xfe;
P1=P0=yi;
delay(50);
for(i=7;i--;i>0)
{
yi=_crol_(yi,1);
P1=P0=yi;
delay(50);
}
P1=P0=0xff;
yi=0xfe;
P3=P2=yi;
delay(50);
for(i=7;i--;i>0)
{
yi=_crol_(yi,1);
P3=P2=yi;
delay(50);
}
P3=P2=0Xff;
//兩邊單個返回流水
for(i=7;i--;i>0)
{
yi=_cror_(yi,1);
P3=P2=yi;
delay(50);
}
P3=P2=0xff;
for(i=7;i--;i>0)
{
yi=_cror_(yi,1);
P0=P1=yi;
delay(50);
}
//全部亮,閃三次
P0=P1=P3=P2=0xff;
for(i=3;i--;i>0)
{
P0=P1=P2=P3=0x00;
delay(100);
P0=P1=P2=P3=0xff;
delay(100);
}
//流水燈
yi0=0xfe,yi1=0x7f;
P3=P2=yi1,P1=P0=yi0;
delay(100);
for(i=7;i--;i>0)
{
yi0=yi0<<1, yi1=yi1>>1;
P1=P0=yi0,P3=P2=yi1;
delay(100);
}
P1=P2=P3=P0=0xff;
delay(200);
yi0=0x7f,yi1=0xfe;
P1=P0=yi0,P3=P2=yi1;
for(i=7;i--;i>0)
{
yi0=yi0>>1,yi1=yi1<<1;
P1=P0=yi0,P3=P2=yi1;
delay(100);
}
//大循環(huán)跟蹤流水
P1=P2=P3=P0=0xff;
for(i=8;i--;i>0)
{
P1=P1<<1;
delay(50);
}
for(i=8;i--;i>0)
{
P3=P3<<1;
delay(50);
}
for(i=8;i--;i>0)
{
P2=P2>>1;
delay(50);
}
for(i=8;i--;i>0)
{
P0=P0>>1;
delay(50);
}
//逆向大循環(huán)跟蹤流水
P1=P2=P3=P0=0xff;
for(i=8;i--;i>0)
{
P0=P0<<1;
delay(50);
}
for(i=8;i--;i>0)
{
P2=P2<<1;
delay(50);
}
for(i=8;i--;i>0)
{
P3=P3>>1;
delay(50);
}
for(i=8;i--;i>0)
{
P1=P1>>1;
delay(50);
}
//全部亮,閃三次
P0=P1=P3=P2=0xff;
for(i=4;i--;i>0)
{
P0=P1=P2=P3=0x00;
delay(100);
P0=P1=P2=P3=0xff;
delay(100);
}
//全部亮,只有一個暗的在流水
temp0=0x01,temp1=0x00;
P1=P0=temp0,P3=P2=temp1;
delay(100);
for(i=7;i--;i>0)
{
temp0=_crol_(temp0,1);
P1=P0=temp0;
delay(100);
}
P1=P0=0x00;
temp1=0x01;
P3=P2=temp1;
delay(100);
for(i=7;i--;i>0)
{
temp1=_crol_(temp1,1);
P3=P2=temp1;
delay(100);
}
//全部亮,逆向一個暗在流水
temp0=0x00,temp1=0x80;
P1=P0=temp0,P3=P2=temp1;
delay(100);
for(i=7;i--;i>0)
{
temp1=_cror_(temp1,1);
P3=P2=temp1;
delay(100);
}
P3=P2=0x00;
temp0=0x80;
P1=P0=temp0;
delay(100);
for(i=7;i--;i>0)
{
temp0=_cror_(temp0,1);
P1=P0=temp0;
delay(100);
}
//花樣
temp0=0xaa,temp1=0x55;
P1=P3=temp0,P2=P0=temp1;
delay(500);
for(;a--;a>0)
{
for(i=7;i--;i>0)
{
temp0=_crol_(temp0,1),temp1=_cror_(temp1,1);
P1=P3=temp0,P2=P0=temp1;
delay(500);
}
}
for(;b--;b>0)
{
temp0=0xee,temp1=0x77;
P1=P3=temp0,P2=P0=temp1;
delay(300);
for(i=7;i--;i>0)
{
temp0=_crol_(temp0,1),temp1=_cror_(temp1,1);
P1=P3=temp0,P2=P0=temp1;
delay(300);
}
}
//環(huán)形逐個亮
P1=P2=P3=P0=0xff;
for(i=8;i--;i>0)
{
P0=P0<<1;
delay(50);
}
for(i=8;i--;i>0)
{
P2=P2<<1;
delay(50);
}
for(i=8;i--;i>0)
{
P3=P3>>1;
……………………
…………限于本文篇幅 余下代碼請從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
愛心燈.rar
(72.61 KB, 下載次數(shù): 23)
2017-8-2 11:22 上傳
點擊文件名下載附件
愛心燈程序加仿真
下載積分: 黑幣 -5
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1