微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > LED流星雨C51程序

LED流星雨C51程序

时间:11-29 来源:互联网 点击:
P1口上接8个led灯可以实现流星雨效果,测试成功.

#include
#define uchar unsigned char
#define led P1
bit flag=0;
uchar code lshift[3]={0x07,0x03,0x01};
uchar code shift[7]={0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe};
//imitate PWM data
uchar code sta0[100]={ 0x0f,0x8f,0x8f,0x8f,0x8f,0x8f,0x8f,0x8f,0x8f,0x8f,
0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,
0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,0xcf,
0xcf,0xcf,0xcf,0xef,0xef,0xef,0xef,0xef,0xef,0xef,
0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,
0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,
0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,
0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,
0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,
0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef
};
//functions statement
void delay(uchar ms);
uchar exchg(uchar dat);
//main function
void main()
{
uchar i,j,k,x,sdata;
while(1)
{
for(k=1;k<8;k++)
for(i=0;i<22;i++)
for(j=0;j<100;j++)
{
sdata=(sta0[j]>>k)|shift[k-1];
if(flag==1) led=exchg(sdata);
else led=sdata;
}
for(x=1;x<4;x++)
for(i=0;i<22;i++)
for(j=0;j<100;j++)
{
sdata=( sta0[j]<(4-x) )|lshift[x-1];
if(flag==1) led=exchg(sdata);
else led=sdata;
}

}
}
void delay(uchar ms)
{
uchar n;
while(ms--)
{
for(n=125;n>0;n--);
}
}
uchar exchg(uchar dat) //对字节的高位和低位进行互换!
{
uchar temp;
temp=
((dat&0x01)<7)|
((dat&0x02)<5)|
((dat&0x04)<3)|
((dat&0x08)<1)|
((dat&0x10)>>1)|
((dat&0x20)>>3)|
((dat&0x40)>>5)|
((dat&0x80)>>7);
return temp;
}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top