字符与图和汉字,等侍时间过长,请高人指点。
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar temp,a,temp1,b;
sbit rs=P3^5;
sbit wr=P3^6;
sbit en=P3^4;
sbit psb=P3^7;
sbit dula=P2^6;
sbit wela=P2^7;
//uchar table[]="hhhhhhhhhhhhh";
uchar table1[]="今天是你的生日。";
//uchar table2[]="今天是你的生日。";
//uchar table3[]="今天是你的生日。";
void delay(uchar j)
{
uchar x,z;
for(x=110;x>0;x--)
for(z=j;z>0;z--);
}
void Write_Cmd(uchar Cmd) //写命令
{
rs=0;
wr=0;
en=0;
P0=Cmd;
delay(1);
en=1;
delay(1);
en=0;
}
void Write_Data(uchar date)
{
rs=1;
wr=0;
en=0;
P0=date;
delay(1);
en=1;
delay(1);
en=0;
}
void Ini_Lcd()
{
en=0;
wr=0;
rs=0;
psb=1;
Write_Cmd(0x30); //基本指令集
delay(1);
Write_Cmd(0x02); // 地址归位
delay(1);
Write_Cmd(0x0c); //整体显示打开,游标关闭
delay(1);
Write_Cmd(0x06); //游标右移
delay(1);
Write_Cmd(0x80); //设定显示的起始地址
delay(1);
Write_Cmd(0x01); //清除显示
delay(1);
}
void Draw_TX(uchar Xaddr,const uchar * dp)
{
uchar z;
uchar k=0;
Write_Cmd(0x01); //清屏,只能清除DDRAM
Write_Cmd(0x30); //使用扩展指令集,关闭绘图显示
Write_Cmd(Xaddr); //X地址
for(z=0;z<16;z++)
{
Write_Data(dp[k++]);
}
Write_Cmd(0x36); //打开绘图显示
// Write_Cmd(0x30); //回到基本指令集模式
}
uchar code qq[]=
{
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X01,0X8C,0X00,0X06,0X00,0X00,0X00,
0X00,0X03,0X0C,0X00,0X06,0X00,0X18,0X00,0X00,0X03,0X08,0X00,0X06,0X0F,0XF8,0X00,
0X00,0X02,0X18,0X00,0X04,0X00,0X30,0X00,0X00,0X06,0X10,0X0C,0X04,0X40,0X20,0X00,
0X00,0X04,0X1F,0XFC,0X7F,0XE0,0X40,0X00,0X00,0X0E,0X20,0X18,0X0C,0X40,0X80,0X00,
0X00,0X0C,0X41,0X10,0X08,0X40,0X80,0X00,0X00,0X14,0X41,0X00,0X08,0XC0,0X80,0X00,
0X00,0X24,0X81,0X00,0X08,0X80,0X84,0X00,0X00,0X44,0X19,0X00,0X08,0XBF,0XFE,0X00,
0X00,0X44,0X11,0X30,0X10,0X80,0X80,0X00,0X00,0X04,0X31,0X18,0X11,0X80,0X80,0X00,
0X00,0X04,0X21,0X08,0X11,0X00,0X80,0X00,0X00,0X04,0X61,0X0C,0X19,0X00,0X80,0X00,
0X00,0X04,0X41,0X04,0X07,0X00,0X80,0X00,0X00,0X04,0X81,0X04,0X02,0XC0,0X80,0X00,
0X00,0X04,0X81,0X04,0X04,0X60,0X80,0X00,0X00,0X04,0X01,0X00,0X08,0X20,0X80,0X00,
0X00,0X06,0X0F,0X00,0X10,0X07,0X80,0X00,0X00,0X04,0X02,0X00,0X60,0X03,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X07,0XC0,0X00,0X00,0X00,0X00,0X00,
0X00,0X08,0X60,0X00,0X00,0X00,0X00,0X00,0X00,0X08,0X20,0X00,0X00,0X00,0X00,0X00,
0X00,0X18,0X20,0X00,0X00,0X00,0X00,0X00,0X00,0X08,0X60,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X40,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0XC0,0X00,0X00,0X00,0X00,0X00,
0X00,0X01,0X80,0X00,0X00,0X00,0X00,0X00,0X00,0X01,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X01,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X01,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X03,0X80,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0X80,0X00,0X00,0X00,0X00,0X00,
0X00,0X03,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
};
void Clear_GDRAM(void) //64X256点阵显示RAM
{
uchar i,j,k;
Write_Cmd(0x34); //打开扩展指令集
i = 0x80; //1000 0000(十进制是128)
for(j = 0;j < 32;j++)
{
Write_Cmd(i++); //Y
Write_Cmd(0x80); //X
for(k = 0;k < 16;k++)
{
Write_Data(0x00);
}
}
i = 0x80;
for(j = 0;j < 32;j++)
{
Write_Cmd(i++);
Write_Cmd(0x88);
for(k = 0;k < 16;k++)
{
Write_Data(0x00);
}
}
Write_Cmd(0x30); //回到基本指令集
}
void Draw_PM(const uchar *ptr)
{
uchar i,j,k;
Write_Cmd(0x34); //打开扩展指令集
i = 0x80;
for(j = 0;j < 32;j++)
{
Write_Cmd(i++);
Write_Cmd(0x80);
for(k = 0;k < 16;k++)
{
Write_Data(*ptr++);
}
}
i = 0x80;
for(j = 0;j < 32;j++)
{
Write_Cmd(i++);
Write_Cmd(0x88);
for(k = 0;k < 16;k++)
{
Write_Data(*ptr++);
}
}
Write_Cmd(0x36); //打开绘图显示
Write_Cmd(0x30); //回到基本指令集
}
/***************************主函数***************************/
void main( void )
{
uchar i;
wela=0;
dula=0;
Ini_Lcd(); //初始化液晶
Write_Cmd(0x80);
//写第一行的显示地址
for(i = 0; i < 16; i++)
Write_Data(0x30+i);
//显示0x30~0x3f对应的字符
Write_Cmd(0x90);
//写第二行的显示地址
for(i = 0; i < 16; i++)
Write_Data(0x40+i);
//显示0x40~0x4f对应的字符
Write_Cmd(0x88);
//写第三行的显示地址
for(i = 0; i < 16; i++)
Write_Data(0x50+i);
//显示0x50~0x5f对应的字符
Write_Cmd(0x98);
//写第四行的显示地址
for(i = 0; i < 16; i++)
Write_Data(0x60+i); //显示0x60~0x6f对应的字符
Clear_GDRAM();
Write_Cmd(0x01);
Draw_PM(qq);
delay(1000);
delay(1000);
delay(1000);
delay(1000);
delay(1000);
delay(1000);
Clear_GDRAM();
Write_Cmd(0x01);
Draw_TX(0x80,table1);
while(1);
} |