一个汉字由16*16个像素点构成。
扫描顺序上下,然后到第2列再上下,一次类推。
显示结果:
参考文献:<<手把手教你学单片机c程序设计>> 下载地址:http://www.51hei.com/bbs/dpj-22812-1.html
主函数代码:
#include
#define uchar unsigned char
#define uint unsigned int
#define dataport P0 //数据口
sbit CS1=P2^4; //左显引脚
sbit CS2=P2^3; //右显引脚
sbit RST=P2^2; //复位引脚
sbit rs=P2^7; //数据或指令寄存器引脚
sbit rw=P2^6; //读或写操作引脚
sbit en=P2^5; //读写时能引脚
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); //设置X,Y方向
void dison_off(uchar k); //显示器开或关
void reset(); //复位
void lcd_init(); //显示器初始化
void lw(uchar x,uchar y,uchar dd); //将数据写入左右半屏
void display_hz(uchar xx,uchar yy,uchar n,uchar fb); //显示汉字函数
uchar code hz[]; //汉字字摸
#include "12864hh.h" //调用文件(函数库)
void main(void)
{
lcd_init();
delay(1000);
while(1)
{
display_hz(2,0,0,0); //display_hz( 显示列位置,显示页位置,显示第几个汉字,是否反显);
display_hz(4,0,1,0);
display_hz(6,0,2,0);
display_hz(8,0,3,0);
display_hz(10,0,4,0);
display_hz(2,4,5,0);
display_hz(4,4,6,0);
display_hz(6,4,7,0);
display_hz(8,4,8,0);
display_hz(10,4,9,0);
}
delay(60000);
}
//---------------------------------------------字形码------------------------------------------------------
uchar code hz[]={
0x20,0x04,0x20,0x04,0x22,0x42,0x22,0x82,0xFE,0x7F,0x21,0x01,0x21,0x01,0x20,0x10,
0x20,0x10,0xFF,0x08,0x20,0x07,0x22,0x1A,0xAC,0x21,0x20,0x40,0x20,0xF0,0x00,0x00,/*"我",0*/
0x00,0x40,0x40,0x20,0xB2,0xA0,0x96,0x90,0x9A,0x4C,0x92,0x47,0xF6,0x2A,0x9A,0x2A,
0x93,0x12,0x91,0x1A,0x99,0x26,0x97,0x22,0x91,0x40,0x90,0xC0,0x30,0x40,0x00,0x00,/*"爱",1*/
0x00,0x08,0x00,0x08,0xF8,0x0B,0x28,0x09,0x29,0x09,0x2E,0x09,0x2A,0x09,0xF8,0xFF,
0x28,0x09,0x2C,0x09,0x2B,0x09,0x2A,0x09,0xF8,0x0B,0x00,0x08,0x00,0x08,0x00,0x00,/*"单",2*/
0x00,0x80,0x00,0x40,0x00,0x30,0xFE,0x0F,0x10,0x01,0x10,0x01,0x10,0x01,0x10,0x01,
0x10,0x01,0x1F,0x01,0x10,0x01,0x10,0xFF,0x10,0x00,0x18,0x00,0x10,0x00,0x00,0x00,/*"片",3*/
0x08,0x04,0x08,0x03,0xC8,0x00,0xFF,0xFF,0x48,0x00,0x88,0x41,0x08,0x30,0x00,0x0C,
0xFE,0x03,0x02,0x00,0x02,0x00,0x02,0x00,0xFE,0x3F,0x00,0x40,0x00,0x78,0x00,0x00, /*机",4*/
[page]
0x00,0x00,0x00,0x10,0x04,0x10,0x04,0x10,0x04,0x10,0x04,0x10,0x04,0x10,0x04,0x10,
0x04,0x10,0x04,0x10,0x04,0x10,0x06,0x10,0x04,0x10,0x00,0x18,0x00,0x10,0x00,0x00,/*"二",0*/
0x00,0x04,0x0C,0x04,0x04,0x04,0x55,0x0A,0x55,0x0A,0x55,0x09,0x85,0x2A,0x7F,0xCC,
0x85,0x28,0x55,0x19,0x55,0x09,0x55,0x02,0x05,0x06,0x0C,0x02,0x04,0x02,0x00,0x00,/*"零",1*/
0x00,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,
0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0xC0,0x00,0x80,0x00,0x00,0x00,/*"一",2*/
0x00,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,
0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0xC0,0x00,0x80,0x00,0x00,0x00,/*"一",3*/
0x40,0x04,0x20,0x04,0x10,0x04,0x0C,0x04,0xE3,0x07,0x22,0x04,0x22,0x04,0x22,0x04,
0xFE,0xFF,0x22,0x04,0x22,0x04,0x22,0x04,0x22,0x04,0x02,0x04,0x00,0x04,0x00,0x00};/*"年",4*/
//---------------------------12864.h-----------函数库------------
void delay(unsigned long v) //延时子函数
{
while(v--);
}
void lcd_busy() //判断是否繁忙函数
{
rs=0;
rw=1;
dataport=0xff;
while(1)
{
en=1;
if(dataport<0x80)break; //并口最高位为1时表示芯片正在工作
en=0;
}
en=0;
}
void wcode(uchar c,uchar csl,uchar csr) //写指令函数
{
CS1=csl; //显示左屏变量
CS2=csr; //显示右屏变量
lcd_busy();
rs=0;
rw=0;
dataport=c;
en=1;
en=0;
}
void wdata(uchar c,uchar csl,uchar csr) //写数据子函数
{
CS1=csl;
CS2=csr;
lcd_busy();
rs=1;
rw=0;
dataport=c;
en=1;
en=0;
}
void lw(uchar x,uchar y,uchar dd) // 写1个字节进RAM函数
{
if(x>=64) //列大于64说明是右半屏操作
{
set_xy(x-64,y);
wdata(dd,0,1);
}
else
{ //否则左半屏
set_xy(x,y);
wdata(dd,1,0);
}
}
void set_startline(uchar i) //设置起始行
{
i=0xc0+i;
wcode(i,1,1);
}
void set_xy(uchar x,uchar y) //列,行定位函数
{
x=x+0x40;
y=y+0xb8;
wcode(x,1,1);
wcode(y,1,1);
}
void dison_off(uchar k) //液晶关,开函数
{
k=k+0x3e;
wcode(k,1,1);
}
void reset() //复位函数
{
RST=0;
delay(40);
RST=1;
delay(40);
}
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);
}
void display_hz(uchar xx, uchar yy, uchar n, uchar fb) //中文字显示函数 扫描方法采用逐列式
{
uchar i,dx;
for(i=0;i<16;i++) //一个汉字列扫描值
{dx=hz[2*i+n*32]; //汉字上半部分扫描
if(fb)dx=255-dx; //反显
lw(xx*8+i,yy,dx); //数据写入芯片
dx=hz[(2*i+1)+n*32]; //汉字下半部分扫描
if(fb)dx=255-dx; //反显
lw(xx*8+i,yy+1,dx); //数据写入芯片
}
}
上一篇:异或妙用
下一篇:C++ 函数重载例子
推荐阅读最新更新时间:2024-03-16 14:04