我是靠谱客的博主 野性人生,最近开发中收集的这篇文章主要介绍STC51单片机33——液晶12864显示汉字,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

 

 
**********************************************************/
#include"reg51.h"
#define uchar unsigned char
#define uint unsigned int
sbit lcdrst=P3^0;
sbit cs2=P3^5;
sbit cs1=P3^4;
sbit  e=P3^2;
sbit rw=P3^3;
sbit rs=P3^1;
/************************************************
// 汉字字模表                                                          //
// 汉字库: 宋体16.dot 纵向取模下高位,数据排列:从左到右从上到下
************************************************/
uchar code hao[]={ 0x10,0x10,0xF0,0x1F,0x10,0xF0,0x80,0x82,
      0x82,0x82,0xE2,0x92,0x8A,0xC6,0x80,0x00,
      0x40,0x22,0x15,0x08,0x14,0x63,0x00,0x00,
      0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,};     //"好",
uchar code xue[]={ 0x40,0x30,0x11,0x96,0x90,0x90,0x91,0x96,
      0x90,0x90,0x98,0x14,0x13,0x50,0x30,0x00,
      0x04,0x04,0x04,0x04,0x04,0x44,0x84,0x7E,
      0x06,0x05,0x04,0x04,0x04,0x06,0x04,0x00,};        //"学",
uchar code xi[]={0x04,0x04,0x04,0x04,0x14,0x24,0xC4,0x04,
      0x04,0x04,0x84,0x04,0x04,0xFE,0x04,0x00,
      0x00,0x00,0x08,0x18,0x04,0x04,0x02,0x02,
      0x01,0x21,0x40,0x80,0x40,0x3F,0x00,0x00,};       //"习",
uchar code tian[]={0x40,0x42,0x42,0x42,0x42,0x42,0x42,0xFE,
      0x42,0x42,0x42,0x42,0x43,0x62,0x40,0x00,
      0x80,0x80,0x40,0x20,0x10,0x0C,0x03,0x00,
      0x03,0x0C,0x10,0x20,0x40,0xC0,0x40,0x00,};           //"天",
uchar code xiang[]={0x00,0xF8,0x08,0x08,0xCC,0x4A,0x49,0x48,
      0x48,0x48,0xE8,0x48,0x08,0xFC,0x08,0x00,
      0x00,0xFF,0x00,0x00,0x1F,0x08,0x08,0x08,
      0x08,0x08,0x1F,0x40,0x80,0x7F,0x00,0x00,};        //"向",
uchar code shang[]={ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
      0x20,0x20,0x20,0x30,0x20,0x00,0x00,0x00,
      0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x7F,
      0x40,0x40,0x40,0x40,0x40,0x60,0x40,0x00};        //"上",
uchar code dian[]={ 0x00,0xF8,0x48,0x48,0x48,0x48,0xFF,0x48,
      0x48,0x48,0x48,0xFC,0x08,0x00,0x00,0x00,
      0x00,0x07,0x02,0x02,0x02,0x02,0x3F,0x42,
      0x42,0x42,0x42,0x47,0x40,0x70,0x00,0x00,};        //"电",
uchar code zi[]={0x80,0x80,0x82,0x82,0x82,0x82,0x82,0xE2,
      0xA2,0x92,0x8A,0x86,0x80,0xC0,0x80,0x00,
      0x00,0x00,0x00,0x00,0x00,0x40,0x80,0x7F,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};        // "子",
uchar code lu[]={0x00,0xFE,0x42,0xC2,0x42,0x7F,0x12,0x08,
      0x8C,0x57,0x24,0x54,0x8C,0x84,0x80,0x00,
      0x40,0x7E,0x40,0x3F,0x22,0x22,0x01,0xFF,
      0x42,0x42,0x42,0x42,0x42,0xFF,0x02,0x00,};        //"路",
uchar code dan[]={0x00,0x00,0xF8,0x49,0x4A,0x4C,0x48,0xF8,
      0x48,0x4C,0x4A,0x49,0xFC,0x08,0x00,0x00,
      0x10,0x10,0x17,0x12,0x12,0x12,0x12,0xFF,
      0x12,0x12,0x12,0x12,0x13,0x18,0x10,0x00,};        //"单",
uchar code pian[]={0x00,0x00,0xFE,0x20,0x20,0x20,0x20,0x20,
      0x3F,0x20,0x20,0x20,0x20,0x30,0x20,0x00,
      0x80,0x40,0x3F,0x01,0x01,0x01,0x01,0x01,
      0x01,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,};        //"片",
uchar code ji[]={0x10,0x10,0xD0,0xFF,0x90,0x10,0x00,0xFC,
      0x04,0x04,0x04,0xFE,0x04,0x00,0x00,0x00,
      0x04,0x03,0x00,0xFF,0x80,0x41,0x20,0x1F,
      0x00,0x00,0x00,0x3F,0x40,0x40,0x70,0x00};        //"机",
/*************************************************
延时函数
**************************************************/
void delay(uchar z)
{
uchar i,j;
for(i=z;i>0;i--)
for(j=110;j>0;j--);
}
/********************************************
检查状态
*********************************************/
void checkbusy()
{
uchar dat;
rs=0;        //数据指令选择
rw=1;        //允许读
do
{
P2=0x00;     //清零P2口
delay(5);
e=1;
dat=P2;          //读P2口
e=0;
dat>>=7;     //仅当第7位为0时才可操作(判别busy信号)
}
while(!(dat==0x00));
}
/*************************************
写命令
***********************************/
void write_com(uchar com)
{
checkbusy();  //检查是否忙
rs=0;        //写命令
rw=0;
P2=com;
e=1;
e=0;
}
/*************************************
写数据
***********************************/
void write_data(uchar date)
{
checkbusy();    //检查是否忙
rs=1;        //写数据
rw=0;
P2=date;
e=1;
e=0;
}
/*************************************
显示汉字
***********************************/
void  hanzi(uchar  ye,uchar lie,uchar  *daima)
{
uchar i,j;
for(i=0;i<2;i++)
{
  write_com(0xb8+ye+i);               //    ye页与 ye+1页
  write_com(0x40+lie);               //确定初始行
  for(j=0;j<16;j++)
  {
    write_data(daima[i*16+j]);         //写数据(汉字)
    }
 }
 }
/*************************************
显示数字
***********************************/
void shuzi(uchar  ye,uchar lie,uchar  *daima)
{
uchar i,j;
for(i=0;i<2;i++)
{
  write_com(0xb8+ye+i);            //    ye页与 ye+1页
  write_com(0x40+lie);             //确定初始行
  for(j=0;j<8;j++)
  {
    write_data(daima[i*8+j]);       //写数据(数字)
    }
 }
 }
 /***************************************
清屏
 ***************************************/
void clearlcd()
{
uchar i,j;
cs1=0;              //清全屏  有cs1=0  cs2=0 与无    cs1=0  cs2=0   效果不同
cs2=0;    
for(i=0;i<8;i++)
  {
  write_com(0xb8+i);
  write_com(0x40);
  for(j=0;j<64;j++)
  write_data(0x00);
  }
}

/****************************************
初始化LCD
****************************************/
void init()
{
write_com(0x3e);      //关显示
delay(1);
write_com(0x3f);       //开显示
write_com(0xc0);       //行初始地址
write_com(0xb8);       //页初始地址
write_com(0x40);       //列初始地址
}
/****************************************
显示数据
****************************************/
void display()
{
cs1=0;            //左半屏 cs1=0   cs2=1
cs2=1;
hanzi(0,0,hao);
hanzi(0,16,hao);
hanzi(0,32,xue);
hanzi(0,48,xi);
cs1=1;            //右半屏 cs1=1   cs2=0
cs2=0;
hanzi(0,0,tian);
hanzi(0,16,tian);
hanzi(0,32,xiang);         // 如果清屏时加上cs1=0  cs2=0则可以不用,否则要加上
hanzi(0,48,shang);
cs1=0;
cs2=1;
hanzi(3,0,dian);
hanzi(3,16,zi);
hanzi(3,32,dian);
hanzi(3,48,lu);
cs1=1;
cs2=0;
hanzi(6,0,dan);
hanzi(6,16,pian);
hanzi(6,32,ji);

}

完整资料打包(含仿真):

STC51单片机33-液晶12864显示汉字-单片机文档类资源-CSDN下载

最后

以上就是野性人生为你收集整理的STC51单片机33——液晶12864显示汉字的全部内容,希望文章能够帮你解决STC51单片机33——液晶12864显示汉字所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(54)

评论列表共有 0 条评论

立即
投稿
返回
顶部