找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3604|回复: 0
收起左侧

12864显示大字符汉字程序

[复制链接]
ID:125275 发表于 2016-9-14 11:09 | 显示全部楼层 |阅读模式
#include <reg52.h>
#include"intrins.h"
#define  uchar unsigned char
#define  uint  unsigned  int
sbit rs =P2^0;   // //数据\//指令//选择
sbit rw =P2^1;   // //读\写选择
sbit en =P2^2;   // 读\写使能  
sbit cs1 =P2^4;  // 片选1,低有效(前64列)
sbit cs2 =P2^5;  // 片选2,低有效(后64列)
void    lcdstate()
{
uchar  lcd=0x00; /*设置初值为0,全部为低,方便后面的判忙*/
rs=0; /*根据时序图拉低,选择写指令*/
rw=1; /*根据时序图拉低,选择写模式*/
do
{
en=1; /*使能,使液晶输出信号,检查是否忙*/
_nop_();_nop_();_nop_();_nop_();/*延时4US*/
lcd=P0; /*把P0口的状态值读回来给lcd*/
en=0; /*使能端跳变*/;
}while(lcd&0x80); /*结果的高位保留,如果高位DB7为一,则表示忙*/
}
void delay(uchar  ms)
{ uchar   i;
    uchar   j;
   for(i=0;i<100;i++)
    for(j=0;j<ms;j++);
}
void   write_command(uchar   command)
{
lcdstate();
   rs=0;                                //RS=0;为往MCU进行指令操作
   rw=0;                                //RW=0;为往MCU写入操作
   en=0;
   _nop_();_nop_();_nop_();_nop_();/*延时4US*/
   en=1;
   _nop_();_nop_();_nop_();_nop_();/*延时4US*/
   P0=command;
   _nop_();_nop_();_nop_();_nop_();/*延时4US*/
   en=0;
}
void   write_data(uchar   datas)
{  
    lcdstate();
    rs=1;
    rw=0;  
    en=0;
    _nop_();_nop_();_nop_();_nop_();/*延时4US*/
    en=1;
    _nop_();_nop_();_nop_();_nop_();/*延时4US*/
    P0=datas;
    _nop_();_nop_();_nop_();_nop_();/*延时4US*/
    en=0;
}
void   lcdinit()
{
     delay(100);                                         //
     cs1=1;
         cs2=1;
         delay(100);        
         lcdstate();                                 //
         write_command(0x3e);                 //
         write_command(0xb8+0);                         //
         write_command(0xc0+0);                 //
         write_command(0x40+0);                 //
         write_command(0x3f);                 
}
void clearScreen(  )
{   uchar i,j;
     lcdstate();
     cs1=1;
         cs2=1;
         write_command(0x3f);                        //设置显示开
         write_command(0xb8);                    //Y        设置第0页;
         write_command(0x40);                         //        设置第0列
    for(i=0;i<8;i++)
    {
      write_command(0xb8+i);
      for(j=0;j<64;j++)
      {
            //write_command(0x40+j);
        write_data(0x00);
            
      }
    }
}
unsigned char code    jin[128]=
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xF0,0xF8,0x7C,0x3C,0x7C,0xF8,0xE0,0xC0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x20,0x60,0x70,0x78,0x38,0x3C,0x7E,0x6F,0x67,0x67,0x63,0x61,0xE0,0xE0,0xE0,0xE0,0x61,0x63,0x63,0x67,0x6F,0x7E,0x7E,0x1C,0x3C,0x38,0x78,0x78,0x10,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0xD8,0xD8,0xD8,0x98,0x18,0x18,0xFF,0xFF,0xFF,0xFF,0x18,0x18,0x38,0xF8,0xD8,0xD8,0xD8,0x18,0x18,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x30,0x30,0x30,0x30,0x31,0x37,0x37,0x33,0x32,0x30,0x3F,0x3F,0x3F,0x3F,0x30,0x38,0x3F,0x3F,0x3F,0x33,0x30,0x30,0x30,0x30,0x30,0x00,0x00,0x00};/*"金",0*/
/* (32 X 32 , 黑体, 加粗 )*/
uchar code    se[128]=
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xF0,0xFC,0xFC,0xF8,0xC8,0xC8,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x10,0x30,0x38,0x3C,0xFE,0xFF,0xFF,0xF7,0x33,0x30,0x30,0x30,0x30,0xF0,0xF0,0xF8,0xFE,0x3F,0x3F,0x33,0x31,0x30,0xF0,0xF0,0xF0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x1C,0x1C,0x1C,0x1C,0x1C,0x1F,0x1F,0x1F,0x1F,0x1C,0x1C,0x1C,0x1C,0x1C,0x3F,0x3F,0x3F,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x1F,0x3F,0x3F,0x38,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x38,0x3E,0x1E,0x0C,0x00,0x00};/*"色",1*/
/* (32 X 32 , 黑体, 加粗 )*/
uchar code    tong[128]=
{0x00,0x00,0x00,0x00,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0xE0,0xE0,0x60,0x68,0x7C,0x7C,0x7C,0x60,0x60,0xE0,0xE0,0xE0,0x60,0x60,0x60,0x60,0x60,0x60,0x00,0x00,0x00,
0x00,0x00,0x00,0x04,0x04,0x04,0xE4,0xE4,0xE4,0x64,0x67,0x67,0x67,0x67,0x64,0xE4,0xE4,0xE4,0x64,0x67,0x67,0x67,0x65,0x64,0xE4,0xE4,0xE4,0x04,0x04,0x04,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x3F,0x3F,0x32,0x32,0x32,0x32,0x32,0x32,0xFF,0xFF,0xFF,0x32,0x32,0x32,0x32,0x32,0x32,0x3F,0x3F,0x3F,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x30,0x30,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x3F,0x3F,0x3F,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x30,0x30,0x00,0x00};/*"童",2*/
/* (32 X 32 , 黑体, 加粗 )*/
uchar code    nian[128]=
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xE0,0xF8,0xFC,0xFC,0x98,0x88,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x00,
0x00,0x00,0x20,0x30,0x78,0x7C,0x3F,0xDF,0xCF,0xC3,0xC1,0xC1,0xC1,0xC1,0xC1,0xC1,0xFF,0xFF,0xFF,0xFF,0xC1,0xC1,0xC1,0xC1,0xC1,0xC1,0xC1,0xC1,0x01,0x00,0x00,0x00,
0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0xFF,0xFF,0xFF,0xFF,0xC0,0xC0,0xC0,0xC0,0xC0,0xFF,0xFF,0xFF,0xFF,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x7F,0x7F,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};/*"年",3*/
/* (32 X 32 , 黑体, 加粗 )*/
void hz_display16(unsigned char pag, unsigned char col, unsigned char code *hzk)
{
         uchar j=0;
         uchar i=0;
         for(j=0;j<4;j++)                          //这里写四页
         {
                 write_command(0xb8+pag+j);          //page在这里就是从page表示的这页开始写起。
                 write_command(0x40+col);          //从列为col表示的列开始
                 for(i=0;i<32;i++)                           //这里写32列
                 write_data(hzk[32*j+i]);        //J为页,I,为第J行第I个数
         }
}
void main()
{
lcdinit();
clearScreen(  );
   
while(1)
{
   delay(2);
// hz_display16(0,0,xms[]);
    cs1=1;
     cs2=0;
   hz_display16(0,0,jin);
   hz_display16(0,32,se);
   cs1=0;cs2=1;
hz_display16(0,0,tong);
hz_display16(0,32,nian);
}
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表