这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 综合技术 » 基础知识 » RT12864 液晶模块RT12864如何显示汉字?

共2条 1/1 1 跳转至

RT12864 液晶模块RT12864如何显示汉字?

院士
2006-09-17 18:14:16     打赏
RT12864 液晶模块RT12864如何显示汉字?



关键词: RT12864     液晶     模块     如何     显示     汉字    

院士
2006-12-22 22:43:00     打赏
2楼
问   我采用串行方式与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条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]