找回密码
 注册会员
更新自动建库工具PCB Footprint Expert 2024.04 Pro / Library Expert 破解版

51+LCD显示汉字,仿真不能显示汉字

[复制链接]
admin 发表于 2012-9-2 11:32:54 | 显示全部楼层 |阅读模式

本文包含原理图、PCB、源代码、封装库、中英文PDF等资源

您需要 登录 才可以下载或查看,没有账号?注册会员

×
#include<REG51.H>
#define uchar unsigned char
#define uint unsigned int
sbit CS1 = P2^4;
sbit CS2 = P2^3;
sbit RS = P2^7;
sbit RW = P2^6;
sbit EN = P2^5;
sbit RST = P2^2;
#define DataPort P0
/*****************************************************/
void delay(unsigned long v);
void wcode(uchar c,uchar csl,uchar csr);
void wdata(uchar c,uchar csl,uchar csr);
void set_startline(uchar i);
void set_xy(uchar x,uchar y);
void dison_off(uchar o);
void reset();
void lcd_init(void);
void lw(uchar x,uchar y,uchar dd);
void display_hz(uchar x,uchar y,uchar n,uchar fb);
uchar code hz[];
/*****************************************************/
void main(void)
{
uchar loop;
lcd_init();
delay(1000);
while(1)
{

for(loop=0;loop<8;loop++)
{
display_hz(2*loop,0,loop,0);
display_hz(2*loop,0,loop,0);
display_hz(2*loop,0,loop,0);
display_hz(2*loop,0,loop,0);
display_hz(2*loop,0,loop,0);
display_hz(2*loop,0,loop,0);
display_hz(2*loop,0,loop,0);
display_hz(2*loop,0,loop,0);

}

for(loop=0;loop<8;loop++)
{
display_hz(2*loop,2,loop+8,0);
display_hz(2*loop,2,loop+8,0);
display_hz(2*loop,2,loop+8,0);
display_hz(2*loop,2,loop+8,0);
display_hz(2*loop,2,loop+8,0);
display_hz(2*loop,2,loop+8,0);
display_hz(2*loop,2,loop+8,0);
display_hz(2*loop,2,loop+8,0);

}

for(loop=0;loop<8;loop++)
{
display_hz(2*loop,4,loop+16,1);
display_hz(2*loop,4,loop+16,1);
display_hz(2*loop,4,loop+16,1);
display_hz(2*loop,4,loop+16,1);
display_hz(2*loop,4,loop+16,1);
display_hz(2*loop,4,loop+16,1);
display_hz(2*loop,4,loop+16,1);
display_hz(2*loop,4,loop+16,1);

}

for(loop=0;loop<8;loop++)
{
display_hz(2*loop,6,loop+24,1);
display_hz(2*loop,6,loop+24,1);
display_hz(2*loop,6,loop+24,1);
display_hz(2*loop,6,loop+24,1);
display_hz(2*loop,6,loop+24,1);
display_hz(2*loop,6,loop+24,1);
display_hz(2*loop,6,loop+24,1);
display_hz(2*loop,6,loop+24,1);

}
delay(1000);
}
}

/********************************************************************
延时函数
*******************************************************************/
void delay(unsigned long v)
{
while(v!=0)v--;
}

/**************************************************
判断LCM忙子函数
***************************************************/
void lcd_busy()
{
RS=0;
RW=1;
DataPort=0xff;
while(1)
{
EN=1;
if(DataPort<0x80)break;
EN=0;
}
EN=0;
}

/****************************************************
写LCM指令子函数
*****************************************************/
void wcode(uchar c,uchar csl,uchar csr)
{
CS1=csl; //C为指令,csl/csr为片选CS1/CS2
CS2=csr;
lcd_busy();
RS=0;
RW=0;
DataPort=c;
EN=1;
EN=0;
}

/*****************************************************
写LCM数据子函数
*******************************************************/
void wdata(uchar c,uchar csl,uchar csr)
{
CS1=csl; //C为数据,csl/csr为片选CS1/CS2
CS2=csr;
lcd_busy();
RS=1;
RW=0;
DataPort=c;
EN=1;
EN=0;

}

/********************************************************
设定起始行子函数
*********************************************************/
void set_startline(uchar i)
{
i=0xc0+i; //i为起始行数
wcode(i,1,1);

}

/********************************************************
定位x方向、y方向子函数
*********************************************************/
void set_xy(uchar x,uchar y)
{
x=x+0x40; //设定x列的指令代码
y=y+0xb8; //设定y页的指令代码
wcode(x,1,1);
wcode(y,1,1);

}

/**********************************************************
屏幕开户关闭子函数
***********************************************************/
void dison_off(uchar o)
{
o=o+0x3e; //o为1开,o为0关
wcode(o,1,1);

}

/************************************************************
复位子函数
*************************************************************/
void reset()
{
RST=0;
delay(20);
RST=1;
delay(20);

}

/**************************************************************
根据x、y地址定位,将数据写入LCM或右半屏子函数
**************************************************************/
void lw(uchar x,uchar y,uchar dd)
{
if(x>=64) //x/y为坐标,dd为数据
{
set_xy(x-64,y);
wdata(dd,0,1);

}
else
{
set_xy(x,y);
wdata(dd,1,0);

}
}

/****************************************************************
显示汉字子函数
****************************************************************/
void display_hz(uchar x,uchar y,uchar n,uchar fb)
{
uchar i,dx; //x/y为列、页定位值,N为字码表中的
for(i=0;i<16;i++) //第N个汉字,FB为反白显示选项
{
dx=hz[2*i+n*32];
if(fb)dx=255-dx;
lw(x*8+i,y,dx);
dx=hz[(2*i+1)+n*32];
if(fb)dx=255-dx;
lw(x*8+i,y+1,dx);
}

}

/******************************************************************
LCM初始化子函数
*******************************************************************/
void lcd_init(void)
{
uchar x,y;
reset();
set_startline(0);
dison_off(0);
for(y=0;y<8;y++)
{
for(x=0;x<128;x++)lw(x,y,0);

}
dison_off(1);
}

uchar code hz[]=
{
/*-- 文字: 朝 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x08,0x00,0x08,0x7C,0x7F,0x44,0x08,0x44,0x3E,0x44,0x22,0x7C,0x3E,0x44,0x22,0x44,
0x3E,0x7C,0x08,0x44,0xFF,0x44,0x08,0x44,0x08,0x84,0x08,0x94,0x09,0x08,0x00,0x00,

/*-- 文字: 辞 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x40,0x0C,0x20,0xF1,0xFE,0x10,0x00,0x10,0x84,0xFE,0x48,0x10,0x00,0x13,0xFE,
0x10,0x20,0x7C,0x20,0x45,0xFE,0x44,0x20,0x44,0x20,0x7C,0x20,0x44,0x20,0x00,0x20,

/*-- 文字: 白 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x02,0x00,0x02,0x00,0x04,0x00,0x3F,0xF8,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0x08,
0x3F,0xF8,0x20,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x3F,0xF8,0x20,0x08,0x00,0x00,

/*-- 文字: 帝 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x02,0x00,0x01,0x00,0x7F,0xFE,0x08,0x10,0x04,0x20,0x7F,0xFE,0x41,0x04,0x81,0x08,
0x1F,0xF0,0x11,0x10,0x11,0x10,0x11,0x10,0x11,0x50,0x11,0x20,0x01,0x00,0x01,0x00,

/*-- 文字: 彩 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x0F,0x00,0xF8,0x08,0x11,0x0C,0x49,0x90,0x2A,0x20,0x24,0x44,0x08,0x06,0xFF,0x88,
0x08,0x14,0x1C,0x26,0x1A,0x04,0x29,0x88,0x49,0x10,0x88,0x60,0x09,0x80,0x08,0x00,

/*-- 文字: 去 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x01,0x00,0x01,0x00,0x01,0x00,0x3F,0xFC,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,
0x7F,0xFE,0x02,0x00,0x06,0x00,0x08,0x20,0x10,0x10,0x3F,0xF8,0x10,0x10,0x00,0x00,

/*-- 文字: 间 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x20,0x00,0x13,0xFC,0x10,0x04,0x40,0x04,0x47,0xE4,0x44,0x24,0x44,0x24,0x47,0xE4,
0x44,0x24,0x44,0x24,0x47,0xE4,0x40,0x04,0x40,0x04,0x40,0x04,0x40,0x14,0x40,0x08,

/*-- 文字: , --*/
/*-- 宋体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,0x30,0x00,0x30,0x00,0x10,0x00,0x20,0x00,0x00,0x00,

/*-- 文字: 千 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x10,0x00,0xF8,0x3F,0x00,0x01,0x00,0x01,0x00,0x01,0x04,0xFF,0xFE,0x01,0x00,
0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x00,0x00,

/*-- 文字: 里 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x3F,0xF8,0x21,0x08,0x21,0x08,0x21,0x08,0x3F,0xF8,0x21,0x08,0x21,0x08,0x3F,0xF8,
0x01,0x00,0x01,0x00,0x3F,0xF8,0x01,0x00,0x01,0x00,0x01,0x00,0xFF,0xFE,0x00,0x00,

/*-- 文字: 江 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x20,0x00,0x10,0x00,0x13,0xFC,0x00,0x40,0x88,0x40,0x48,0x40,0x50,0x40,0x10,0x40,
0x10,0x40,0x20,0x40,0xE0,0x40,0x20,0x40,0x20,0x40,0x2F,0xFE,0x20,0x00,0x00,0x00,

/*-- 文字: 陵 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x40,0x78,0x40,0x4B,0xFC,0x50,0x40,0x57,0xFE,0x61,0x20,0x51,0x10,0x4A,0x8C,
0x48,0xF0,0x69,0x10,0x52,0xA0,0x44,0x40,0x40,0xA0,0x43,0x18,0x4C,0x0E,0x40,0x04,

/*-- 文字: 一 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x7F,0xFE,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

/*-- 文字: 日 --*/
/*-- 宋体12;
 楼主| admin 发表于 2012-9-2 11:32:58 | 显示全部楼层
此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0x1F,0xF0,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1F,0xF0,0x10,0x10,
0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1F,0xF0,0x10,0x10,0x00,0x00,0x00,0x00,

/*-- 文字: 还 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x40,0x00,0x27,0xFC,0x30,0x40,0x20,0x40,0x00,0x80,0x00,0x80,0xE1,0xA0,0x22,0x90,
0x24,0x88,0x28,0x8C,0x20,0x88,0x20,0x80,0x20,0x80,0x50,0x00,0x8F,0xFE,0x00,0x00,

/*-- 文字: 。 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x30,0x00,0x48,0x00,0x48,0x00,0x30,0x00,0x00,0x00,0x00,0x00,

/*-- 文字: 两 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x04,0xFF,0xFE,0x04,0x40,0x04,0x44,0x7F,0xFE,0x44,0x44,0x44,0x44,0x46,0x44,
0x49,0x64,0x48,0x94,0x50,0x94,0x61,0x04,0x42,0x04,0x40,0x14,0x40,0x08,0x00,0x00,

/*-- 文字: 岸 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x80,0x10,0x84,0x10,0x84,0x1F,0xFC,0x00,0x00,0x3F,0xFE,0x20,0x00,0x2F,0xFC,
0x20,0x80,0x20,0x80,0x3F,0xFE,0x20,0x80,0x20,0x80,0x40,0x80,0x80,0x80,0x00,0x80,

/*-- 文字: 猿 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x08,0x40,0x48,0x40,0x33,0xFC,0x30,0x40,0x57,0xFE,0x88,0x00,0x09,0xF8,0x19,0x08,
0x29,0xF8,0x48,0xC0,0x89,0x46,0x0B,0x28,0x0D,0x10,0x09,0x48,0x51,0x8E,0x21,0x04,

/*-- 文字: 声 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x01,0x00,0xFF,0xFE,0x01,0x00,0x01,0x00,0x7F,0xFC,0x00,0x00,0x3F,0xF8,0x21,0x08,
0x21,0x08,0x3F,0xF8,0x20,0x08,0x20,0x00,0x40,0x00,0x40,0x00,0x80,0x00,0x00,0x00,

/*-- 文字: 啼 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x80,0x00,0x44,0xF7,0xFE,0x91,0x08,0x90,0x90,0x97,0xFE,0x94,0x44,0x98,0x48,
0x93,0xF8,0xF2,0x48,0x92,0x48,0x82,0x48,0x02,0x68,0x02,0x50,0x00,0x40,0x00,0x40,

/*-- 文字: 不 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x04,0x7F,0xFE,0x01,0x80,0x01,0x00,0x01,0x00,0x01,0x00,0x03,0x60,0x05,0x30,
0x09,0x18,0x11,0x0C,0x21,0x08,0x41,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x00,0x00,

/*-- 文字: 住 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x09,0x00,0x08,0x80,0x10,0x48,0x17,0xFC,0x20,0x40,0x60,0x40,0xA0,0x40,0x20,0x48,
0x27,0xFC,0x20,0x40,0x20,0x40,0x20,0x40,0x20,0x44,0x2F,0xFE,0x20,0x00,0x00,0x00,

/*-- 文字: , --*/
/*-- 宋体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,0x30,0x00,0x30,0x00,0x10,0x00,0x20,0x00,0x00,0x00,

/*-- 文字: 轻 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x20,0x00,0x21,0xFC,0xFE,0x08,0x20,0x10,0x50,0x20,0x50,0x50,0x90,0x8C,0xFD,0x04,
0x13,0xFE,0x10,0x20,0x1C,0x20,0xF0,0x20,0x10,0x20,0x10,0x20,0x17,0xFE,0x10,0x00,

/*-- 文字: 舟 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x01,0x00,0x02,0x00,0x0F,0xF0,0x08,0x10,0x09,0x10,0x08,0x90,0x08,0x10,0xFF,0xFE,
0x08,0x10,0x0A,0x10,0x09,0x90,0x08,0x90,0x10,0x10,0x10,0x10,0x20,0x50,0x40,0x20,

/*-- 文字: 已 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0x3F,0xF0,0x00,0x10,0x00,0x10,0x00,0x10,0x20,0x10,0x3F,0xF0,0x20,0x00,
0x20,0x00,0x20,0x00,0x20,0x04,0x20,0x04,0x20,0x06,0x3F,0xFC,0x00,0x00,0x00,0x00,

/*-- 文字: 过 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x40,0x10,0x20,0x10,0x30,0x10,0x20,0x10,0x07,0xFE,0x00,0x10,0x02,0x10,0xE1,0x10,
0x21,0x90,0x21,0x10,0x20,0x10,0x20,0x50,0x20,0x20,0x58,0x00,0x87,0xFE,0x00,0x00,

/*-- 文字: 万 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0x7F,0xFE,0x02,0x00,0x02,0x00,0x02,0x10,0x03,0xF8,0x02,0x10,0x04,0x10,
0x04,0x10,0x04,0x10,0x08,0x10,0x08,0x10,0x10,0x10,0x20,0xE0,0x40,0x40,0x00,0x00,

/*-- 文字: 重 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x01,0xF0,0x3F,0x00,0x01,0x00,0xFF,0xFE,0x01,0x00,0x1F,0xF0,0x11,0x10,0x1F,0xF0,
0x11,0x10,0x1F,0xF0,0x01,0x00,0x3F,0xF8,0x01,0x00,0x01,0x00,0xFF,0xFE,0x00,0x00,

/*-- 文字: 山 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x21,0x04,0x21,0x04,0x21,0x04,
0x21,0x04,0x21,0x04,0x21,0x04,0x21,0x04,0x21,0x04,0x7F,0xFC,0x20,0x04,0x00,0x00,

/*-- 文字: 。 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x30,0x00,0x48,0x00,0x48,0x00,0x30,0x00,0x00,0x00,0x00,0x00

};

5_80455_9cc3617e0db7145.jpg
*滑块验证:
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

QQ|手机版|MCU资讯论坛 ( 京ICP备18035221号-2 )|网站地图

GMT+8, 2024-11-24 20:48 , Processed in 0.059277 second(s), 12 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表