这个移动扫描程序谁来解释一下?
尤其是那个开关语句里的
/*******************************************************************************
2011,1,27 使用4片74HC595做的16*16LED调试程序
晶振22.1184M
行数据与列数据都由595驱动,点阵采用整块的16*16点阵,2MM的LED
*******************************************************************************/
#include<reg51.h>
#define KUAN 168
#define GAO 16
sbit R1=P1^0; //定义数据引脚
sbit SK=P1^1; //定义数据时钟引脚
sbit LT=P1^2; //定义锁存引脚
unsigned int zi=0;
unsigned int x;
unsigned long cnt=0;
//定义扫描的数据码
unsigned long code ROW_code[16]={0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,
0x0100,0x0200,0x0400,0x0800,0x1000,0x2000,0x4000,0x8000};
unsigned char D_buff[32]={0}; //创建显示缓冲的数据,用于16*16点阵储存
unsigned char temp1,temp2,temp;
unsigned int i,j;
unsigned int x_cnt=0; //used for effect moving
//数据代码 横向取模,字节正序
unsigned char code Bmp[]=
{
/*------------------------------------------------------------------------------
; 若数据乱码,请检查字模格式设置,注意选择正确的取模方向和字节位顺序。
; 源文件 / 文字 : 欢迎光临 幻德科技
; 宽×高(像素): 168×16
; 字模格式/大小 : 单色点阵液晶字模,横向取模,字节正序/336字节
; 数据转换日期 : 2011-10-19 21:58:45
------------------------------------------------------------------------------*/
//0xA8,0x10,0x15,//宽的像素数,高的像素数,宽的字节数,参数设置可选
0x00,0x00,0x00,0x80,0x40,0x00,0x01,0x00,0x01,0x00,0x00,0x08,0x00,0x10,0x40,0x06,
0x08,0x10,0x20,0x00,0x00,0x00,0x00,0x00,0x80,0x21,0x80,0x21,0x10,0x09,0x80,0x00,
0x0C,0x00,0x18,0x40,0x78,0x88,0x10,0x20,0x00,0x00,0x00,0x00,0xFC,0x80,0x36,0x7C,
0x19,0x18,0x09,0x00,0x00,0x19,0xFC,0x27,0xFE,0x08,0x48,0x10,0x20,0x00,0x00,0x00,
0x00,0x05,0xFE,0x24,0x44,0x0D,0x10,0x49,0xFE,0x00,0x10,0x04,0x50,0x40,0x08,0x48,
0xFD,0xFE,0x00,0x00,0x00,0x00,0x85,0x04,0x04,0x44,0x09,0x20,0x4A,0x20,0x00,0x22,
0x04,0x9B,0xFC,0xFE,0x08,0x10,0x20,0x00,0x00,0x00,0x00,0x4A,0x48,0x04,0x44,0x01,
0x04,0x4A,0x10,0x00,0x43,0x04,0x32,0x94,0x18,0x88,0x14,0x20,0x00,0x00,0x00,0x00,
0x28,0x40,0xE4,0x44,0x7F,0xFE,0x4C,0x10,0x00,0xFE,0x04,0x22,0x94,0x1C,0x48,0x19,
0xFC,0x00,0x00,0x00,0x00,0x10,0x40,0x24,0x44,0x04,0x40,0x49,0x04,0x00,0x04,0x04,
0x63,0xFC,0x2A,0x48,0x31,0x08,0x00,0x00,0x00,0x00,0x18,0x40,0x25,0x44,0x04,0x40,
0x49,0xFE,0x00,0x08,0x04,0xA0,0x00,0x28,0x0E,0xD0,0x88,0x00,0x00,0x00,0x00,0x18,
0x60,0x26,0x54,0x04,0x40,0x49,0x24,0x00,0x0A,0x04,0x2F,0xFE,0x48,0x78,0x10,0x90,
0x00,0x00,0x00,0x00,0x24,0xA0,0x24,0x48,0x04,0x40,0x49,0x24,0x00,0x11,0x04,0x20,
0x00,0x8B,0x88,0x10,0x60,0x00,0x00,0x00,0x00,0x24,0x90,0x20,0x40,0x08,0x42,0x49,
0x24,0x00,0x7F,0x84,0x25,0x44,0x08,0x08,0x10,0x60,0x00,0x00,0x00,0x00,0x41,0x18,
0x20,0x40,0x08,0x42,0x49,0x24,0x00,0x21,0x04,0x25,0x22,0x08,0x08,0x10,0x90,0x00,
0x00,0x00,0x00,0x86,0x0E,0x50,0x00,0x10,0x42,0x09,0xFC,0x00,0x00,0x28,0x25,0x0A,
0x08,0x08,0x11,0x0E,0x00,0x00,0x00,0x00,0x38,0x04,0x8F,0xFE,0x20,0x3E,0x09,0x04,
0x00,0x00,0x10,0x28,0xF8,0x08,0x08,0x56,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x08,0x08,0x20,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x03,0xC0,0x03,0xC0,0x03,0xC0,
0x0C,0x30,0x0C,0x30,0x0C,0x30,0x0C,0x30,0x10,0x08,0x10,0x08,0x10,0x08,0x10,0x08,
0x26,0x64,0x28,0x14,0x26,0x64,0x20,0x04,0x48,0x12,0x46,0x62,0x48,0x12,0x4C,0x32,
0x46,0x62,0x40,0x02,0x46,0x62,0x52,0x4A,0x46,0x62,0x46,0x62,0x46,0x62,0x40,0x02,
0x40,0x02,0x40,0x02,0x40,0x02,0x40,0x02,0x48,0x12,0x40,0x02,0x40,0x02,0x4F,0xF2,
0x44,0x22,0x43,0xC2,0x43,0xC2,0x48,0x12,0x23,0xC4,0x24,0x24,0x24,0x24,0x24,0x24,
0x10,0x08,0x10,0x08,0x10,0x08,0x13,0xC8,0x08,0x10,0x08,0x10,0x08,0x10,0x08,0x10,
0x07,0xE0,0x07,0xE0,0x07,0xE0,0x07,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
//unsigned char code Bmp2[]=
//{
/*------------------------------------------------------------------------------
; 源文件 / 文字 : E:\Wonder Technolog\点阵数据\喜怒哀乐.bmp
; 宽×高(像素): 64×16
------------------------------------------------------------------------------*/
//};
void delay(unsigned int i) //延时子程序
{
unsigned int j,k;
for(i;i>0;i--)
for(j=10;j>0;j--)
for(k=50;k>0;k--);
}
//扫描程序
void display(unsigned int n) //n 变量为行的数量0-15分别扫描第1到16行
{
unsigned int i,j;
unsigned char num1;
unsigned long num=ROW_code[n];
for(i=0;i<16;i++)
{
SK=0;
R1=num&0x8000;
SK=1;
num<<=1;
}
num1=D_buff[2*n];
for(j=0;j<8;j++)
{
SK=0;
R1=~num1&0x80;
SK=1;
num1<<=1;
}
num1=D_buff[2*n+1];
for(j=0;j<8;j++)
{
SK=0;
R1=~num1&0x80;
SK=1;
num1<<=1;
}
LT=1;
LT=0;
}
void timer0(void) interrupt 1
{
TH0=0xf8;
TL0=0xD7;
//add your code here.
display(x);
x++;
if(x==16)
x=0;
cnt++;
}
void initTimer(void)
{
TMOD|=0x01;
TH0=0xF8;
TL0=0xD7;
TR0=1;
ET0=1;
//EA=1;
}
void main(void) //主函数
{
initTimer();
EA=1;
for(i=0;i<32;i++)
D_buff[i]=0x00;
while(1)
{
if(cnt==100)
{
cnt=0;
if(x_cnt<KUAN-16)
{
for(i=0;i<16;i++)
{ for(j=0;j<2;j++)
{
temp1= Bmp[i*(KUAN/8)+j+x_cnt/8];
temp2= Bmp[i*(KUAN/8)+j+1+x_cnt/8];
switch(x_cnt%8)
{
case 0: temp=(temp1<<=1) |((temp2>>=7) & 0x01); break;
case 1: temp=(temp1<<=2) |((temp2>>=6) & 0x03); break;
case 2: temp=(temp1<<=3) |((temp2>>=5) & 0x07); break;
case 3: temp=(temp1<<=4) |((temp2>>=4) & 0x0f); break;
//case 4: temp=(temp1<<=4) |((temp2>>=4) & 0x0f); break;
case 4: temp=(temp1<<=5) |((temp2>>=3) & 0x1f); break;
case 5: temp=(temp1<<=6) |((temp2>>=2) & 0x3f); break;
case 6: temp=(temp1<<=7) |((temp2>>=1) & 0x7f); break;
case 7: temp=temp2; break;
default: break;
}
D_buff[2*i+j]=temp;
}
}
x_cnt++;
}
else
x_cnt=0;
}
}
}
真复查