题目要求:
控制LED点阵依次滚动显示出I LOVE YOU,并且滚动速度可控。
C语言程序代码:
# include
# define uint unsigned int
# define uchar unsigned char
char code led[]={
0x0,0x3E,0x8,0x8,0x8,0x8,0x3E,0x0,
0x0,0x20,0x20,0x20,0x20,0x20,0x3C,0x0,
0x0,0x38,0x44,0x44,0x44,0x44,0x38,0x0,
0x4,0x2,0x62,0x22,0x24,0x28,0x10,0x0,
0x3C,0x20,0x20,0x3C,0x20,0x20,0x3C,0x0,
0x0,0x44,0x28,0x10,0x10,0x10,0x10,0x10,
0x0,0x38,0x44,0x44,0x44,0x44,0x38,0x0,
0x0,0x24,0x24,0x24,0x24,0x24,0x24,0x18
};
void delay(uint a)
{
uint x,y;
for(x=0;x<a;x++)
for(y=0;y<110;y++);
}
void main()
{
uint i,j,k=0,w=0x01;
while(1)
{
for(j=10;j>0;j--)//控制滚动速度
{
w=0x01;
for(i=0;i<8;i++)
{
P2=w;
P3=~led[k+i];
delay(3);
w<<=1;
}
}
k++;
if(k==56)
{
k=0;
}
}
}