📄 main7.c
字号:
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define staticdis 0x01
#define up 0x02
#define left 0x03
typedef struct typFNT_GB16 // 汉字字模显示数据结构
{
char Index[2];
char Msk[32];
};
struct typFNT_GB16 code GB_16[] = { // 显示为16*16
"中",0x01,0x00,0x01,0x00,0x21,0x08,0x3F,0xFC,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x3F,0xF8,0x21,0x08,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,
"文",0x02,0x00,0x01,0x00,0x01,0x00,0xFF,0xFE,0x08,0x20,0x08,0x20,0x08,0x20,0x04,0x40,0x04,0x40,0x02,0x80,0x01,0x00,0x02,0x80,0x04,0x60,0x18,0x1E,0xE0,0x08,0x00,0x00,
"测",0x40,0x02,0x27,0xC2,0x24,0x42,0x84,0x52,0x45,0x52,0x55,0x52,0x15,0x52,0x25,0x52,0x25,0x52,0x25,0x52,0xC5,0x52,0x41,0x02,0x42,0x82,0x42,0x42,0x44,0x4A,0x48,0x04,
"试",0x00,0x20,0x40,0x28,0x20,0x24,0x30,0x24,0x27,0xFE,0x00,0x20,0xE0,0x20,0x27,0xE0,0x21,0x20,0x21,0x10,0x21,0x10,0x21,0x0A,0x29,0xCA,0x36,0x06,0x20,0x02,0x00,0x00,
"衡",0x22,0x00,0x33,0xDE,0x44,0x40,0x58,0x80,0x97,0xC0,0x25,0x5E,0x67,0xC4,0xA5,0x44,0x27,0xC4,0x21,0x04,0x2F,0xE4,0x21,0x04,0x22,0x84,0x24,0x54,0x28,0x28,0x20,0x00,
"阳",0x00,0x00,0x7D,0xFC,0x45,0x04,0x49,0x04,0x49,0x04,0x51,0x04,0x49,0xFC,0x45,0x04,0x45,0x04,0x45,0x04,0x69,0x04,0x51,0x04,0x41,0xFC,0x41,0x04,0x40,0x00,0x40,0x00,
"师",0x08,0x00,0x0B,0xFE,0x48,0x20,0x48,0x20,0x4B,0xFE,0x4A,0x22,0x4A,0x22,0x4A,0x22,0x4A,0x22,0x52,0x22,0x52,0x2A,0x12,0x24,0x20,0x20,0x40,0x20,0x80,0x20,0x00,0x20,
"范",0x04,0x20,0x04,0x20,0xFF,0xFE,0x04,0x60,0x40,0x00,0x31,0xF8,0x91,0x08,0x61,0x08,0x49,0x08,0x09,0x38,0x11,0x10,0xE1,0x00,0x21,0x04,0x21,0x04,0x20,0xFC,0x20,0x00,
"学",0x01,0x08,0x10,0x8C,0x0C,0xC8,0x08,0x90,0x7F,0xFE,0x40,0x04,0x8F,0xE8,0x00,0x40,0x00,0x80,0x7F,0xFE,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x02,0x80,0x01,0x00,
"院",0x00,0x80,0xF8,0x40,0x8F,0xFE,0x94,0x04,0xA0,0x00,0xA3,0xF8,0x90,0x00,0x88,0x00,0x8F,0xFE,0xA9,0x20,0x91,0x20,0x81,0x20,0x82,0x22,0x82,0x22,0x84,0x22,0x88,0x1E,
"物",0x10,0x80,0x10,0x80,0x50,0x80,0x51,0xFC,0x7D,0x54,0x52,0x54,0x94,0x94,0x14,0x94,0x19,0x24,0x32,0x24,0xD4,0x44,0x10,0x84,0x11,0x04,0x12,0x04,0x14,0x28,0x00,0x10,
"理",0x00,0x00,0x03,0xFC,0xFA,0x44,0x22,0x44,0x23,0xFC,0x22,0x44,0xFA,0x44,0x23,0xFC,0x22,0x44,0x20,0x40,0x23,0xFC,0x38,0x40,0xC0,0x40,0x00,0x40,0x0F,0xFE,0x00,0x00,
"与",0x00,0x00,0x08,0x00,0x08,0x04,0x0F,0xFE,0x08,0x00,0x08,0x00,0x0F,0xFC,0x00,0x04,0x00,0x04,0x00,0x24,0x7F,0xF4,0x00,0x04,0x00,0x04,0x00,0x48,0x00,0x30,0x00,0x00,
"电",0x01,0x00,0x01,0x00,0x01,0x00,0x3F,0xF8,0x21,0x08,0x21,0x08,0x3F,0xF8,0x21,0x08,0x21,0x08,0x21,0x08,0x3F,0xF8,0x21,0x08,0x01,0x02,0x01,0x02,0x00,0xFE,0x00,0x00,
"子",0x00,0x00,0x3F,0xF0,0x00,0x20,0x00,0x40,0x00,0x80,0x01,0x00,0x01,0x00,0x01,0x04,0xFF,0xFE,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x05,0x00,0x02,0x00,
"信",0x08,0x80,0x0C,0x60,0x18,0x40,0x17,0xFE,0x30,0x00,0x33,0xF8,0x50,0x00,0x93,0xF8,0x10,0x00,0x13,0xF8,0x12,0x08,0x12,0x08,0x12,0x08,0x13,0xF8,0x12,0x08,0x00,0x00,
"息",0x01,0x00,0x02,0x00,0x1F,0xF0,0x10,0x10,0x1F,0xF0,0x10,0x10,0x1F,0xF0,0x10,0x10,0x1F,0xF0,0x00,0x00,0x09,0x00,0x28,0x84,0x28,0x92,0x68,0x12,0x07,0xF0,0x00,0x00,
"科",0x06,0x08,0x78,0x88,0x08,0x48,0x08,0x48,0xFE,0x08,0x18,0x88,0x1C,0x48,0x2A,0x48,0x28,0x0E,0x48,0x78,0x8B,0x88,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,
"学",0x01,0x08,0x10,0x8C,0x0C,0xC8,0x08,0x90,0x7F,0xFE,0x40,0x04,0x8F,0xE8,0x00,0x40,0x00,0x80,0x7F,0xFE,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x02,0x80,0x01,0x00,
"系",0x00,0x7C,0x3F,0x80,0x02,0x20,0x04,0x20,0x08,0x40,0x1F,0x80,0x03,0x20,0x0C,0x10,0x3F,0xF8,0x10,0x8C,0x04,0xA0,0x08,0x90,0x10,0x88,0x20,0x84,0x42,0x84,0x01,0x00,
};
uchar code str1[]={"衡阳师范学院"};
uchar code str2[]={"衡阳师范学院物理与电子信息科学系"};
void timerinit(void);
void sioinit(void);
void initial(void);
void clrscree(void);
void clrindex(void);
void senddata(uchar i);
void row_dis(void);
void full_index(uchar *prt,uchar st_buf,uchar en_buf);
void l_databuf(uchar i);
void full_databuf(uchar effict);
void display(uchar *a,uchar effict,char st_space,char shfitspeed,int sta_time);
void timeIRQ(void);
void delay_s(uint k);
uchar str_longth(uchar *a);
uchar databuf[18];
uchar *dataindex[12];
uchar cbuf_flag,fullindex_flag,fulldata_flag;
uchar row_count,shift_count,shift_add,disen;
uchar *indexprt;
uint time_count,shfitspeed;
uchar st_space,en_space;
main()
{
initial();
while(1)
{
display(str1,staticdis,0,0,1000);
// delay_s(10);
// clrscree();
display(str2,up,10,100,0);
}
}
void timerinit(void)//3ms timer
{
TMOD=0x01;
TH0=(65535-600)/256;
TL0=(65535-600)%256;
IE=0x82;
}
void sioinit(void)// 方式0
{
SCON=0x00;
TI=0;
}
void initial(void)
{
timerinit();
sioinit();
fulldata_flag=1;
fullindex_flag=1;
time_count=0;
TR0=1;
}
/*********application function*******
静态显示、左移、右移
************************************/
void senddata(uchar j) //sio 口发送数据
{
j=~j;
SBUF=j;
while(TI==0);
TI=0;
}
void row_dis(void) //p1.0-a,p1.1-b,p1.2-c,p1.3-d st-p1.4 p1.5-en
{
uchar i=0,j=0,k;
for(i=0;i<16;i++)
{
j=databuf[15-i];
senddata(j);
}
k=~row_count&0x0f;
P1=k+0x20+0x10;
_nop_();
_nop_();
P1=k+0x20;
// P1=row_count+0x10;
// P1=row_count;
fulldata_flag=1;
row_count++;
if(row_count==16)row_count=0;
}
//*************************databuf 更新
void clrscree(void)
{
int i;
for(i=0;i<18;i+=2)
{
databuf[i]=0;
databuf[i+1]=0;
}
}
void clrindex(void)
{
int i;
for(i=0;i<12;i++)
{
dataindex[i]=0;
}
}
void full_databuf(uchar effict)
{
uchar i;
uchar *ptr;
clrscree();
if(effict==staticdis||effict==left)
{
for(i=0;i<18;i+=2)
{
ptr=dataindex[i/2];
if(ptr==0)continue;
databuf[i]=*(ptr+row_count*2);
databuf[i+1]=*(ptr+row_count*2+1);
}
if(effict==left)
{
l_databuf(shift_add);
}
}
else if(effict==up)
{
for(i=0;i<18;i+=2)
{
ptr=dataindex[i/2];
if(ptr==0)continue;
if((shift_add+row_count)>15)
{
databuf[i]=*(ptr+134+(shift_add+row_count-15)*2);
databuf[i+1]=*(ptr+134+(shift_add+row_count-15)*2+1);
}
else
{
databuf[i]=*(ptr+(shift_add+row_count)*2);
databuf[i+1]=*(ptr+(shift_add+row_count)*2+1);
}
}
}
}
void l_databuf(uchar i)//左移时数据BUF处理
{
uchar h;
int j,k;
if(i>=8)
{
for(h=0;h<17;h++)
databuf[h]=databuf[h+1];
i-=8;
}
for(h=0;h<16;h++)
{
j=databuf[h];
k=databuf[h+1];
j=j<<i;
k=k>>(8-i);
databuf[h]=j|k;
}
}
void full_index(uchar *prt,uchar st_index,uchar en_index)
{
uchar str1,str2;
uchar *prt2;
int i,j;
clrindex();
for(i=st_index;i<en_index;i++,prt=prt+2)
{
str1=*prt;
str2=*(prt+1);
if(str1=='\0')
{
disen=1;
break;
}
for(j=0;j<sizeof(GB_16)/sizeof(GB_16[0]);j++)
{
if(str1 == GB_16[j].Index[0]&&str2 == GB_16[j].Index[1])
break;
}
prt2=GB_16[j].Msk;
dataindex[i]=prt2;
}
}
void timeIRQ(void) interrupt 1
{
TH0=(65535-600)/256;
TL0=(65535-600)%256;
time_count++;
if(fulldata_flag!=1)
{
row_dis();
shift_count--;
if(shift_count==0)
{
shift_count=shfitspeed;
shift_add++;
if(shift_add==16)
{
shift_add=0;
fullindex_flag=1;
}
}
}
}
void display(uchar *a,uchar effict,char st_space,char shfitspeed,int sta_time)//effict 显示效果 space 显示初始空白大小
{
uchar i,j,end_flag=0;
char longth;
indexprt=a;
disen=0;
shfitspeed=shfitspeed;
longth=str_longth(indexprt);
while(!end_flag)
{
if(fullindex_flag)
{
fullindex_flag=0;
if(disen)
{
if(longth>0)
{
for(j=0;j<12;j++)
{
dataindex[i]=dataindex[i+1];
}
longth--;
}
else
end_flag=1;
}
else
{
full_index(indexprt,st_space,12);
if(st_space>0)
{
if(effict==up)
{
if(st_space>4)
st_space-=4;
else
{indexprt+=2*st_space;longth=longth-st_space;st_space=0;}
}
else if(effict==left)
st_space--;
}
else
{
if(effict==up)
{indexprt+=8;longth-=4;}
else if(effict==left)
{indexprt+=2;longth--;}
}
}
}
if(fulldata_flag)
{
fulldata_flag=0;
full_databuf(effict);
if(effict==staticdis)
{
sta_time--;
if(sta_time==0)
end_flag=1;
}
}
}
}
//********************************
uchar str_longth(uchar *a)
{
uchar i,str1;
for(i=0;;i++,a+=2)
{
str1=*a;
if(str1=='\0') return (i/2);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -