帖个实例给大家看看。单字或者多字反白
#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
#define x1 0x80
#define x2 0x88
#define y 0x80
#define comm 0
#define dat 1
sbit rs = P3^0; //H=data; L=command;
sbit rw = P3^1; //H=read; L=write;
sbit e = P3^2; //input enable;
sbit psb= P3^3; //H=并口; L=串口;
sbit rst= P3^4; //Reset Signal 低电平有效
sbit busy=P1^7; //lcd busy bit
void wr_lcd (uchar dat_comm,uchar content);
void chk_busy (void);
void delay (uint us);
void delay1 (uint ms);
uchar code tab1[]={
"锐显科技有限公司"
"ES:www.rxlcd.com"
"中文图形液晶模块"
"TEL:020-62619437"
};
unsigned char code tab5[]=
{
/*------------------------------------------------------------------------------
; 宽×高(像素): 128×64
; 字模格式/大小 : 单色点阵液晶字模,横向取模,字节正序/1024字节
------------------------------------------------------------------------------*/
0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0x80,0x00,0x60,0x00,0x00,0x00,0x00,0x0F,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x00,0x00,0xF0,0x00,0x00,0x3F,0x8F,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x01,0xF8,0x00,0x00,0x3F,0x8F,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x03,0xFC,0x00,0x00,0x3F,0x8F,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x07,0xFE,0x00,0x00,0x3F,0xCF,0xEF,0xC0,0xFF,0xC7,0xE3,0xE7,0xF0,0x00,0x00,
0x00,0x0F,0xBF,0x03,0x00,0x1F,0xDF,0xCF,0xC3,0xFF,0xF7,0xF7,0xF3,0xF0,0x00,0x00,
0x00,0x1F,0x1F,0x87,0x80,0x1F,0xD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x00,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,0x1C,0x00,0x1C,0x0F,0x00,0x00,
0x00,0x08,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x38,0x1C,0x00,0x1E,0x0F,0x00,0x00,
0x00,0x0E,0x00,0x38,0x00,0x07,0xFF,0x00,0x00,0x7C,0x0C,0x00,0x1E,0x07,0x00,0x00,
0x00,0x0F,0x00,0x38,0x00,0xFF,0xFF,0x80,0x01,0xFC,0x0C,0x00,0x0E,0x07,0x00,0x00,
0x00,0x0E,0x3C,0x78,0x00,0x70,0x0F,0x00,0x03,0xF0,0x1C,0x00,0x0E,0x07,0x00,0x00,
0x00,0x1E,0x1E,0xF0,0x00,0x73,0xFF,0x00,0x07,0xE3,0xFC,0x00,0x0E,0x07,0xE0,0x00,
0x00,0x1F,0xFF,0xC0,0x00,0x7F,0xFE,0x00,0x00,0xE0,0xEC,0x00,0x0C,0x0F,0xF0,0x00,
0x00,0x3F,0xCF,0xE0,0x00,0x1C,0x0E,0x00,0x00,0xEC,0x0C,0x00,0x1F,0xFF,0x80,0x00,
0x00,0x3C,0x07,0xF8,0x00,0x18,0x1E,0x00,0x00,0xFE,0x0C,0x00,0xFF,0x3E,0x00,0x00,
0x00,0x63,0xFF,0xF8,0x00,0x3F,0xFC,0x00,0x1F,0xFF,0xEC,0x01,0xFC,0x0E,0x00,0x00,
0x00,0xFF,0xF8,0x70,0x00,0x1F,0xFC,0x00,0x3F,0xC0,0xEC,0x00,0x0C,0x07,0xC0,0x00,
0x00,0xFE,0x18,0xF0,0x00,0x00,0x33,0x00,0x3F,0xFC,0x0F,0xE0,0x0F,0x1F,0xE0,0x00,
0x01,0xCE,0x1F,0xE0,0x00,0x0E,0x73,0xC0,0x03,0xFC,0x3F,0xF0,0x0E,0xFF,0xC0,0x00,
0x01,0x8F,0xDE,0xC0,0x00,0x07,0x73,0xC0,0x07,0xE7,0xFC,0x40,0x3C,0x63,0xC0,0x00,
0x00,0x7F,0x8E,0xC0,0x01,0xC7,0x77,0x80,0x07,0xEF,0xFC,0x00,0xFC,0x73,0x80,0x00,
0x00,0xFE,0x0E,0xC0,0x00,0xFF,0x7F,0x00,0x0E,0xE0,0x1C,0x07,0xFC,0x3F,0x80,0x00,
0x00,0x0E,0x1E,0xC1,0x80,0xFE,0x7E,0x00,0x1C,0xE0,0x1C,0x07,0x9C,0x1F,0x00,0x00,
0x00,0x0C,0x98,0x83,0x80,0x7E,0x70,0x00,0x78,0xC0,0x1C,0x03,0x9C,0x0E,0x00,0x00,
0x00,0x0F,0xB8,0x83,0x80,0x3E,0x60,0x00,0x60,0xC0,0x1C,0x00,0x1C,0x0F,0xC0,0x00,
0x00,0x0F,0x70,0xC3,0x80,0x0E,0x7F,0xF0,0x00,0xC0,0x1C,0x00,0x1C,0x7D,0xF0,0x00,
0x00,0x3E,0xE0,0xFF,0xC1,0xFF,0xFF,0xF8,0x00,0xE0,0x0C,0x00,0x3D,0xF0,0x7E,0x00,
0x00,0x3D,0xC0,0x7F,0x8F,0xFF,0x80,0x00,0x00,0xE0,0x0C,0x00,0x7F,0xC0,0x7F,0x80,
0x00,0x18,0x00,0x3C,0x07,0x80,0x00,0x00,0x00,0x80,0x08,0x00,0x3C,0x00,0x3F,0x00,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x18,0x00,0x00,0x01,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,
};
/*------------------初始化-----------------*/
void init_lcd (void)
{
rst=0;
delay1 (900);
rst=1;
psb=1;
wr_lcd (comm,0x30); /*30---基本指令动作*/
wr_lcd (comm,0x01); /*清屏,地址指针指向00H*/
wr_lcd (comm,0x06); /*光标的移动方向*/
wr_lcd (comm,0x08); /*开显示,关游标*/
}
/*---------------显示汉字或字符----------------*/
void chn_disp (uchar code *chn)
{
uchar i,j;
wr_lcd (comm,0x30);
wr_lcd (comm,0x80);
for (j=0;j<4;j++)
{
for (i=0;i<16;i++)
wr_lcd (dat,chn[j*16+i]);
}
}
/*-----------上半屏显示汉字或字符------------*/
void chn_disp1 (uchar code *chn)
{
uchar i,j;
wr_lcd (comm,0x30);
wr_lcd (comm,0x80);
j=0;
for (i=0;i<16;i++)
wr_lcd (dat,chn[j*16+i]);
wr_lcd (comm,0x90);
j=1;
for (i=0;i<16;i++)
wr_lcd (dat,chn[j*16+i]);
}
/*----------------显示图形-----------------*/
void img_disp (uchar code *img)
{
uchar i,j;
for(j=0;j<32;j++)
{
for(i=0;i<8;i++)
{
wr_lcd (comm,0x34);
wr_lcd (comm,y+j);
wr_lcd (comm,x1+i);
wr_lcd (comm,0x30);
wr_lcd (dat,img[j*16+i*2]);
wr_lcd (dat,img[j*16+i*2+1]);
}
}
for(j=32;j<64;j++)
{
for(i=0;i<8;i++)
{
wr_lcd (comm,0x34);
wr_lcd (comm,y+j-32);
wr_lcd (comm,x2+i);
wr_lcd (comm,0x30);
wr_lcd (dat,img[j*16+i*2]);
wr_lcd (dat,img[j*16+i*2+1]);
}
}
wr_lcd (comm,0x36);
}
/*-------------下半屏显示图形--------------*/
void img_disp1 (uchar code *img)
{
uchar i,j;
for(j=0;j<32;j++)
{
for(i=0;i<8;i++)
{
wr_lcd (comm,0x34);
wr_lcd (comm,y+j);
wr_lcd (comm,x2+i);
wr_lcd (comm,0x30);
wr_lcd (dat,img[j*16+i*2]);
wr_lcd (dat,img[j*16+i*2+1]);
}
}
wr_lcd (comm,0x36);
}
/*--------------显示点阵----------------*/
void lat_disp (uchar data1,uchar data2)
{
uchar i,j,k,x;
x=x1;
for(k=0;k<2;k++)
{
for(j=0;j<16;j++)
{
for(i=0;i<8;i++)
{
wr_lcd (comm,0x34);
wr_lcd (comm,y+j*2);
wr_lcd (comm,x+i);
wr_lcd (comm,0x30);
wr_lcd (dat,data1);
wr_lcd (dat,data1);
}
for(i=0;i<8;i++)
{
wr_lcd (comm,0x34);
wr_lcd (comm,y+j*2+1);
wr_lcd (comm,x+i);
wr_lcd (comm,0x30);
wr_lcd (dat,data2);
wr_lcd (dat,data2);
}
}
x=x2;
}
wr_lcd (comm,0x36);
}
/*-----------------------------------------------*/
//当data1=0xff,data2=0xff时,在x0,y0处反白显示16xl*yl.
void con_disp (uchar data1,uchar data2,uchar x0,uchar y0,uchar xl,uchar yl)
{
uchar i,j;
for(j=0;j<yl;j++)
{
for(i=0;i<xl;i++)
{
wr_lcd (comm,0x34);
wr_lcd (comm,y0+j);
wr_lcd (comm,x0+i);
wr_lcd (comm,0x30);
wr_lcd (dat,data1);
wr_lcd (dat,data2);
}
}
wr_lcd (comm,0x36);
}
/*--------------清DDRAM------------------*/
void clrram (void)
{
wr_lcd (comm,0x30);
wr_lcd (comm,0x01);
}
/*---------------------------------------*/
void wr_lcd (uchar dat_comm,uchar content)
{
chk_busy ();
if(dat_comm)
{
rs=1; //data
rw=0; //write
}
else
{
rs=0; //command
rw=0; //write
}
P1=content; //output data or comm
e=1;
;
e=0;
}
void chk_busy (void)
{
P1=0xff;
rs=0;
rw=1;
e =1;
while(busy==1);
e =0;
}
void delay (uint us) //delay time
{
while(us--);
}
void delay1 (uint ms)
{
uint i,j;
for(i=0;i<ms;i++)
for(j=0;j<15;j++)
delay(1);
}
/*------------------主程序--------------------*/
void main ()
{
SP=0x5f;
init_lcd ();
while (1)
{
lat_disp (0x00,0x00);
chn_disp (tab1);
wr_lcd (comm,0x0f); //开光标
con_disp (0xff,0xff,0x82,0x90,2,16);//文字反白
wr_lcd (comm,0x8f); //光标位置
delay1 (5000);
wr_lcd (comm,0x30); //基本指令
wr_lcd (comm,0x08); //关光标
clrram(); //文字清屏
lat_disp (0xcc,0xcc);
delay1 (5000);
lat_disp (0x00,0x00);//图形清屏
lat_disp (0xff,0x00);
delay1 (5000);
img_disp (tab5);
delay1 (5000);
}
} |