#include
#define uchar unsigned char
#define uint unsigned int
uchar i,j,k,n;
void program_0(); //序幕·倒数
void program_1(); //流水·基本要求
void program_2(); //流水·堆砌方块
void program_3(); //动画·沙漏
void program_4(); //动画·小车
void program_5(); //流水·扩散
void program_6(); //流水·贪吃蛇
void delay(uint x);
uchar code table0[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x42,0x81,0x89,0x89,0x76,0x00,0x00, // '3'
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0xc6,0xa1,0x91,0x89,0x86,0x00,0x00, //'2'
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x82,0xff,0x80,0x00,0x00,0x00, //'1'
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
uchar code table1_1[]={0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00, //0为真点亮 低到高
0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff}; // 灭
uchar code table1_2[]={ 0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01,0x00, //0为真点亮 高到低
0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff}; //灭
uchar code table1_3[]={0xe7,0xc3,0x81,0x00,0x81,0xc3,0xe7,0xff, //中间向两边点亮,两边向中间灭 (低电平点亮)
0x7e,0x3c,0x18,0x00,0x18,0x3c,0x7e,0xff, }; //两边向中间点亮,中间向两边灭 (低电平点亮)
uchar code table1_4[]={ 0x18,0x3c,0x7e,0xff,0x7e,0x3c,0x18,0x00, // 中间向两边点亮,两边向中间灭 (高电平点亮)
0x81,0xc3,0xe7,0xff,0xe7,0xc3,0x81,0x00,}; //两边向中间点亮,中间向两边灭 (高电平点亮)
uchar code table1_5[]={ 0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff, //1为真点亮 低到高
0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00}; //灭
uchar code table1_6[]={ 0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff, //1为真点亮 高到低
0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01,0x00}; // 灭
uchar code table1_7[]={0x7e,0xbd,0xdb,0xe7}; //两边向中间一个一个地点亮(低电平)
uchar code table2_1[]={ 0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f, //堆砌(向左)(低电平)
0x7e,0x7d,0x7b,0x77,0x6f,0x5f,0x3f,
0x3e,0x3d,0x3b,0x37,0x2f,0x1f,
0x1e,0x1d,0x1b,0x17,0x0f,
0x0e,0x0d,0x0b,0x07,
0x06,0x05,0x03,
0x02,0x01,
0x00};
uchar code table2_2[]={ 0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80, //堆砌(向下)(高电平)
0x81,0x82,0x84,0x88,0x90,0xa0,0xc0,
0xc1,0xc2,0xc4,0xc8,0xd0,0xe0,
0xe1,0xe2,0xe4,0xe8,0xf0,
0xf1,0xf2,0xf4,0xf8,
0xf9,0xfa,0xfc,
0xfd,0xfe,
0xff};
//沙漏
uchar code table_3[9][8]={ 0x81,0xC3,0xA7,0x9F,0x9F,0xA7,0xC3,0x81,
0x81,0xC3,0xA5,0xBF,0x9F,0xA7,0xC3,0x81,
0x81,0xC3,0xE5,0xBD,0x9F,0xA7,0xC3,0x81,
0x81,0xC3,0xE5,0xFD,0x9D,0xA7,0xC3,0x81,
0x81,0xC3,0xE5,0xF9,0xDD,0xA7,0xC3,0x81,
0x81,0xC3,0xE5,0xF9,0xDD,0xE5,0xC3,0x81,
0x81,0xC3,0xE5,0xF9,0xF9,0xE5,0xC3,0x81,
0xFF,0x42,0x24,0x18,0x18,0x3C,0x7E,0xFF,
0x81,0xC3,0xA7,0x9F,0x9F,0xA7,0xC3,0x81,};
uchar code table_4[18][8]={ 0x00,0x00,0x00,0x51,0x79,0x51,0x01,0x01, //小车
0x00,0x00,0x50,0x7B,0x53,0x03,0x03,0x03,
0x00,0x50,0x78,0x56,0x06,0x06,0x06,0x06,
0x50,0x78,0x50,0x0C,0x0C,0x0C,0x0C,0x0C,
0x50,0x78,0x50,0x18,0x18,0x18,0x18,0x18,
0x50,0x78,0x50,0x60,0x60,0x60,0x60,0x60,
0x01,0x51,0x78,0xD0,0x80,0x80,0x81,0x81,
0x03,0x03,0x50,0x78,0x50,0x00,0x03,0x03,
0x06,0x06,0x00,0x50,0x78,0x50,0x06,0x06,
0x0C,0x0C,0x00,0x0A,0x0F,0x0A,0x0C,0x0C,
0x60,0x60,0x00,0x28,0x3C,0x28,0x60,0x60,
0x00,0x00,0x00,0x50,0x78,0x50,0x00,0x00,
0x00,0x00,0x00,0x50,0x78,0x50,0x00,0x00,
0x01,0x01,0x01,0x0B,0x0F,0x0B,0x01,0x01,
0x01,0x01,0x01,0x07,0x07,0x07,0x01,0x01,
0x01,0x01,0x01,0x05,0x02,0x05,0x01,0x01,
0x01,0x01,0x01,0x00,0x00,0x00,0x01,0x01,
0x01,0x01,0x01,0x05,0x02,0x05,0x01,0x01, };
void main()
{
while(1)
{
program_0(); // 序幕 倒计时
program_1(); //
program_2(); // 第一章 流水·堆砌方块
program_3(); //
program_4(); // 第二章 动画
program_5(); // 第三章 流水·扩散·贪吃蛇
program_6(); //
}
}
void program_0() //倒计时
{
uchar i=0,j=0,k=0;
for(i=0;i<16;i++) //清屏(向左)
{
P0=0XFF;
P2=table1_1[i];
delay(20);}
do
{
for(i=0;i<8;i++)
{
P2=0XFF; //去重影
P0=table0[i+k]; //查表赋值
P2=~(0x80>>i); //点亮相应列
delay(1);
}
//循环周期(设定动作的速度)
if(j++==10)
{
j=0;
k++; //查表行号
}
}
while(k!=48);
}
void program_1() //流水·基本要求
{
uchar i=0,j=0,n=0;
for(i=0;i<80;i++) //循环周期·5次
{
P0=0Xff;
P2=table1_1[j];
j++;
if(j==16)j=0;
delay(80); }
for(i=0;i<80;i++) //循环周期·5次
{
P0=0Xff;
P2=table1_3[j];
j++;
if(j==16)j=0;
delay(120);}
}
void program_2() //流水·堆砌方块
{
uchar i=0,j=0;
do //跑马效果
{
for(i=0;i<16;i++)
{
P2=table1_1[i];
P0=~(0x7f>>j);
delay(50);}
j++;
}
while(j!=8);
i=0;
while(i!=36) //向左堆砌
{
P0=0xff;
P2=table2_1[i];
i++;
delay(80); }
for(n=0;n<2;n++) //闪烁·2次
{
P0=0X00;
P2=0XFF;
delay(200);
P0=0XFF;
P2=0X00;
delay(200);}
i=0;
while(i!=36) //向下堆砌
{
P0=table2_2[i];
i++;
P2=0x00;
delay(80);}
for(n=0;n<2;n++) //闪烁·2次
{
P0=0X00;
P2=0XFF;
delay(200);
P0=0XFF;
P2=0X00;
delay(200);}
for(i=0;i<36;i++) //左下方堆砌至方块满
{
P2=table2_1[i];
P0=table2_2[i];
delay(70);
}
for(n=0;n<2;n++) //闪烁·2次
{
P0=0X00;
P2=0XFF;
delay(200);
P0=0XFF;
P2=0X00;
delay(200);}
}
void program_3() //沙漏
{
uchar i=0,j=0,k=0;
while(k<9)
{
for(i=0;i<8;i++)
{
P2=0XFF;
P0=table_3[k][i];
P2=~(0x80>>i);
delay(1);}
if(j++==70)
{j=0;k++;}
}
k=1;
while(k<7)
{
for(i=0;i<8;i++)
{
P2=0XFF;
P0=table_3[k][i];
P2=~(0x80>>i);
delay(1);}
if(j++==70)
{j=0;k++;}
}
for(i=0;i<8;i++) //以点出发
{
P0=0x01<
P2=~(0x01<
delay(100);}
for(n=0;n<3;n++) //循环周期·3次
{
for(i=0;i<8;i++) //扩散
{
P2=0x7f>>i;
P0=0x80>>i;
delay(100);}
}
for(i=0;i<8;i++) //清屏(向下)
{
P0=~(0xfe<
P2=0x00;
delay(100);}
for(i=12;i<16;i++)
{
P0=0XFF;
P2=table1_3[i]; //拉开帷幕(中间向两边灭)
delay(200);}
}
void program_4() //小车·儿时经典电玩
{
uchar i=0,j=0,k=0;
while(k<18)
{
for(i=0;i<8;i++)
{
P2=0XFF;
P0=table_4[k][i];
P2=~(0X80>>i);
delay(1);
}
if(j++==30)
{j=0;k++;}
}
k=17;
while(k>0) //小车倒退
{
for(i=0;i<8;i++)
{
P2=0XFF;
P0=table_4[k][i];
P2=~(0X80>>i);
delay(1);
}
if(j++==10)
{j=0;k--;}
}
}
void program_5() //扩散效果
{
uchar i=0,j=0,k=0,n=0;
for(i=0;i<15;i++) //流水引出(向左)
{
P0=0x80;
P2=table1_1[i];
delay(50);}
for(i=1;i<15;i++) //流水引出(向上)
{
P0=table1_6[i];
P2=0x7f;
delay(50);}
for(i=1;i<15;i++) //流水引出(向右)
{
P0=0x01;
P2=table1_2[i];
delay(50);}
for(i=1;i<15;i++) //流水引出(向下)
{
P0=table1_5[i];
P2=0xfe;
delay(50);}
for(n=0;n<2;n++)
{
for(i=0;i<16;i++) // 四边形扩散(由内到外一圈一圈点亮至全亮,逆回,然后方块的四个角同时点亮扩散至全亮)
{
P2=table1_3[i];
P0=table1_4[i];
delay(150);}
}
for(i=0;i<8;i++) //十字扩散(形成十字点灭,沿对角线走)
{
P0=~(0x80>>i);
P2=0x80>>i;
delay(200);}
P0=0XFF; //关闭
P2=0X00;
delay(500);
for(i=0;i<36;i++) //扩散消逝
{
P0=table2_1[i];
P2=table2_2[i];
delay(70);
}
}
void program_6()
{
uchar i=0,j=0,k=0;
while(k<8) //堆砌·呼唤贪吃蛇
{
for(i=8;i<12;i++)
{
P2=table1_3[i];
P0=~(0x0fe<
delay(100);}
k++;
}
k=3; //贪吃蛇出发
for(i=8;i<16;i++)
{
P0=table1_5[i];
P2=table1_7[k];
delay(50);}
k--;
do //贪吃蛇上下移动
{
for(i=0;i<16;i++)
{
P0=table1_6[i];
P2=table1_7[k];
delay(50);}
k--;
for(i=0;i<16;i++)
{
P0=table1_5[i];
P2=table1_7[k];
delay(50);}
}
while(k!=1);
do
{ //贪吃蛇疯狂暴走·闭幕
for(i=0;i<16;i++)
{
P2=table1_1[i];
P0=0x80>>j;
delay(30); }
j++;
for(i=0;i<16;i++)
{
P2=table1_2[i];
P0=0x80>>j;
delay(30); }
j++;
}
while(j!=8);
for(i=0;i<8;i++) // 从右上方 行列一起点亮 (清屏)
{
P2=0xfe<
P0=~(0xfe<
delay(300);}
}
void delay(uint x)
{
uint i,j;
for(i=x;i>0;i--)
for(j=110;j>0;j--);}
|