LCD12864程序

发布者:沭阳小黄同志最新更新时间:2016-08-06 来源: eefocus关键字:LCD12864程序 手机看文章 扫描二维码
随时随地手机看文章
希望对第一次接触液晶屏的人有一定帮助……………………

 

#include
#include                         // 声明了void _nop_(void)
#include

#define uchar unsigned char 
#define uint  unsigned int

#define DPORT  P3  // 命令数据输出端口 
sbit RS =P2^7 ;
sbit RW =P2^6 ; 
sbit E  =P2^5 ;
sbit CS2=P2^4 ; 
sbit CS1=P2^3 ;

#define disp_start  0xc0 //显示起始行设置.
#define page_add    0xb8 //页面地址设置.(第 0 页)
#define col_add     0x40 //列地址设置.  (第 0 列)
#define disp_on     0x3f //打开显示.     
#define disp_off    0x3e  //关闭显示.

/*--函数声明--*/
void Led_init(void);
void Lcd_clr(void);
void Wr_com(uchar);
void Wr_dat(uchar);
void Rstatue(void);
uchar Rdat(void);
void Display_ch(uchar,uchar,uchar*);      //  仅仅只能显示 16*16  汉字
void Position(uchar,uchar);
void Draw_ph(uchar,uchar*);               //  画 128*16 的图片 (占两页)
void Delay(uint);

/***********************************************************************************************/
/******************************  主  函  数  *****************************************/
void main(void)
{
 Delay(50);
 Led_init();     // LCD初始化
 Wr_com(disp_off);//关闭显示.
 Lcd_clr();    // LCD清屏
 Wr_com(disp_on); //打开显示.
 Delay(1000);

// Wr_com(disp_off);//关闭显示.
 Draw_ph(0,XTCSH);//  0 表示 页(<7);  XTCSH  图片首地址  (128*16)
// Wr_com(disp_on); //打开显示.
    Delay(6000);

 Lcd_clr();     // LCD清屏

 Wr_com(disp_off); //关闭显示.
 Draw_ph(2,ZZR);      
 Display_ch(4,65,WANG); // 5 表示 页(<8);  65 表示 列(<128)[相邻两个汉字列差为 16] ;WANG 显示汉字首地址
 Display_ch(4,81,XUE);
 Display_ch(4,97,FAN);
    Draw_ph(6,NYR);
    Wr_com(disp_on); //打开显示.

 while(1);
}

 


/**********************************************************************************************/
/*---------------------- LCD12864 显示部分 (控制芯片 KS0108 )---------------------------*/
/**********************************************************************************************/
/*----------------LCD初始化-------------------------------------*/
void Led_init(void)
{
 P2=0; 
 Wr_com(disp_start); //显示起始行设置.
 Wr_com(page_add); //页面地址设置.
 Wr_com(col_add); //列地址设置.
 Wr_com(disp_on); //打开显示.     
}
/*---------------------LCD清屏---------------------------------*/
void Lcd_clr(void)  
{
 uchar page,col;
 CS1=0;
 CS2=0;
 for (page=0;page<8;page++)
 {
  Wr_com(page_add | page);
  Wr_com(col_add);
  for (col=0;col<64;col++)  Wr_dat(0x00); //列地址自动加一.
 } 
}
/*---------------------写命令----------------------------------*/
void Wr_com(uchar c)
{
 Rstatue();      
 RS=0;
 RW=0;
 DPORT=c;        // "写"   (下降沿有效)
 E=1;
 E=0;
}
/*---------------------写数据----------------------------------*/
void Wr_dat(uchar c)
{
 Rstatue(); 
 RS=1;
 RW=0;
 DPORT=c;        // "写"   (下降沿有效)
 E=1;
 E=0;
}
/*----------------------读状态---------------------------------*/
void Rstatue(void)
{
 uchar data temp=0;
 DPORT=0xff;
 RS=0;
 RW=1;
 while(1)    // 有必要让 E 的上升沿在循环体中
 {
  E=0;
  temp=(DPORT&0x90);   // "读"   (上升沿有效)
  E=1;    
  if(temp==0)   break;
 }                            
 E=0;
}
/*-----------------------读数据--------------------------------*/
/*uchar Rdat(void)
{
 uchar data temp=0;
 Rstatue();
 RS=1;
 RW=1;
 temp=DPORT;             // "读"   (上升沿有效)
 E=0;
 E=1;
 return temp;
}
/*----------------------单个显示汉字程序( 16*16 )----------------------------*/
void Display_ch(uchar page,uchar col,uchar *p)
{
 uchar i,j,X,Y;
 X=page;
 Y=col;
 CS1=0;
 CS2=1;
 for(j=0;j<2;j++)
 {
  for(i=0;i<16;i++)
  {
   if(Y>63)         //  到了右便半屏幕       
   { 
    Y=Y-64 ;
    CS1=1  ;
    CS2=0  ; 
   } 
   if(i<1||Y!=0)   Position(X,Y); 
   Wr_dat(*p);     //  列 自动加 1
   Y++;
   p++;
  }
  X++;
  Y=col;
 }

 CS1=0;
 CS2=0;
}
/*---------------------定位显示坐标---------------------*/
void Position(uchar page,uchar col)
{
 uchar X,Y;                   // X 表示行, Y 表示列
 X= page | page_add  ;
 Y= col  | col_add   ;
 Wr_com(X) ;
 Wr_com(Y) ;
}
/*------------------ 画图程序(128*16 ; 二页) -------------------*/
void Draw_ph(uchar page,uchar *p)
{
 uchar i,j;
 uchar temp=page;
 for(j=0;j<2;j++)
 {
  CS1=0;     // 左半屏幕
  CS2=1;
  Wr_com(page_add|temp);
  Wr_com(col_add);
  for(i=0;i<64;i++)
  {
   Wr_dat(*p);     //  列 自动加 1
   p++;
  }
  
  CS1=1;     // 右半屏幕
  CS2=0;
  Wr_com(page_add|temp);
  Wr_com(col_add);
  for(i=0;i<64;i++)
  {
   Wr_dat(*p);     //  列 自动加 1
   p++;
  }
  temp++;
 } 

 CS1=0;
 CS2=0;
}
/*---------------------延时程序-------------------------*/
void Delay(uint delay)
{
 uchar data i;
 while(delay)
 {
  for(i=0;i<125;i++)  {;}
  delay--;
 }
}
/**********************************************************************************************/

 

 

/***************************************************************************************************************/
/*                              汉    字    字    模(下面代码保存为Zhiku.h文件)
/***************************************************************************************************************/
#define uchar unsigned char

// " 制作人: "
uchar code ZZR[]={ 0x00,0x50,0x4F,0x4A,0x48,0xFF,0x48,0x48,0x48,0x00,0xFC,0x00,0x00,0xFF,0x00,0x00,   //
     0x80,0x40,0x20,0xF8,0x07,0x22,0x18,0x0C,0xFB,0x48,0x48,0x48,0x68,0x48,0x08,0x00,
     0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x3F,0xC2,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,     // 
     0x00,0x00,0x3F,0x01,0x01,0xFF,0x21,0x61,0x3F,0x00,0x0F,0x40,0x80,0x7F,0x00,0x00,
     0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0xFF,0x04,0x04,0x04,0x04,0x06,0x04,0x00,
     0x00,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x01,0x06,0x0C,0x18,0x30,0x60,0x20,0x00,
     0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00  };
// 系统初始化
uchar code XTCSH[]={0x00,0x00,0x02,0x22,0xB2,0xAA,0x66,0x62,0x22,0x11,0x4D,0x81,0x01,0x01,0x00,0x00,
     0x20,0x30,0x2C,0xA3,0x60,0x10,0x84,0xC4,0xA4,0x9D,0x86,0x84,0xA4,0xC4,0x84,0x00,
     0x00,0x08,0x88,0xC9,0x2E,0x98,0x48,0x00,0x08,0x08,0xF8,0x08,0x08,0xFC,0x08,0x00,
     0x10,0x90,0x70,0x1F,0x12,0xF0,0x00,0x20,0x70,0x28,0x27,0x22,0x28,0x70,0x20,0x00,
     0x80,0x40,0x20,0xF8,0x07,0x02,0x00,0x00,0xFF,0xC0,0x60,0x30,0x1C,0x08,0x00,0x00,
     0x00,0x00,0xFC,0x08,0x08,0x08,0x08,0xFF,0x08,0x08,0x08,0x08,0xFC,0x08,0x00,0x00,
     0x00,0xC0,0xC0,0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,
     0x00,0xC0,0xC0,0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,
     0x00,0x40,0x21,0x13,0x09,0x05,0x41,0x81,0x7F,0x01,0x05,0x09,0x13,0x62,0x00,0x00,
     0x20,0x22,0x23,0x12,0x12,0x92,0x40,0x30,0x0F,0x00,0x00,0x3F,0x40,0x41,0x70,0x00,
     0x02,0x01,0x00,0x7F,0x01,0x02,0x44,0x20,0x10,0x0C,0x03,0x20,0x40,0x3F,0x00,0x00,
     0x40,0x21,0x12,0x0C,0x06,0x09,0x30,0x00,0x7F,0x21,0x21,0x21,0x21,0x7F,0x00,0x00,
     0x00,0x00,0x00,0x7F,0x00,0x04,0x02,0x01,0x3F,0x40,0x40,0x40,0x40,0x78,0x00,0x00,
     0x00,0x00,0x07,0x02,0x02,0x02,0x02,0xFF,0x02,0x02,0x02,0x02,0x07,0x00,0x00,0x00,
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, };
// 2008.08.16
uchar code NYR[]={ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
     0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,
     0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,
     0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
     0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
     0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,
     0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,
     0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,
     0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,
     0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00  };
// " 王 "
uchar code WANG[]={ 0x00,0x04,0x04,0x04,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0x04,0x86,0x04,0x00,0x00,
     0x40,0x40,0x41,0x41,0x41,0x41,0x41,0x7F,0x41,0x41,0x41,0x41,0x41,0x61,0x40,0x00  };
// " 雪 " 
uchar code XUE[]={  0x00,0x18,0x0A,0xAA,0xAA,0xAA,0x0A,0xFE,0x0A,0xAA,0xAA,0xAA,0x0A,0x18,0x08,0x00,
          0x00,0x00,0x42,0x4A,0x4A,0x4A,0x4A,0x4A,0x4A,0x4A,0x4A,0x4A,0xFE,0x00,0x00,0x00  };
// " 凡 "
uchar code FAN[]={ 0x00,0x00,0x00,0x00,0xFE,0x02,0x22,0x42,0x82,0x02,0xFE,0x00,0x00,0x00,0x00,0x00,
     0x00,0x40,0x20,0x10,0x0F,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,0x40,0x70,0x00     };



/**********************************************************************************************/

关键字:LCD12864程序 引用地址:LCD12864程序

上一篇:AT89S5X的ISP下载线制作
下一篇:单片机通讯程序

推荐阅读最新更新时间:2024-03-16 15:04

C8051F LCD12864程序
摘要: /********************************************************************************************************** File : LCD12864.c* Hardware Environment: DVK501 F320 EX* Build Environment : Silicon LABs 3 ... /******************************************************************************************************** * * F
[单片机]
LCD12864测试程序
LCD12864的控制器为ST7920,带中文字库与图形库,并口驱动。 #include reg52.h #include intrins.h #define uint unsigned int #define uchar unsigned char #define P0 P0 uchar co de table1 ={ Wallacer }; uchar co de table2 ={ 我喜欢单片机! }; uchar co de table3 ={ I Like MCU! }; uchar co de table4 ={ 河北科技师范学院 }; sbit lcd_rs=P1^0; sbit lcd_rw=P1^1; s
[单片机]
STC89C52+LCD12864+DS1302+DS18B20时钟原理图+源程序
STC89C52+LCD12864+DS1302 +DS18B20+PCB 时钟供大家学习。 电子智能时钟程序 单 片 机:STC89C52 晶 振:12MHz 时钟芯片:DS1302 液 晶 屏:LCD12864 时 间:2020年1月1日 LCD12864使用并口连接方式,PSB、RST接高电平 /*-------------------------------头文件---------------------------------------*/ #include reg52.h #include intrins.h
[单片机]
STC89C52+<font color='red'>LCD12864</font>+DS1302+DS18B20时钟原理图+源<font color='red'>程序</font>
小广播
添点儿料...
无论热点新闻、行业分析、技术干货……
设计资源 培训 开发板 精华推荐

最新单片机文章
何立民专栏 单片机及嵌入式宝典

北京航空航天大学教授,20余年来致力于单片机与嵌入式系统推广工作。

换一换 更多 相关热搜器件
随便看看
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved