/*************************************************/
#include<reg51.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
/*************************************************/
sbit hc595_ds=P2^0;
sbit hc595_shcp=P2^1;
sbit hc595_stcp=P2^2;
sbit P2_4=P2^4;
sbit P2_5=P2^5;
sbit P2_6=P2^6;
sbit P2_7=P2^7;
sbit OE =P3^3;
sbit LE =P3^7;
uchar flag_left,flag_right,flag_up,flag_down;
uchar dispram[8];
uchar code table[]={
0xFF,0xFF,0xFF,0xE7,0xDB,0xBD,0xBD,0xBD,
0xBD,0xBD,0xBD,0xBD,0xDB,0xE7,0xFF,0xFF,/*"0",0*/
0xFF,0xFF,0xFF,0xE7,0xDB,0xBD,0xBD,0xBD,
0xBD,0xBD,0xBD,0xBD,0xDB,0xE7,0xFF,0xFF,/*"0",1*/
0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x24,0x24,
0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,
0x42,0x24,0x24,0x18,0x18,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x24,0x24,
0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,
0x42,0x42,0x42,0x42,0x24,0x24,0x18,0x18,0x00,0x00,0x00,0x00,//00
};
/*************************************************/
void hc595_write_data(uchar data_ds);//
void hc595_display();
void delay(uint n);
void key_scan();
void shift_L();
void shift_R();
/*************************************************/
void main()
{
uchar i,j,k,num_l,num_r,n=0;
while(1)
{ char a1;
a1=0;
for(i=0;i<16;i++)
{
for(j=0;j<6;j++)
{ P1=0xfe; P0=0xfe ;
for(k=0;k<16;k++)
{
key_scan();
dispram[0]=table[2*k+1];
dispram[1]=table[2*k];
dispram[2]=table[2*k+33];
dispram[3]=table[2*k+32];
if(k<8) P0=_crol_(P1,1);
else P1=_crol_(P1,1);
if(flag_left==1)
{num_l=n;for(;num_l>0;num_l--)shift_L();}
if(flag_right==1)
{num_r=n;for(;num_r>0;num_r--)shift_R();}
hc595_write_data(dispram[0]);
hc595_write_data(dispram[1]);
hc595_write_data(dispram[2]);
hc595_write_data(dispram[3]);
if(flag_up==1)
{LE=1;
if(k<8) P0=_crol_(P1,1);
if(k>7) P1=_crol_(P1,1);}
else if(flag_down==1)
{ LE=1;
if(k<8) P0=_crol_(P1,1);
if(k>7) P1=_crol_(P1,1);}
hc595_display();
}
}
n++;
if(n==32)n=0;
}
}
}
/*************************************************/
void hc595_write_data(uchar data_ds)
{
uchar n_bit;
for(n_bit=0;n_bit<8;n_bit++)
{
hc595_shcp=0;//禁止列数据输出
hc595_ds=data_ds&(1<<n_bit);
hc595_shcp=1;
}
}
/*************************************************/
void hc595_display()
{
hc595_stcp=0;
delay(1);
hc595_stcp=1;
}
/*************************************************/
void delay(uint n)
{
while(n--);
}
/*************************************************/
void key_scan()
{
if(P2_4==0)delay(10);
if(P2_4==0){flag_left=1;flag_right=0;flag_up=0;flag_down=0;}
if(P2_5==0)delay(10);
if(P2_5==0){flag_right=1;flag_left=0,flag_up=0;flag_down=0;}
if(P2_6==0)delay(10);
if(P2_6==0){flag_up=1;flag_left=0,flag_right=0;flag_down=0;}
if(P2_7==0)delay(10);
if(P2_7==0){flag_down=1;flag_left=0;flag_right=0;flag_up=0;}
}
/*************************************************/
void shift_L() //循环左移
{
bit hbit;
uchar i;
hbit=dispram[0]&0x80;
for(i=0;i<3;i++)
{
dispram[i]=dispram[i]<<1;
dispram[i]+=dispram[i+1]>>7;
}
dispram[3]=dispram[3]<<1;
if(hbit)dispram[3]+=0x01;
}
/*************************************************/
void shift_R() //右移函数
{
bit lbit;
uchar i;
lbit=dispram[3]&0x01; //保存最低位
for(i=3;i>0;i--)
{
dispram[i]=dispram[i]>>1; //右移一位
dispram[i]+=dispram[i-1]<<7;
}
dispram[0]=dispram[0]>>1;
if(lbit)dispram[0]+=0x80;
}
/*************************************************/