发布时间:2018-03-26 浏览量:
#include
#define uint unsigned int
#define uchar unsigned char
sbit cs2=P2^0;
sbit cs1=P2^1;
sbit e=P2^2;
sbit rw=P2^3;
sbit rs=P2^4;
uchar code zifu[]=
{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//,0
0x00,0x00,0x58,0x38,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,//。1
0x00,0x18,0x24,0x24,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//!2
0x00,0x00,0x00,0x5F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
uchar code ziku[]=
{
//0x80,0x40,0xF0,0x2C,0x43,0x20,0x98,0x0F,0x0A,0xE8,0x08,0x88,0x28,0x1C,0x08,0x00,//"你",
//0x00,0x00,0x7F,0x00,0x10,0x0C,0x03,0x21,0x40,0x3F,0x00,0x00,0x03,0x1C,0x08,0x00,
0x80,0x84,0x44,0x44,0x24,0x14,0x04,0xFF,0x04,0x14,0x24,0x24,0x46,0xC4,0x40,0x00,//"李",0 汉字后面的数字表示汉字的代号,方便使用
0x00,0x08,0x08,0x08,0x09,0x49,0x89,0x7D,0x0D,0x0B,0x09,0x08,0x0C,0x08,0x00,0x00,
0x10,0x10,0x10,0xFF,0x90,0x50,0xFE,0x92,0x92,0x92,0x92,0x92,0x9A,0xD3,0x82,0x00,//"振",1
0x02,0x42,0x81,0x7F,0x40,0x30,0x0F,0x00,0xFF,0x40,0x07,0x18,0x28,0x64,0x22,0x00,
0x80,0x40,0x20,0xF8,0x07,0x48,0x48,0x48,0x48,0xFF,0x48,0x48,0x68,0x4C,0x08,0x00,//"伟",2
0x00,0x00,0x00,0xFF,0x02,0x02,0x02,0x02,0x02,0xFF,0x02,0x12,0x22,0x1F,0x02,0x00,
0x00,0x00,0x00,0xC0,0x70,0x20,0x00,0xFF,0x00,0x10,0x20,0xC0,0x80,0x00,0x00,0x00,//小3
0x04,0x02,0x01,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x01,0x07,0x02,0x00,
0x00,0x04,0x84,0x44,0x3C,0x44,0x85,0x06,0x04,0xC4,0x3C,0x44,0x84,0x04,0x00,0x00,//卒4
0x04,0x05,0x04,0x04,0x04,0x04,0x05,0xFE,0x05,0x04,0x04,0x04,0x05,0x04,0x04,0x00,
0x40,0x41,0xCE,0x04,0x00,0x80,0x40,0xBE,0x82,0x82,0x82,0xBE,0xC0,0x40,0x40,0x00,//设5
0x00,0x00,0x7F,0x20,0x90,0x80,0x40,0x43,0x2C,0x10,0x10,0x2C,0x43,0xC0,0x40,0x00,
0x20,0x21,0x2E,0xE4,0x00,0x00,0x20,0x20,0x20,0x20,0xFF,0x20,0x20,0x20,0x20,0x00,//计6
0x00,0x00,0x00,0x7F,0x20,0x10,0x08,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//,7
0x00,0x00,0x58,0x38,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,//。8
0x00,0x18,0x24,0x24,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//!9
0x00,0x00,0x00,0x5F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
/*void delay(uchar i) //1ms延时函数
{
uchar a,b;
for(b=i;b>0;b--)
for(a=110;a>0;a--);
}*/
void lcd12864_busy() //忙标志位函数
{
uchar i;
rw=1;
rs=0;
while(1)
{
P0=0xff;
e=1;
//i=P0;
e=0;
i=P0;
i=i&0x80;
if(i!=0x80)
break;
}
}
lcd12864_writedat(uchar dat) //写数据函数
{
//lcd12864_busy();
rw=0;
rs=1;
e=1;
P0=dat;
e=0;
}
lcd12864_writecom(uchar com) //写命令函数
{
//lcd12864_busy();
rw=0;
rs=0;
e=1;
P0=com;
e=0;
}
void lcd12864_init() //初始化函数
{
lcd12864_writecom(0x3f);//开显示 关显示为0x3e
lcd12864_writecom(0xb8);//设置页地址为0.第一页。
lcd12864_writecom(0xc0);//设置显示起始行地址,为第一行显示到液晶屏上
lcd12864_writecom(0x40);//设置列地址
}
lcd12864_pxy(uchar p,uchar x,uchar y) //数据的位置,p=0左半屏,p=1右半屏,p=2两半屏全选,xy为显示的坐标,第四象限,用正值表示。
{
switch(p)
{
case 0:cs1=0;cs2=1;break;
case 1:cs1=1;cs2=0;break;
case 2:cs1=0;cs2=0;break;
}
lcd12864_writecom(0xb8+y);
lcd12864_writecom(0x40+x);
}
lcd12864_zifu(uchar p,uchar x,uchar y,uchar m) //第m个字符的显示位置,与测字的定义一样,只是xy的坐标的值应小于等于7.
{
uchar i;
lcd12864_pxy(p,x*8,y);
for(i=0;i<8;i++)
{
lcd12864_writedat(zifu[i+m*8]);
}
}
lcd12864_hanzi(uchar p,uchar x,uchar y,uchar m) //第m个汉字的显示位置,p=0左半屏,p=1右半屏,p=2两半屏全选,xy为显示的坐标,第四象限,用正值表示,x或y的值都应小于等于3。m为显示的第m个汉字。
{
uchar i;
lcd12864_pxy(p,x*16,2*y);
for(i=0;i<16;i++)
lcd12864_writedat(ziku[i+m*32]);
lcd12864_pxy(p,x*16,2*y+1);
for(i=0;i<16;i++)
lcd12864_writedat(ziku[i+m*32+16]);
}
void lcd12864_clear() //清屏函数
{
uint i;
lcd12864_pxy(2,0,0); //清左右两屏的第一、二、三、四页
for(i=0;i<256;i++)
{
lcd12864_writedat(0x00);
}
lcd12864_pxy(2,0,4); //清左右两屏的第五、六、七、八页
for(i=0;i<256;i++)
{
lcd12864_writedat(0x00);
}
}
#include
#include"lcd12864.h"
void main()
{
lcd12864_init();
lcd12864_clear();
lcd12864_hanzi(0,0,0,0);//李
lcd12864_hanzi(0,1,0,1);//振
lcd12864_hanzi(0,2,0,2);//伟
lcd12864_hanzi(0,3,0,8);// 。
lcd12864_hanzi(0,0,2,3);//小
lcd12864_hanzi(0,1,2,4);//卒
lcd12864_hanzi(0,2,2,5);//设
lcd12864_hanzi(0,3,2,6);//计
lcd12864_hanzi(1,0,2,9);//!
lcd12864_zifu(1,6,6,8); //!的左上部 分开以字符的形式显示
lcd12864_zifu(1,7,6,9); //!的右上部
lcd12864_zifu(1,6,7,10);//!的左下部
lcd12864_zifu(1,7,7,11);//!的右下部
while(1);
}