#include <reg51.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
#define Port P0 //LCD12864数据线
sbit RS=P1^0; // 数据指令 选择
sbit RW=P1^1; // 读写 选择
sbit EN=P1^2; // 读写使能
sbit cs1=P1^6; // 片选1
sbit cs2=P1^7; // 片选2
//sbit RST = P1^3;
/********************************/
/* 定义中文字库 */
/********************************/
uchar code Hzk[]={
/*-- 文字: 各 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x20,0x20,0x10,0x08,0x8F,0xB4,0x44,0x44,0xA4,0x9C,0x04,0x00,0x00,0x00,0x00,
0x02,0x02,0x02,0x01,0x7F,0x42,0x42,0x42,0x42,0x42,0x42,0x7F,0x01,0x03,0x01,0x00,
/*-- 文字: 位 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0xC0,0x30,0xEC,0x03,0x2A,0xC8,0x09,0x0A,0x0E,0x08,0xE8,0x48,0x08,0x00,0x00,
0x01,0x00,0x00,0x7F,0x20,0x20,0x20,0x27,0x20,0x30,0x2E,0x21,0x20,0x20,0x20,0x00,
/*-- 文字: 单 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0xF8,0x28,0x29,0x2E,0x2A,0xF8,0x28,0x2C,0x2B,0x2A,0xF8,0x00,0x00,0x00,
0x08,0x08,0x0B,0x09,0x09,0x09,0x09,0xFF,0x09,0x09,0x09,0x09,0x0B,0x08,0x08,0x00,
/*-- 文字: 机 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x08,0x08,0xC8,0xFF,0x48,0x88,0x08,0x00,0xFE,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,
0x04,0x03,0x00,0xFF,0x00,0x41,0x30,0x0C,0x03,0x00,0x00,0x00,0x3F,0x40,0x78,0x00,
/*-- 文字: 爱 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x40,0xB2,0x96,0x9A,0x92,0xF6,0x9A,0x93,0x91,0x99,0x97,0x91,0x90,0x30,0x00,
0x40,0x20,0xA0,0x90,0x4C,0x47,0x2A,0x2A,0x12,0x1A,0x26,0x22,0x40,0xC0,0x40,0x00,
/*-- 文字: 好 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x10,0x10,0xF0,0x1F,0x10,0xF0,0x80,0x82,0x82,0x82,0xF2,0x8A,0x86,0x82,0x80,0x00,
0x80,0x43,0x22,0x14,0x0C,0x73,0x20,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,
/*-- 文字: 者 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x20,0x24,0x24,0x24,0x24,0xA4,0xBF,0x64,0x24,0x34,0x28,0x26,0x24,0x20,0x00,
0x04,0x04,0x04,0x02,0x02,0xFF,0x49,0x49,0x49,0x49,0x49,0x49,0xFF,0x00,0x00,0x00,
/*-- 文字: 你 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
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,
/*-- 文字: 们 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x80,0x40,0xF0,0x1C,0x03,0xF0,0x01,0x0E,0x04,0x00,0x04,0x04,0x04,0xFC,0x00,0x00,
0x00,0x00,0x7F,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x20,0x40,0x3F,0x00,0x00,
/*-- 文字: 辛 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x80,0x84,0x84,0x94,0xA4,0xC4,0x85,0x86,0x84,0xC4,0xA4,0x94,0x84,0x84,0x80,0x00,
0x00,0x04,0x04,0x04,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x04,0x00,0x00,0x00,
/*-- 文字: 苦 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x40,0x44,0x44,0x44,0x44,0x5F,0x44,0xF4,0x44,0x44,0x5F,0x44,0x44,0x44,0x44,0x00,
0x00,0x00,0x00,0x7E,0x22,0x22,0x22,0x23,0x22,0x22,0x22,0x7E,0x00,0x00,0x00,0x00,
/*-- 文字: 了 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x02,0x02,0x02,0x02,0x02,0x02,0xF2,0x12,0x0A,0x0A,0x06,0x06,0x02,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*-- 文字: 希 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x20,0x20,0x30,0x30,0xA9,0x6A,0x3A,0x24,0xE4,0x2A,0x29,0x30,0x20,0x20,0x20,0x00,
0x08,0x04,0x02,0x01,0x3F,0x01,0x01,0x01,0xFF,0x01,0x21,0x61,0x3F,0x00,0x00,0x00,
/*-- 文字: 望 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x04,0x04,0xFC,0x85,0x46,0x24,0x04,0x80,0x7E,0x2A,0x2A,0xAA,0xAA,0xFE,0x00,0x00,
0x00,0x40,0x42,0x4A,0x4A,0x4A,0x4A,0x7E,0x4A,0x4A,0x4A,0x4A,0x4A,0x42,0x40,0x00,
/*-- 文字: 大 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x20,0x20,0x20,0x20,0x20,0x20,0xA0,0x7F,0xA0,0x20,0x20,0x20,0x20,0x20,0x20,0x00,
0x00,0x80,0x40,0x20,0x10,0x0C,0x03,0x00,0x01,0x06,0x08,0x30,0x60,0xC0,0x40,0x00,
/*-- 文字: 家 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x18,0x04,0x14,0x94,0x94,0xD5,0xB6,0x14,0x14,0x94,0x04,0x14,0x0C,0x04,0x00,
0x00,0x29,0x29,0x15,0x14,0x4A,0x89,0x44,0x3F,0x06,0x09,0x09,0x10,0x30,0x10,0x00,
/*-- 文字: 能 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x10,0xB8,0x97,0x92,0x90,0x94,0xB8,0x10,0x00,0x7F,0x48,0x48,0x44,0x74,0x20,0x00,
0x00,0xFF,0x0A,0x0A,0x4A,0x8A,0x7F,0x00,0x00,0x3F,0x44,0x44,0x42,0x72,0x20,0x00,
/*-- 文字: 多 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0x00,0x20,0x90,0x88,0x54,0x53,0xA2,0x22,0x12,0x0A,0x06,0x00,0x00,0x00,
0x00,0x81,0x89,0x89,0x44,0x44,0x42,0x25,0x29,0x11,0x11,0x09,0x05,0x03,0x01,0x00,
/*-- 文字: 多 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0x00,0x20,0x90,0x88,0x54,0x53,0xA2,0x22,0x12,0x0A,0x06,0x00,0x00,0x00,
0x00,0x81,0x89,0x89,0x44,0x44,0x42,0x25,0x29,0x11,0x11,0x09,0x05,0x03,0x01,0x00,
/*-- 文字: 交 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x08,0x88,0x48,0x38,0x28,0x09,0x0E,0x0C,0x08,0x98,0x28,0x68,0x48,0x08,0x00,
0x00,0x80,0x80,0x40,0x41,0x22,0x14,0x18,0x0C,0x16,0x23,0x61,0xC0,0x40,0x00,0x00,
/*-- 文字: 流 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x10,0x60,0x01,0x86,0x60,0x04,0x44,0x64,0x55,0x4E,0x44,0x64,0xC4,0x04,0x04,0x00,
0x04,0x04,0xFC,0x03,0x40,0x30,0x0F,0x00,0x00,0x7F,0x00,0x3F,0x40,0x40,0x70,0x00,
/*-- 文字: 学 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x40,0x30,0x10,0x12,0x5C,0x54,0x50,0x51,0x5E,0xD4,0x50,0x18,0x57,0x32,0x10,0x00,
0x00,0x02,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,0x02,0x02,0x02,0x02,0x02,0x02,0x00,
/*-- 文字: 习 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0x02,0x02,0x0A,0x12,0x22,0x62,0x02,0x82,0x82,0x42,0x02,0xFE,0x00,0x00,
0x00,0x00,0x04,0x0C,0x04,0x02,0x02,0x01,0x01,0x00,0x20,0x40,0x80,0x7F,0x00,0x00,
/*-- 文字: 24 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
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,
};
/****************************************/
/* 定义ASCII字库8列*16行 */
/****************************************/
uchar code Ezk[]={
/*-- 文字: Q --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,
/*-- 文字: Q --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,
/*-- 文字: 3 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,
/*-- 文字: 4 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,
/*-- 文字: 5 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,
/*-- 文字: 4 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,
/*-- 文字: 1 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,
/*-- 文字: 5 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,
/*-- 文字: 2 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,
/*-- 文字: 4 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,
/*-- 文字: 4 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,
/*-- 文字: --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*-- 文字: --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*-- 文字: --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*-- 文字: --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*-- 文字: --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*-- 文字: --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
/*状态检查,LCD是否忙*/
void Checkbusy()
{
uchar dat;//状态信息(判断是否忙)
RS=0; // 数据指令选择,D/I(RS)=“L” ,表示 DB7∽DB0 为显示指令数据
RW=1; //R/W=“H” ,E=“H”数据被读到DB7∽DB0
do{
Port=0x00;
EN=1; //EN下降源
_nop_(); //一个时钟延时
dat=Port;
EN=0;
dat=(0x80 & dat);
}while(!(dat==0x00)); //仅当第7位为0时才可操作(判别busy信号)
}
/*写命令到LCD中*/
Wcmd(uchar cmd)
{
Checkbusy();//状态检查,LCD是否忙
RS=0; //向LCD发送命令。RS=0写指令,RS=1写数据
RW=0;//R/W=“L” ,E=“H→L”数据被写到 IR 或 DR
Port=cmd; //com :命令
EN=1;//EN下降源
_nop_();
_nop_();
EN=0;
}
/*设置页 0xb8是页的首地址*/
void Setpage(uchar page)
{
page=0xb8|page; //1011 1xxx 0<=page<=7 设定页地址--X 0-7,8行为一页64/8=8,共8页
Wcmd(page);
}
/*设定显示开始行,0xc0是行的首地址*/
void Setx(uchar x)
{
x=0xc0|x; //1100 0000
Wcmd(x); //设置从哪行开始:0--63,一般从0 行开始显示
}
/*设定列地址--Y 0-63 ,0x40是列的首地址*/
void Sety(uchar y)
{
y=y&0x3f; //column最大值为64,越出 0=<column<=63
y= 0x40|y; //01xx xxxx
Wcmd(y);
}
/*开关显示,0x3f是开显示,0x3e是关显示*/
void SetOnOff(uchar onoff)
{
onoff=0x3e|onoff; //0011 111x,onoff只能为0或者1
Wcmd(onoff);
}
/*写显示数据 */
void Writedata(uchar dat)
{
Checkbusy();//状态检查,LCD是否忙
RS=1; //RS=0写指令,RS=1写数据
RW=0;////R/W=“L” ,E=“H→L”数据被写到 IR 或 DR
Port=dat;//dat:显示数据
EN=1; //EN下降源
_nop_();
_nop_();
EN=0;
}
/*选择屏幕screen: 0-全屏,1-左屏,2-右屏*/
void SelectScreen(uchar screen)
{
switch(screen)
{ case 0: cs1=0;//全屏
_nop_(); _nop_(); _nop_();
cs2=0;
_nop_(); _nop_(); _nop_();
break;
case 1: cs1=0;//左屏
_nop_(); _nop_(); _nop_();
cs2=1;
_nop_(); _nop_(); _nop_();
break;
case 2: cs1=1;//右屏
_nop_(); _nop_(); _nop_();
cs2=0;
_nop_(); _nop_(); _nop_();
break;
}
}
/*清屏screen: 0-全屏,1-左屏,2-右*/
void ClearScreen(uchar screen)
{
uchar i,j;
SelectScreen(screen);
for(i=0;i<8;i++) //控制页数0-7,共8页
{
Setpage(i);
Sety(0);
for(j=0;j<64;j++) //控制列数0-63,共64列
{
Writedata(0x00); //写点内容,列地址自动加1
}
}
}
/*延时程序*/
void delay(uint z)
{
uint i,j;
for(i=0; i<z; i++)
for(j = 0; j < 110; j++);
}
/*向上滚屏*//*这里用做滚动显示*/
/*void lcd_rol()
{
uint i;
for(i = 0; i < 64; i++)
{
cs1=0; // 片选1
SendCommandToLCD(0xc0+i);
cs1=1;
cs2=0;// 片选2
SendCommandToLCD(0xc0+62-i);
cs2=0; // 片选2
delay(6);
}
}
*/
/*初始化LCD*/
void InitLCD()
{
// RST=0;
//delay(10);
//RST=1;
// delay(10);
Checkbusy();
SelectScreen(0);
SetOnOff(0); //关显示
SelectScreen(0);
SetOnOff(1); //开显示
SelectScreen(0);
ClearScreen(0);//清屏
Setx(0); //开始行:0
}
/*显示全角汉字*/
void Display(uchar ss,uchar page,uchar y,uchar number)
{
int i; //选屏参数,pagr选页参数,column选列参数,number选第几汉字输出
SelectScreen(ss);
y=y&0x3f;
Setpage(page); //写上半页
Sety(y); //控制列
for(i=0;i<16;i++) //控制16列的数据输出
{
Writedata(Hzk[i+32*number]); //i+32*number汉字的前16个数据输出
}
Setpage(page+1); //写下半页
Sety(y); //控制列
for(i=0;i<16;i++) //控制16列的数据输出
{
Writedata(Hzk[i+32*number+16]); //i+32*number+16汉字的后16个数据输出
}
}
/*显示半角汉字和数字和字母*/
void Displayen(uchar ss,uchar page,uchar y,uchar number)
{
uint i;//选屏参数,pagr选页参数,column选列参数,number选第几汉字输出
SelectScreen(ss);
y=y&0x3f;
Setpage(page); //写上半页
Sety(y);
for(i=0;i<8;i++)
{
Writedata(Ezk[i+16*number]);
}
Setpage(page+1); //写下半页
Sety(y);
for(i=0;i<8;i++)
{
Writedata(Ezk[i+16*number+8]);
}
}
/*主函数*/
void main()
{
uint i;
InitLCD();//初始12864
ClearScreen(0);//清屏
Setx(0);//显示开始行
while(1)
{
//delay(1000);
// i=0;
/* // 可以单个显示
Display(2,0,0*16,0);//
Display(2,0,1*16,1);//
Display(2,0,2*16,2);//
Display(2,0,3*16,3);//
Display(1,0,4*16,4);//
Display(1,0,5*16,5);//
Display(1,0,6*16,6);//
可以多个显示,这里是4个一起显示*/
for(i=0;i<4;i++)
{
Display(2,0,i*16,i);//Display(选屏参数(cs0,cs1),pagr选页参数,column选列参数,number选第几汉字输出)
_nop_();
Display(1,0,i*16,i+4);
_nop_();
Display(2,0+2,i*16,i+8);
_nop_();
Display(1,0+2,i*16,i+12);
_nop_();
Display(2,0+2+2,i*16,i+16);
_nop_();
Display(1,0+2+2,i*16,i+20);
}
for(i=0;i<8;i++)
{
Displayen(2,0+2+2+2,i*8,i);
_nop_(); ;
Displayen(1,0+2+2+2,i*8,i+8);
}
// while(1);
}
/*这里用做滚动显示 while(1)
{
lcd_rol();
delay(1000);
} */
}
一周热门 更多>