共2条
1/1 1 跳转至页
RT12864 液晶模块RT12864如何显示汉字?
问
我采用串行方式与LCD进行通信,按照说明书写的程序,但是只能显示一个光标在第一个字符位置(我设置显示光标),不显示字符什么的。
请问如何显示汉字?这个液晶模块是带中文字库的,每个汉字的偏移地址是2个字节(比如A123),不知道怎么写入。请用过的高手指点一二。 答 1: 成熟产品中的原码,自己编制./*
*********************************************
Copyright (c) 2004
All rights reserved.
文件名称:ST7920.C
文件标示:液晶显示屏(带字库)处理程序
摘 要:
版 本:1.0
设计公司:
作 者:WAYNE
完成日期:2004年8月
*********************************************
*/
#include <intrins.h>
#define L_SCK P1_0
#define L_SI P1_1
#define L_EN P1_6
#define L_RST T1
#define LOW 0
#define HIGH 1
unsigned char lcd_readcmd(void)
{
register unsigned char i;
register unsigned char temp;
L_EN = LOW;
L_SI = LOW;
L_SCK = LOW;
L_EN = HIGH;
// 11111 100
L_SI = HIGH;
for (i=0;i<5;i++){L_SCK = HIGH;L_SCK = LOW;}
L_SI = HIGH;
L_SCK = HIGH;L_SCK = LOW;
L_SI = LOW;
L_SCK = HIGH;L_SCK = LOW;
L_SI = LOW;
L_SCK = HIGH;L_SCK = LOW;
temp = 0;
for (i=0;i<8;i++)
{
L_SCK = HIGH;
temp <<=1;
temp |= L_SI;
L_SCK = LOW;
}
temp >>= 4;
for (i=0;i<4;i++)
{
L_SCK = HIGH;
temp <<=1;
temp |= L_SI;
L_SCK = LOW;
}
for (i=0;i<4;i++)
{
L_SCK = HIGH;L_SCK = LOW;
}
L_EN = LOW;
L_SI = LOW;
L_SCK = LOW;
return temp;
}
void lcd_writecmd(unsigned char lcddata)
{
unsigned char lcdopt;
register unsigned char i;
register unsigned char temp;
EA=0;
L_EN = LOW;
L_SI = LOW;
L_SCK = LOW;
L_EN = HIGH;
// 11111 000
L_SI = HIGH;
for (i=0;i<5;i++){L_SCK = HIGH;L_SCK = LOW;}
L_SI = LOW;
L_SCK = HIGH;L_SCK = LOW;
L_SI = LOW;
L_SCK = HIGH;L_SCK = LOW;
L_SI = LOW;
L_SCK = HIGH;L_SCK = LOW;
// HHHH000
temp = lcddata&0xf0;
for (i=0;i<8;i++)
{
L_SI = (temp&0x80)?HIGH:LOW;
temp <<=1;
L_SCK = HIGH;L_SCK = LOW;
}
// LLLL0000
temp = (lcddata<<4)&0xf0;
for (i=0;i<8;i++)
{
L_SI = (temp&0x80)?HIGH:LOW;
temp <<=1;
L_SCK = HIGH;L_SCK = LOW;
}
L_EN = LOW;
L_SI = LOW;
L_SCK = LOW;
lcdopt = 0;
do
{
lcdopt = lcd_readcmd();
}while (lcdopt&0x80);
EA=1;
}
void lcd_writedata(unsigned char lcddata)
{
register unsigned char temp;
register unsigned char i;
unsigned char lcdopt;
EA=0;
L_EN = LOW;
L_SI = LOW;
L_SCK = LOW;
L_EN = HIGH;
// 11111 010
L_SI = HIGH;
for (i=0;i<5;i++){L_SCK = HIGH;L_SCK = LOW;}
L_SI = LOW;
L_SCK = HIGH;L_SCK = LOW;
L_SI = HIGH;
L_SCK = HIGH;L_SCK = LOW;
L_SI = LOW;
L_SCK = HIGH;L_SCK = LOW;
// HHHH000
temp = (lcddata)&0xf0;
for (i=0;i<8;i++)
{
L_SI = (temp&0x80)?HIGH:LOW;
temp <<=1;
L_SCK = HIGH;L_SCK = LOW;
}
// LLLL0000
temp = ((lcddata)<<4)&0xf0;
for (i=0;i<8;i++)
{
L_SI = (temp&0x80)?HIGH:LOW;
temp <<=1;
L_SCK = HIGH;L_SCK = LOW;
}
L_EN = LOW;
L_SI = LOW;
L_SCK = LOW;
lcdopt = 0;
do
{
lcdopt = lcd_readcmd();
}while (lcdopt&0x80);
EA=1;
}
void lcd_cmd(unsigned char cmd,unsigned char opt)
{
switch (cmd)
{
//基本指令 //扩展指令
case 0:lcd_writecmd(0x01);break; //清除 //待命模式
case 1:lcd_writecmd(0x02);break; //位址归位 //卷动位址或RAM位址选择
case 2:opt&=0x03;lcd_writecmd(0x04|opt);break; //进入点设定 //反白选择
case 3:opt&=0x07;lcd_writecmd(0x08|opt);break; //显示状态 //睡眠模式
case 4:opt&=0x0f;lcd_writecmd(0x10|opt);break; //游标或显示移位控制 //扩充功能设定
case 5:opt&=0x1f;lcd_writecmd(0x20|opt);break; //功能设定 //设定ICONRAM位址或卷动位址
case 6:opt&=0x3f;lcd_writecmd(0x40|opt);break; //CGRAM位址 //设定绘图RAM位址
case 7:opt&=0x3f;lcd_writecmd(0x80|opt);break; //DDRAM位址
}
}
void lcd_home(void)
{
lcd_cmd(1,0);
lcd_cmd(2,0x02);
// os_wait2(K_TMO,1);
}
void lcd_init(void)
{
L_RST = HIGH;
lcd_cmd(5,0x10);
lcd_cmd(5,0x10);
lcd_cmd(3,0x04);
lcd_cmd(2,0x02);
lcd_cmd(0,0);
// os_wait2(K_TMO,1);
}
void lcd_writestr(unsigned char l_line,unsigned char l_site,unsigned char * words)
{
// l_line:行0-3; l_site:列 0-7; words:中英字符
unsigned char c;
c = 0;
l_site = l_site % 8;
if (l_line>1)
{
l_line = l_line % 2;
l_site = l_site + 8;
}
l_site = (l_line<<4) + l_site;
lcd_cmd(7,l_site);
while(*words != 0)
{
unsigned char tempdata;
tempdata = *words;
lcd_writedata(tempdata);
words++;
l_site++;
c++;
}
if (c%2)
{
lcd_writedata(0x20);
}
}
//------------------------------------
其他模块调用方法:
lcd_init();//初始化,开机调用一次
lcd_home();
lcd_writestr(0,0,"┏━━━━━━┓");
lcd_writestr(1,0,"┃ 设备维护 ┃");
lcd_writestr(2,0,"┃ 暂停使用 ┃");
lcd_writestr(3,0,"┗━━━━━━┛");
答 2: 多谢,回去参考一下现在感觉我自己用万用板和漆包线连的板子有问题 答 3: 用过信利的一块儿液晶用过一块信利的液晶,也是带字库,12864,不知是否一样。你的显示的地址对么?
请问如何显示汉字?这个液晶模块是带中文字库的,每个汉字的偏移地址是2个字节(比如A123),不知道怎么写入。请用过的高手指点一二。 答 1: 成熟产品中的原码,自己编制./*
*********************************************
Copyright (c) 2004
All rights reserved.
文件名称:ST7920.C
文件标示:液晶显示屏(带字库)处理程序
摘 要:
版 本:1.0
设计公司:
作 者:WAYNE
完成日期:2004年8月
*********************************************
*/
#include <intrins.h>
#define L_SCK P1_0
#define L_SI P1_1
#define L_EN P1_6
#define L_RST T1
#define LOW 0
#define HIGH 1
unsigned char lcd_readcmd(void)
{
register unsigned char i;
register unsigned char temp;
L_EN = LOW;
L_SI = LOW;
L_SCK = LOW;
L_EN = HIGH;
// 11111 100
L_SI = HIGH;
for (i=0;i<5;i++){L_SCK = HIGH;L_SCK = LOW;}
L_SI = HIGH;
L_SCK = HIGH;L_SCK = LOW;
L_SI = LOW;
L_SCK = HIGH;L_SCK = LOW;
L_SI = LOW;
L_SCK = HIGH;L_SCK = LOW;
temp = 0;
for (i=0;i<8;i++)
{
L_SCK = HIGH;
temp <<=1;
temp |= L_SI;
L_SCK = LOW;
}
temp >>= 4;
for (i=0;i<4;i++)
{
L_SCK = HIGH;
temp <<=1;
temp |= L_SI;
L_SCK = LOW;
}
for (i=0;i<4;i++)
{
L_SCK = HIGH;L_SCK = LOW;
}
L_EN = LOW;
L_SI = LOW;
L_SCK = LOW;
return temp;
}
void lcd_writecmd(unsigned char lcddata)
{
unsigned char lcdopt;
register unsigned char i;
register unsigned char temp;
EA=0;
L_EN = LOW;
L_SI = LOW;
L_SCK = LOW;
L_EN = HIGH;
// 11111 000
L_SI = HIGH;
for (i=0;i<5;i++){L_SCK = HIGH;L_SCK = LOW;}
L_SI = LOW;
L_SCK = HIGH;L_SCK = LOW;
L_SI = LOW;
L_SCK = HIGH;L_SCK = LOW;
L_SI = LOW;
L_SCK = HIGH;L_SCK = LOW;
// HHHH000
temp = lcddata&0xf0;
for (i=0;i<8;i++)
{
L_SI = (temp&0x80)?HIGH:LOW;
temp <<=1;
L_SCK = HIGH;L_SCK = LOW;
}
// LLLL0000
temp = (lcddata<<4)&0xf0;
for (i=0;i<8;i++)
{
L_SI = (temp&0x80)?HIGH:LOW;
temp <<=1;
L_SCK = HIGH;L_SCK = LOW;
}
L_EN = LOW;
L_SI = LOW;
L_SCK = LOW;
lcdopt = 0;
do
{
lcdopt = lcd_readcmd();
}while (lcdopt&0x80);
EA=1;
}
void lcd_writedata(unsigned char lcddata)
{
register unsigned char temp;
register unsigned char i;
unsigned char lcdopt;
EA=0;
L_EN = LOW;
L_SI = LOW;
L_SCK = LOW;
L_EN = HIGH;
// 11111 010
L_SI = HIGH;
for (i=0;i<5;i++){L_SCK = HIGH;L_SCK = LOW;}
L_SI = LOW;
L_SCK = HIGH;L_SCK = LOW;
L_SI = HIGH;
L_SCK = HIGH;L_SCK = LOW;
L_SI = LOW;
L_SCK = HIGH;L_SCK = LOW;
// HHHH000
temp = (lcddata)&0xf0;
for (i=0;i<8;i++)
{
L_SI = (temp&0x80)?HIGH:LOW;
temp <<=1;
L_SCK = HIGH;L_SCK = LOW;
}
// LLLL0000
temp = ((lcddata)<<4)&0xf0;
for (i=0;i<8;i++)
{
L_SI = (temp&0x80)?HIGH:LOW;
temp <<=1;
L_SCK = HIGH;L_SCK = LOW;
}
L_EN = LOW;
L_SI = LOW;
L_SCK = LOW;
lcdopt = 0;
do
{
lcdopt = lcd_readcmd();
}while (lcdopt&0x80);
EA=1;
}
void lcd_cmd(unsigned char cmd,unsigned char opt)
{
switch (cmd)
{
//基本指令 //扩展指令
case 0:lcd_writecmd(0x01);break; //清除 //待命模式
case 1:lcd_writecmd(0x02);break; //位址归位 //卷动位址或RAM位址选择
case 2:opt&=0x03;lcd_writecmd(0x04|opt);break; //进入点设定 //反白选择
case 3:opt&=0x07;lcd_writecmd(0x08|opt);break; //显示状态 //睡眠模式
case 4:opt&=0x0f;lcd_writecmd(0x10|opt);break; //游标或显示移位控制 //扩充功能设定
case 5:opt&=0x1f;lcd_writecmd(0x20|opt);break; //功能设定 //设定ICONRAM位址或卷动位址
case 6:opt&=0x3f;lcd_writecmd(0x40|opt);break; //CGRAM位址 //设定绘图RAM位址
case 7:opt&=0x3f;lcd_writecmd(0x80|opt);break; //DDRAM位址
}
}
void lcd_home(void)
{
lcd_cmd(1,0);
lcd_cmd(2,0x02);
// os_wait2(K_TMO,1);
}
void lcd_init(void)
{
L_RST = HIGH;
lcd_cmd(5,0x10);
lcd_cmd(5,0x10);
lcd_cmd(3,0x04);
lcd_cmd(2,0x02);
lcd_cmd(0,0);
// os_wait2(K_TMO,1);
}
void lcd_writestr(unsigned char l_line,unsigned char l_site,unsigned char * words)
{
// l_line:行0-3; l_site:列 0-7; words:中英字符
unsigned char c;
c = 0;
l_site = l_site % 8;
if (l_line>1)
{
l_line = l_line % 2;
l_site = l_site + 8;
}
l_site = (l_line<<4) + l_site;
lcd_cmd(7,l_site);
while(*words != 0)
{
unsigned char tempdata;
tempdata = *words;
lcd_writedata(tempdata);
words++;
l_site++;
c++;
}
if (c%2)
{
lcd_writedata(0x20);
}
}
//------------------------------------
其他模块调用方法:
lcd_init();//初始化,开机调用一次
lcd_home();
lcd_writestr(0,0,"┏━━━━━━┓");
lcd_writestr(1,0,"┃ 设备维护 ┃");
lcd_writestr(2,0,"┃ 暂停使用 ┃");
lcd_writestr(3,0,"┗━━━━━━┛");
答 2: 多谢,回去参考一下现在感觉我自己用万用板和漆包线连的板子有问题 答 3: 用过信利的一块儿液晶用过一块信利的液晶,也是带字库,12864,不知是否一样。你的显示的地址对么?
共2条
1/1 1 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
vscode+cmake搭建雅特力AT32L021开发环境被打赏30分 | |
【换取逻辑分析仪】自制底板并驱动ArduinoNanoRP2040ConnectLCD扩展板被打赏47分 | |
【分享评测,赢取加热台】RISC-V GCC 内嵌汇编使用被打赏38分 | |
【换取逻辑分析仪】-基于ADI单片机MAX78000的简易MP3音乐播放器被打赏48分 | |
我想要一部加热台+树莓派PICO驱动AHT10被打赏38分 | |
【换取逻辑分析仪】-硬件SPI驱动OLED屏幕被打赏36分 | |
换逻辑分析仪+上下拉与多路选择器被打赏29分 | |
Let'sdo第3期任务合集被打赏50分 | |
换逻辑分析仪+Verilog三态门被打赏27分 | |
换逻辑分析仪+Verilog多输出门被打赏24分 |