LED流星雨C51程序
#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;
}
LED流星雨C51程 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)