#include
#define Disp_On 0x3f
#define Disp_Off 0x3e
#define
#define Page_Add 0xb8
#define Start_Line 0xc0
#define delaytime
int st_line=Start_Line;
sbit cs1=P2^0;
sbit cs2=P2^1;
sbit Enable=P2^2;
sbit RW=P2^3;
sbit RS=P2^4;
//即将显现的文字放在32*32的数组中,一行里边则对应一个汉字
unsigned char code dat[32][32]=
{
0x02,0xF2,0x12,0x12,0x12,0xFE,0x92,0x12,0x12,0xFE,0x12,0x12,0x12,0xFB,0x12,0x00,
0x00,0x7F,0x08,0x04,0x03,0x00,0x10,0x09,0x06,0x01,0x01,0x26,0x40,0x3F,0x00,0x00,
0x00,0x80,0x80,0x40,0x20,0x10,0x0C,0xE3,0x04,0x08,0x10,0x20,0x60,0xC0,0x40,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x20,0x24,0x24,0xA4,0xA4,0xBF,0xA4,0xE4,0xA4,0xBF,0xA4,0xA4,0x24,0x24,0x20,0x00,
0x00,0x80,0x80,0x5F,0x32,0x12,0x12,0x1F,0x12,0x12,0x32,0x5F,0xC0,0x00,0x00,0x00,
0xFA,0x8A,0xFA,0x02,0xFA,0x8A,0x0A,0xFA,0x00,0xFC,0x0E,0x35,0x44,0x7C,0x00,0x00,
0x7F,0x41,0x7F,0x00,0x7F,0x20,0x41,0x3F,0x08,0x09,0x09,0x09,0x29,0x41,0x3F,0x00,
0x00,0xFC,0x04,0x04,0xFC,0x00,0xFC,0x04,0x16,0x65,0x04,0x84,0xFC,0x00,0x00,0x00,
0x00,0x03,0x02,0x0A,0x0B,0x08,0x0B,0x0A,0x0A,0x0A,0x0A,0x4A,0x82,0x7E,0x00,0x00,
0x00,0x41,0x63,0x55,0x49,0xC1,0x5F,0x50,0x61,0x53,0xCD,0x41,0x5F,0x40,0x00,0x00,
0x00,0x08,0x08,0x0C,0x0A,0x09,0x0A,0xFC,0x08,0x0A,0x09,0x0A,0x0C,0x08,0x08,0x00,
0x08,0x88,0x68,0xFF,0x28,0x48,0xFC,0x04,0x02,0xF2,0x00,0xFC,0x04,0x04,0xFC,0x00,
0x02,0x01,0x00,0xFF,0x00,0x40,0x47,0x22,0x19,0x07,0x00,0xFF,0x02,0x04,0x03,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x58,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xC0,0x80,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x10,0x08,0x84,0xC6,0x73,0x22,0x40,0x44,0x44,0x44,0xC4,0x44,0x44,0x44,0x40,0x00,
0x02,0x01,0x00,0xFF,0x00,0x00,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xF8,0x08,0x08,0x0C,0x0B,0x08,0x08,0x08,0x08,0x08,0xF8,0x00,0x00,0x00,
0x00,0x00,0x7F,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x7F,0x00,0x00,0x00,
0x80,0xF7,0x85,0x7D,0x55,0xD7,0x40,0x14,0xF7,0xAA,0xAA,0xB6,0xF2,0x10,0x00,0x00,
0x40,0x40,0x40,0x5F,0x51,0x53,0x55,0x51,0x51,0x55,0x17,0x50,0x90,0x70,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x40,0x40,0x40,0x40,0x40,0x00,0x00,0x00,
0x00,0x40,0x40,0x40,0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0x40,0x40,0x60,0x40,0x00,
0x40,0x40,0x44,0x54,0x54,0x54,0x54,0x7F,0x54,0x54,0x54,0x54,0x44,0x40,0x40,0x00,
0x00,0x00,0x00,0xFF,0x15,0x15,0x15,0x15,0x15,0x55,0x95,0x7F,0x00,0x00,0x00,0x00,
0x00,0x40,0x42,0x42,0x42,0x42,0x42,0xFE,0x42,0x42,0x42,0x42,0x42,0x42,0x40,0x00,
0x00,0x80,0x40,0x20,0x10,0x08,0x06,0x01,0x02,0x04,0x08,0x10,0x30,0x60,0x20,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x18,0x24,0x24,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x4C,0x44,0xE4,0x54,0x44,0x64,0xD5,0x46,0x44,0x4C,0x54,0xD4,0x24,0x2C,0x00,
0x00,0x00,0x00,0xFF,0x44,0x62,0x55,0x49,0x55,0x43,0x41,0x40,0xFF,0x00,0x00,0x00,
0x08,0x08,0xE8,0xA8,0xA9,0xAE,0xEA,0x08,0x08,0xC8,0x0C,0x0B,0xEA,0x08,0x08,0x00,
0x00,0x00,0x7F,0x04,0x24,0x44,0x3F,0x00,0x00,0x1F,0x40,0x80,0x7F,0x00,0x00,0x00,
0x02,0xF2,0x12,0x12,0x12,0xFE,0x12,0x12,0x12,0xFE,0x12,0x12,0x12,0xF2,0x02,0x00,
0x00,0x7F,0x28,0x24,0x22,0x21,0x20,0x20,0x20,0x21,0x22,0x22,0x22,0x7F,0x00,0x00,
0x00,0xF0,0x00,0xFF,0x00,0xF0,0x40,0x20,0x10,0x2C,0x43,0x04,0x08,0x70,0x20,0x00,
0x08,0x1F,0x08,0x07,0x04,0x07,0x01,0x05,0x09,0x11,0x29,0x65,0x03,0x01,0x00,0x00,
0x40,0x40,0x44,0x44,0x44,0x44,0x44,0xFC,0x42,0x42,0x42,0x43,0x42,0x60,0x40,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x24,0x24,0xE4,0xFC,0xA2,0x22,0x22,0x80,0x70,0x00,0xFF,0x40,0x20,0x18,0x00,0x00,
0x02,0x01,0x00,0xFF,0x00,0x83,0x40,0x20,0x18,0x07,0x01,0x06,0x18,0xE0,0x40,0x00,
0x00,0x18,0x0A,0xAA,0xAA,0xAA,0x0A,0xFE,0x0A,0xAA,0xAA,0xAA,0x0A,0x18,0x08,0x00,
0x00,0x00,0x42,0x4A,0x4A,0x4A,0x4A,0x4A,0x4A,0x4A,0x4A,0x4A,0xFE,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x58,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xF8,0x01,0x06,0x00,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0xFE,0x00,0x00,
0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,
0x08,0x31,0x06,0xC0,0x30,0x00,0xF8,0x08,0x0C,0x0B,0x08,0x08,0x08,0xF8,0x00,0x00,
0x02,0x02,0xFF,0x00,0x00,0x00,0xFF,0x41,0x41,0x41,0x41,0x41,0x41,0xFF,0x00,0x00,
0x00,0x04,0x04,0xC4,0xB4,0x8C,0x87,0x84,0xF4,0x84,0x84,0x84,0x84,0x04,0x00,0x00,
0x00,0x00,0x20,0x18,0x0E,0x04,0x20,0x40,0xFF,0x00,0x02,0x04,0x18,0x30,0x00,0x00,
0x00,0x00,0x80,0xBE,0xA2,0xA2,0xA2,0xA2,0xA2,0xA2,0xA2,0xBE,0x80,0x00,0x00,0x00,
0x84,0x84,0x44,0x44,0x24,0x14,0x0C,0x07,0x0C,0x14,0x24,0x64,0xC4,0x44,0x04,0x00,
0x00,0x02,0x02,0x02,0x02,0x82,0x7E,0x22,0x22,0x22,0x22,0xF2,0x22,0x02,0x02,0x00,
0x00,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x20,0x60,0x20,0x1F,0x00,0x00,0x00,0x00,
0x00,0x00,0xFF,0x91,0x91,0x91,0x91,0xFF,0x91,0x91,0x91,0x91,0xFF,0x00,0x00,0x00,
0x40,0x40,0x44,0x44,0x44,0x44,0x44,0x7F,0x44,0x44,0x44,0x44,0x44,0x40,0x40,0x00,
0x80,0x80,0xFC,0x96,0xA5,0xFC,0x80,0x40,0x3E,0x02,0x02,0x02,0x7E,0x40,0x40,0x00,
0x80,0x60,0x1F,0x42,0x84,0x7F,0x00,0x00,0x7E,0x22,0x22,0x22,0x22,0x7E,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x18,0x24,0x24,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
//延时函数
void delay(unsigned int t)
//写指令
void write_com(unsigned char cmdcode)
//写数据
void write_data(unsigned char Dispdata)
//清屏
void Clr_Scr()
//显现汉字.汉字的显现是先显现第一页,再显现第二页.
void hz_disp16(unsigned char pag,unsigned char col, unsigned char code *hzk)
{
unsigned char j=0,i=0;
for(j=0;j<2;j++)
{
write_com(Page_Add+pag+j);
delay(3);
write_com(Col_Add+col);
delay(3);
for(i=0;i<16;i++)
{
write_data(hzk[16*j+i]);
delay(3);
}
}
}
//显现字母
void hz_disp8(unsigned char pag,unsigned char col,unsigned char code *hzk)
{
unsigned char j=0,i=0;
for(j=0;j<2;j++)
{
write_com(Page_Add+pag+j);
delay(3);
write_com(Col_Add+col);
delay(3);
for(i=0;i<8;i++)
write_data(hzk[8*j+i]);
delay(3);
}
}
//初始化
void init_lcd()
{
delay(10);
cs1=1;
cs2=1;
delay(10);
write_com(Disp_Off);
write_com(Page_Add+0);
write_com(st_line+0);
write_com(Col_Add+0);
write_com(Disp_On);
}
void main()
{
int pag=0,col=0,zishu=0; //zishu用来计算显现的字数
init_lcd();
Clr_Scr();
cs1=1;cs2=1;
delay(10);
cs1=1;cs2=0;
while(1)
{
hz_disp16(pag,col,dat[zishu]);
delay(delaytime);
zishu++;
col=col+16;
if(col==64)
col=0;
if(!(zishu%4)) //当显现的字数为4,12,28时在左半屏
{cs1=0;cs2=1;}
if(!(zishu%8)) //当显现的字数为8,16,32时在右半屏,而且右半屏显现完之后,页数加2。由于汉字占用的空间为16*16,8行为一页
{cs1=1;cs2=0;pag+=2;}
if(!(zishu%32))
{
st_line+=3; //当显现完32个字的时分,起始行加一,到达翻滚作用
if(st_line>=0xff)
st_line=Start_Line;
write_com(st_line+0);
cs1=0;cs2=1;
write_com(st_line+0); //设置左半屏起始行
zishu=0;pag=0;
cs1=1;cs2=0;
}
}
}