#include "qudong.h"
#include <reg51.h>
#include <intrins.h>
#include "delay.h"
sbit DS=P2^7; //595 DATAS
sbit SHCP=P2^6; //595 CLK
sbit LATCH=P2^5; //595 STR
sbit gate=P2^4;
uchar tmp[8];
uchar cube[8][8];
uchar xdata tmpcube[8][8];
uchar line;
bit exchg_flag;
void fill_plane(uchar m,uchar dat);
void sendline();
void saomiao(uchar i);
void SendByte(unsigned char dat);
void Out595(void);
uchar exchg(uchar dat);
void exchg_x();
void exchg_y();
void exchg_z();
void tmptocube();
void exchg_jiao();
void exchg_plane();
uchar code frame[14][8]=
{
{0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01}, /*-1-*/
{0x00,0xc0,0x20,0x10,0x08,0x04,0x03,0x00}, /*-2-*/
{0x00,0x00,0xe0,0x10,0x08,0x07,0x00,0x00}, /*-3-*/
{0x00,0x00,0x00,0xf0,0x0f,0x00,0x00,0x00}, /*-4-*/
{0x00,0x00,0x00,0x0f,0xf0,0x00,0x00,0x00}, /*-5-*/
{0x00,0x00,0x07,0x08,0x10,0xe0,0x00,0x00}, /*-6-*/
{0x00,0x03,0x04,0x08,0x10,0x20,0xc0,0x00}, /*-7-*/
{0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}, /*-8-*/
{0x02,0x02,0x04,0x08,0x10,0x20,0x40,0x40}, /*-9-*/
{0x04,0x04,0x04,0x08,0x10,0x20,0x20,0x20}, /*-10-*/
{0x08,0x08,0x08,0x08,0x10,0x10,0x10,0x10}, /*-11-*/
{0x10,0x10,0x10,0x10,0x08,0x08,0x08,0x08}, /*-12-*/
{0x20,0x20,0x20,0x10,0x08,0x04,0x04,0x04}, /*-13-*/
{0x40,0x40,0x20,0x10,0x08,0x04,0x02,0x02}, /*-14-*/
};
void all_z(bit state)
{
uchar i,j;
for(i=0;i<8;i++)
{
if(state) fill(0xff);
else fill(0x00);
for(j=0;j<=i;j++)
{
if(state) fill_plane(j,0x00);
else fill_plane(j,0xff);
}
saomiao(15);
}
}
void plane(bit state,bit mode)
{
uchar i,m,n;
for(i=0;i<56;i++)
{
for(m=0;m<8;m++)
{
for(n=0;n<8;n++)
{
if(state==0) cube[m][n]=frame[i%14][n];
else cube[m][n]=frame[(i+m)%14][n];
}
}
if(mode)
{
exchg_plane();
tmptocube();
}
saomiao(5);
}
fill(0x00);
}
void jiao_plane(bit state)
{
uchar i,m,n;
for(i=0;i<22;i++)
{
for(n=7;n>0;n--)
{
cube[0][n]=cube[1][n-1];
}
cube[0][0]=0x01<<i;
for(n=0;n<8;n++) tmp[n]= cube[0][n];
for(m=7;m>0;m--)
{
for(n=0;n<8;n++)
{
if(m==7)
cube[m][n]=cube[m-1][n]|cube[m][n];
else
cube[m][n]=cube[m-1][n];
}
}
for(n=0;n<8;n++)
{
if(cube[0][n]==0&&i<8) cube[0][n]=0xff;
else cube[0][n]=0xff-((2*cube[0][n])-1);
}
if(state) exchg_z();
saomiao(5);
if(state) exchg_z();
for(n=0;n<8;n++) cube[0][n]= tmp[n];
}
fill(0x00);
}
void liedrop(bit state)
{
uchar i,j;
fill_plane(0,0xff);
saomiao(5);
for(j=0;j<8;j++)
{
for(i=1;i<8;i++)
{
fill_plane(0,0xff-(0x01<<j|((0x01<<j)-1)));
if(i!=7||i!=0)
fill_plane(i,0x01<<j);
if(i==7)
fill_plane(7,(0x01<<j)|((0x01<<j)-1));
else
fill_plane(7,(0x01<<j)-1);
if(state==1)
{
exchg_jiao();
tmptocube();
}
saomiao(2);
fill(0x00);
}
}
for(j=8;j>0;j--)
{
for(i=7;i>=1;i--)
{
fill_plane(0,0xff-(0x01<<j|((0x01<<j)-1)));
if(i!=7||i!=0)
fill_plane(i,0x01<<j);
if(i==7)
fill_plane(7,(0x01<<j)|((0x01<<j)-1));
else
fill_plane(7,(0x01<<j)-1);
if(state==1)
{
exchg_jiao();
tmptocube();
}
saomiao(2);
fill(0x00);
}
}
}
void diaomian(bit state,uchar mode)
{
uchar i,m,n;
fill(0x00);
if(state==0)fill_plane(0,0xff);
else fill_plane(7,0xff);
saomiao(5);
if(state==1) fill_plane(7,0x00);
for(i=0;i<15;i++)
{
fill_plane(0,0xff-(((0x01<<i)-1)|(0x01<<i)));
for(m=6;m>0;m--)
{
for(n=0;n<8;n++)
{
if(m==6) cube[m+1][n]=cube[m][n]|cube[m+1][n];
else cube[m+1][n]=cube[m][n];
}
}
fill_plane(1,0x01<<i);
switch(mode)
{
case 1:break;
case 2: exchg_y();
}
if(state) exchg_z();
saomiao(5);
if(state) exchg_z();
switch(mode)
{
case 1:break;
case 2: exchg_y();
}
}
fill(0x00);
}
void all(bit state,bit mode)
{
bit flag;
uchar i,m,n,ii;
for(i=0;i<15;i++)
{
if(i>=8)
{
flag=1;
ii=i;
i=7;
}
for(m=i;m>0;m--)
for(n=0;n<8;n++)
cube[m][n]=cube[m-1][n];
for(n=0;n<8;n++)
{
if(state) cube[0][n]=~(0x01<<i|((0x01<<i)-1));
else cube[0][n]=0x01<<i|((0x01<<i)-1);
if(mode==1) cube[0][n]=exchg(0x01<<i|((0x01<<i)-1));
}
saomiao(10);
if(flag) i=ii;
}
flag=0;
}
void zhongxing(bit state)
{
uchar i,m,n;
for(i=0;i<4;i++)
{
if(state==1) i=3-i;
for(m=3-i;m<=4+i;m++)
{
for(n=3-i;n<=4+i;n++)
{
if(((m==3-i)||(m==4+i))&&((n==3-i)||(n==4+i)))
cube[m][n]=((0x01<<(4+i)|((0x01<<(4+i))-1)))-((0x01<<(3-i))-1);
else if((!(m==3-i||m==4+i))&&(!(n==3-i||n==4+i)))
cube[m][n]=0x00;
else
cube[m][n]=0x01<<(3-i)|0x01<<(4+i);
}
}
if(state==1) i=3-i;
saomiao(5);
fill(0x00);
}
}
void cubeadd(uchar mode,bit state)
{
uchar i,m,n;
for(i=0;i<8;i++)
{
for(m=0;m<=i;m++)
{
for(n=0;n<=i;n++)
{
if((m==0||m==i)&&(n==0||n==i))
cube[m][n]=(0x01<<i)|((0x01<<i)-1);
else if((!(m==0||m==i))&&(!(n==0||n==i)))
cube[m][n]=0x00;
else
cube[m][n]=(0x01<<i)|0x01;
}
}
switch(mode)
{
case 1: break;
case 2: exchg_x();break;
case 3: exchg_x();exchg_y();break;
case 4: exchg_y();break;
}
if(state==1) exchg_z();
saomiao(5);
fill(0x00);
}
}
void cubesub(uchar mode,bit state)
{
uchar i,m,n;
for(i=6;i>0;i--)
{
for(m=0;m<=i;m++)
{
for(n=0;n<=i;n++)
{
if((m==0||m==i)&&(n==0||n==i))
cube[m][n]=(0x01<<i)|((0x01<<i)-1);
else if((!(m==0||m==i))&&(!(n==0||n==i)))
cube[m][n]=0x00;
else
cube[m][n]=(0x01<<i)|0x01;
}
}
switch(mode)
{
case 1: break;
case 2: exchg_x();break;
case 3: exchg_x();exchg_y();break;
case 4: exchg_y();break;
}
if(state==1) exchg_z();
saomiao(5);
fill(0x00);
}
}
void z(uchar state)
{
fill(0xff);
for(line=0;line<8;line++)
{
gate=0;
sendline(); //发送一线移动数据
if(state==0) P0=line;
else P0=7-line;
Out595();
delay_ms(150);
gate=1;
}
}
void y(uchar state)
{
uchar j;
for(j=0;j<8;j++)
{
if(state==0)fill(0x01<<j);
else fill(0x80>>j);
saomiao(5);
}
fill(0x00);
}
void x(uchar state)
{
uchar i,j;
for(j=0;j<8;j++)
{
fill(0x00);
if(state==0)
{for(i=0;i<8;i++) cube[i][j]=0xff;}
else{for(i=0;i<8;i++) cube[i][7-j]=0xff;}
saomiao(5);
}
fill(0x00);
}
void fill (unsigned char pattern)
{
uchar z;
uchar y;
for (z=0;z<8;z++)
{
for (y=0;y<8;y++)
{
cube[z][y] = pattern;
}
}
}
void SendByte(unsigned char dat)
{
unsigned char i;
for(i=0;i<8;i++)
{
SHCP=0;
DS=dat&0x01;
dat>>=1;
SHCP=1;
}
}
void Out595(void)
{
LATCH=0; //锁存
_nop_();
LATCH=1;
}
/********************发送一线移动数据********************/
void sendline()
{
uchar i;
for(i=0;i<8;i++)
SendByte(cube[line][i]);
}
void saomiao(uchar i)
{
uchar z;
for(z=0;z<i;z++)
{
for(line=0;line<8;line++)
{
gate=0;
sendline(); //发送一线移动数据
P0=line;
Out595();
delay2();
gate=1;
}
}
}
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;
}
void fill_plane(uchar m,uchar dat)
{
uchar n;
for(n=0;n<8;n++)
cube[m][n]=dat;
}
void exchg_x()
{
uchar i,j,temp;
for(i=0;i<8;i++)
{
for(j=0;j<4;j++)
{
temp=cube[i][j];
cube[i][j]=cube[i][7-j];
cube[i][7-j]=temp;
}
}
}
void exchg_
- 1
- 2
- 3
- 4
- 5
- 6
前往页