任务描述:单片机连接无字库的12864模块,利用给定的程序模板和点阵取模软件,编程显示一首诗词。
首先要会使用点阵取模软件:
选择默认16*16,点确定。
在文字输入区输入文字。
左键选择字体。
结束输入时按下ctrl+enter。
取模方式选择c51。
前面几个可以,后面的不行。行不行看生成的是几行,两行就可以,其他不行。下面这种就不行。
/*************************
项目名称:项目三简易计算器
任务名称:任务4-5利用12864显示诗词
任务描述:单片机连接无字库的12864模块,利用给定的程序模板和点阵取模软件,编程显示一首诗词。
*************************/
//51单片机寄存器定义头文件
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
/*****************定义汉字数组**************************/
uchar code ren[]={
0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x3F,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x80,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x00,0x03,0x0C,0x10,0x20,0x40,0x80,0x00,};// 人
uchar code sheng[]={
0x80,0x40,0x30,0x1E,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,
0x40,0x40,0x42,0x42,0x42,0x42,0x42,0x7F,0x42,0x42,0x42,0x42,0x42,0x40,0x40,0x00,};//生
uchar code de[]={
0x00,0x10,0x88,0xC4,0x33,0x00,0xBE,0xAA,0xAA,0xAA,0xAA,0xAA,0xBE,0x80,0x00,0x00,
0x02,0x01,0x00,0xFF,0x00,0x02,0x0A,0x12,0x02,0x42,0x82,0x7F,0x02,0x02,0x02,0x00,};//得
uchar code yi[]={
0x10,0x10,0x12,0xD2,0x56,0x5A,0x52,0x53,0x52,0x5A,0x56,0xD2,0x12,0x10,0x10,0x00,
0x40,0x30,0x00,0x77,0x85,0x85,0x8D,0xB5,0x85,0x85,0x85,0xE7,0x00,0x10,0x60,0x00,};//意
uchar code xu[]={
0x20,0x10,0x08,0x84,0x63,0x00,0x00,0xF2,0x12,0x1A,0xD6,0x12,0x12,0xF2,0x02,0x00,
0x84,0x42,0x21,0x10,0x08,0x06,0x80,0x4F,0x20,0x18,0x07,0x10,0x20,0x4F,0x80,0x00,};//须
uchar code jin[]={
0x00,0x00,0x00,0xFE,0x22,0x22,0x22,0x22,0x22,0xE2,0x22,0x22,0x7E,0x00,0x00,0x00,
0x10,0x08,0x06,0x01,0x10,0x10,0x22,0x22,0x44,0x80,0x01,0x02,0x04,0x08,0x08,0x00,};//尽
uchar code huan[]={
0x04,0x24,0x44,0x84,0x64,0x9C,0x40,0x30,0x0F,0xC8,0x08,0x08,0x28,0x18,0x00,0x00,
0x10,0x08,0x06,0x01,0x82,0x4C,0x20,0x18,0x06,0x01,0x06,0x18,0x20,0x40,0x80,0x00,};//欢
uchar code dou1[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x58,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};//,
uchar code mou[]={
0x04,0x04,0x04,0xE4,0xAF,0xA4,0xA4,0xA4,0xA4,0xA4,0xAF,0xE4,0x04,0x04,0x04,0x00,
0x80,0x88,0x88,0x4B,0x4A,0x2A,0x1A,0x0E,0x1A,0x2A,0x4A,0x4B,0x88,0x88,0x80,0x00,};//莫
uchar code shi[]={
0x80,0x60,0xF8,0x07,0x04,0xE4,0x24,0x24,0x24,0xFF,0x24,0x24,0x24,0xE4,0x04,0x00,
0x00,0x00,0xFF,0x00,0x80,0x81,0x45,0x29,0x11,0x2F,0x41,0x41,0x81,0x81,0x80,0x00,};//使
uchar code jin1[]={
0x80,0x80,0x40,0x20,0x50,0x48,0x44,0xC3,0x44,0x48,0x50,0x20,0x40,0x80,0x80,0x00,
0x40,0x40,0x42,0x4A,0x72,0x42,0x42,0x7F,0x42,0x42,0x62,0x5A,0x42,0x40,0x40,0x00,};//金
uchar code zun[]={
0x10,0x10,0xD0,0xFF,0x90,0x10,0x04,0xF4,0x55,0xBE,0x94,0xBE,0x55,0xF4,0x04,0x00,
0x04,0x03,0x00,0xFF,0x00,0x03,0x08,0x1B,0x6A,0x0A,0x4A,0x8A,0x7E,0x0B,0x08,0x00,};//樽
uchar code kong[]={
0x10,0x0C,0x44,0x24,0x14,0x04,0x05,0x06,0x04,0x04,0x14,0x24,0x44,0x14,0x0C,0x00,
0x00,0x40,0x40,0x41,0x41,0x41,0x41,0x7F,0x41,0x41,0x41,0x41,0x40,0x40,0x00,0x00,};//空
uchar code dui[]={
0x00,0x08,0x48,0x88,0x08,0xC8,0x38,0x00,0x90,0x10,0x10,0xFF,0x10,0x10,0x10,0x00,
0x00,0x20,0x10,0x0C,0x03,0x04,0x18,0x00,0x00,0x43,0x80,0x7F,0x00,0x00,0x00,0x00,};//对
uchar code yue[]={
0x00,0x00,0x00,0xFE,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0xFE,0x00,0x00,0x00,
0x80,0x40,0x30,0x0F,0x02,0x02,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,0x00,0x00,0x00,};//月
uchar code juhao1[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x18,0x24,0x24,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};//。
uchar code tian[]={
0x40,0x40,0x42,0x42,0x42,0x42,0x42,0xFE,0x42,0x42,0x42,0x42,0x42,0x40,0x40,0x00,
0x80,0x80,0x40,0x20,0x10,0x0C,0x03,0x00,0x03,0x0C,0x10,0x20,0x40,0x80,0x80,0x00,};//天
uchar code sheng1[]={
0x80,0x40,0x30,0x1E,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,
0x40,0x40,0x42,0x42,0x42,0x42,0x42,0x7F,0x42,0x42,0x42,0x42,0x42,0x40,0x40,0x00,};//生
uchar code wo[]={
0x20,0x24,0x24,0x24,0xFE,0x23,0x22,0x20,0x20,0xFF,0x20,0x22,0x2C,0xA0,0x20,0x00,
0x00,0x08,0x48,0x84,0x7F,0x02,0x41,0x40,0x20,0x13,0x0C,0x14,0x22,0x41,0xF8,0x00,};//我
uchar code cai[]={
0x10,0x10,0x10,0xD0,0xFF,0x90,0x10,0x00,0x10,0x10,0x10,0xD0,0xFF,0x10,0x10,0x00,
0x08,0x04,0x03,0x00,0xFF,0x00,0x03,0x00,0x08,0x04,0x43,0x80,0x7F,0x00,0x00,0x00,};//材
uchar code bi[]={
0x00,0x00,0xC0,0x00,0xE0,0x02,0x04,0x18,0x00,0xC0,0x30,0x0C,0x40,0x80,0x00,0x00,
0x08,0x86,0x41,0x20,0x3F,0x48,0x44,0x42,0x41,0x40,0x40,0x78,0x00,0x01,0x0E,0x00,};//必
uchar code you[]={
0x04,0x04,0x04,0x84,0xE4,0x3C,0x27,0x24,0x24,0x24,0x24,0xE4,0x04,0x04,0x04,0x00,
0x04,0x02,0x01,0x00,0xFF,0x09,0x09,0x09,0x09,0x49,0x89,0x7F,0x00,0x00,0x00,0x00,};//有
uchar code yong[]={
0x00,0x00,0xFE,0x22,0x22,0x22,0x22,0xFE,0x22,0x22,0x22,0x22,0xFE,0x00,0x00,0x00,
0x80,0x60,0x1F,0x02,0x02,0x02,0x02,0x7F,0x02,0x02,0x42,0x82,0x7F,0x00,0x00,0x00,};//用
uchar code dou2[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x58,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};//,
uchar code qian[]={
0x80,0x80,0x84,0x84,0x84,0x84,0x84,0xFC,0x82,0x82,0x82,0x83,0x82,0x80,0x80,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};//千
uchar code jin2[]={
0x80,0x80,0x40,0x20,0x50,0x48,0x44,0xC3,0x44,0x48,0x50,0x20,0x40,0x80,0x80,0x00,
0x40,0x40,0x42,0x4A,0x72,0x42,0x42,0x7F,0x42,0x42,0x62,0x5A,0x42,0x40,0x40,0x00,};//金
uchar code san[]={
0x20,0xA4,0xBF,0xA4,0xA4,0xBF,0xA4,0x20,0x80,0x70,0x8F,0x08,0x08,0xF8,0x08,0x00,
0x00,0xFF,0x0A,0x0A,0x4A,0x8A,0x7F,0x00,0x80,0x40,0x33,0x0C,0x33,0x40,0x80,0x00,};//散
uchar code jin3[]={
0x00,0x00,0x00,0xFE,0x22,0x22,0x22,0x22,0x22,0xE2,0x22,0x22,0x7E,0x00,0x00,0x00,
0x10,0x08,0x06,0x01,0x10,0x10,0x22,0x22,0x44,0x80,0x01,0x02,0x04,0x08,0x08,0x00,};//尽
uchar code huan1[]={
0x40,0x40,0x42,0xCC,0x00,0x00,0x02,0x82,0x42,0xF2,0x0E,0x42,0x82,0x02,0x00,0x00,
0x00,0x40,0x20,0x1F,0x20,0x42,0x41,0x40,0x40,0x5F,0x40,0x40,0x40,0x43,0x40,0x00,};//还
uchar code fu[]={
0x20,0x10,0x08,0xF7,0x54,0x54,0x54,0x54,0x54,0x54,0x54,0xF4,0x04,0x04,0x00,0x00,
0x80,0x90,0x90,0x49,0x4D,0x57,0x25,0x25,0x25,0x55,0x4D,0x45,0x80,0x80,0x80,0x00,};//复
uchar code lai[]={
0x00,0x08,0x08,0x28,0xC8,0x08,0x08,0xFF,0x08,0x08,0x88,0x68,0x08,0x08,0x00,0x00,
0x21,0x21,0x11,0x11,0x09,0x05,0x03,0xFF,0x03,0x05,0x09,0x11,0x11,0x21,0x21,0x00,};//来
uchar code juhao2[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x18,0x24,0x24,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};//。
/*************************************************/
sbit CS1=P2^0;//片选1,低电平有效,CS1=0开左屏幕,CS1=1关左屏幕
sbit CS2=P2^1;//片选2,低电平有效,CS2=0开右屏幕,CS2=1关右屏幕
sbit RS=P2^2;//数据,指令选择信号,RS=1为数据操作,RS=0为写指令或读状态(一般为读忙标志)
sbit RW=P2^3;//读写选择信号,RW=1为读选通,RW=0为写选通
sbit EN=P2^4;//读写使能信号
void busy()//忙检测函数
{P0=0X00; //这句不能少
RS=0;
RW=1;
EN=1;
while(P0&0X80);//P0&0X80结果为真则一直执行空操作,也就是说P0&0X80为0则结束循环
EN=0;
}
void wcmd(uchar cmd)
{busy(); //每次写入指令或数据之前都进行忙检测
RS=0;
RW=0;
P0=cmd;
EN=1;_nop_();_nop_();//在EN下降沿写入数据和指令
EN=0;
}
void wdata(uchar dat) //写命令和写数据只在RS=0或RS=1上不同,其余都相同
{busy();
RS=1;
RW=0;
P0=dat;
EN=1;_nop_();_nop_();//在EN下降沿写入数据和指令
EN=0;
}
void set_page(uchar page)//设置页,12864LCD共有8页,每页有8行点阵点。
{page=0xb8|page; //首页地址为0XB8
wcmd(page); //page取值范围为0~7,表示第1到8页
}
void set_line(uchar line)//设置显示的起始行,共有0--63行,一般从0行开始显示
{line=0xc0|line; //起始行地址0XC0
wcmd(line); //line取值范围为0~63,表示第1到64行
}
void set_column(uchar column)//设置显示的列
{//column=column&0x3f; //列的最大值为0X3F,即64
column=0x40|column; //列的首地址为0X40,
wcmd(column); //column的取值范围为0~63,共64列
}
void set_onoff(uchar onoff)//设置显示开关,onoff取值为0或1
{onoff|=0x3e;//0X3E是关显示,0X3F是开显示
wcmd(onoff);//所以若onoff为0,则表示关显示,onoff为1,则表示开显示
}
void select_screen(uchar screen)//选屏,screen取值范围为0,1,2
{switch(screen)
{case 0:CS1=0;CS2=0;break; //全屏
case 1:CS1=0;CS2=1;break; //左半屏
case 2:CS1=1;CS2=0;break; //右半屏
default:break;
}
}
void clear_screen(uchar screen)//清屏
{uchar i,j;
select_screen(screen);//先选屏
for(i=0;i<8;i++)//控制页数0--7,共8页
{set_page(i);//设置页
set_column(0); //设置列,每页都从第1列开始,共64列
for(j=0;j<64;j++)//控制列数0--63,共64列
wdata(0x00);//写入0,列地址指针会自动加1
}
}
void init() //LCD初始化
{busy(); //忙检测
select_screen(0);//选屏,全屏
set_onoff(0); //关显示
select_screen(0); //选屏,全屏
set_onoff(1); //开显示
select_screen(0); //选屏,全屏
clear_screen(0); //清屏
set_line(0); //起始行:0
}
void show(uchar screen,uchar page,uchar column,uchar *p)//显示一个汉字,一个汉字有32字节数据
{uchar i; //screen表示选择屏幕,page表示页,column表示列,*p表示汉字的数组
select_screen(screen); //选屏
set_page(page); //设置页,写上半页
set_column(column);//设置列
for(i=0;i<16;i++) //控制16列的数据输出
wdata(p[i]); //汉字的上半部分
set_page(page+1); //写下半页
set_column(column); //控制列
for(i=0;i<16;i++) //控制16列的数据输出
wdata(p[i+16]); //汉字的下半部分
}
void main()
{init(); //LCD初始化
clear_screen(0); //清屏
set_line(0); //显示开始行
/***************************************
show函数参数说明:
参数1:左右屏选择,1-左屏显示 2-右屏显示
参数2:行数选择 0-第一行 2-第二行 4-第三行 6-第四行
参数3:列数选择 0*16-位置1 1*16-位置2 2*16-位置3 3*16-位置4
参数4:汉字数组名
****************************************/
show(1,0,0*16,ren);
show(1,0,1*16,sheng);
show(1,0,2*16,de);
show(1,0,3*16,yi);
show(2,0,0*16,xu);
show(2,0,1*16,jin);
show(2,0,2*16,huan);
show(2,0,3*16,dou1);
show(1,2,0*16,mou);
show(1,2,1*16,shi);
show(1,2,2*16,jin1);
show(1,2,3*16,zun);
show(2,2,0*16,kong);
show(2,2,1*16,dui);
show(2,2,2*16,yue);
show(2,2,3*16,juhao1);
show(1,4,0*16,tian);
show(1,4,1*16,sheng1);
show(1,4,2*16,wo);
show(1,4,3*16,cai);
show(2,4,0*16,bi);
show(2,4,1*16,you);
show(2,4,2*16,yong);
show(2,4,3*16,dou2);
show(1,6,0*16,qian);
show(1,6,1*16,jin2);
show(1,6,2*16,san);
show(1,6,3*16,jin3);
show(2,6,0*16,huan1);
show(2,6,1*16,fu);
show(2,6,2*16,lai);
show(2,6,3*16,juhao2);
while(1);
}
效果如下: