本例程为通过用AT89C52芯片操作LCD12864显示的程序,使用的晶振为12M。
/********************************************************** 程序说明:LCD12864显示主程序 程序调试员:莫剑辉 调试时间:2010-6-7
**********************************************************/
#include
/********************************************************** 程序说明:LCD12864显示头文件 程序调试员:莫剑辉 调试时间:2010-6-7
**********************************************************/ //#include
#define uchar unsigned char #define uint unsigned int
#define DATA P2 //数据输出端0~7 sbit RS=P0^0; //LCD12864 RS端 sbit RW=P0^1; //LCD12864 RW端 sbit E =P0^2; //LCD12864 E 端 sbit PSB =P0^3;
/********************************************* 延时子程序
*********************************************/ void Delay_1ms(uint x) {  uint j,i;   for(j=0;j /*********************************************   LCD12864液晶测忙子程序(读状态)  *********************************************/ void Busy()   {   uchar busy;   do  {      E = 0;      //0为关闭使能端,1为打开使能端      RS = 0;      //1为指令,0为数据      RW = 1;    //1为读,0为写       Delay_1ms(20);  //延时20乘以120时间      E = 1;     //0为关闭使能端,1为打开使能端      busy=P1;    //读取P2状态      Delay_1ms(20);  //延时20乘以120时间      E = 0;    //0为关闭使能端,1为打开使能端     }  while(busy&0x80);  //判断BUSY位是否工作:1为内部在工作,0为正常状态 }  /*********************************************   LCD12864液晶数据写入子程序  *********************************************/ void Write_Data(uchar k) {   Busy();   //测忙    E =1;   //0为关闭使能端,1为打开使能端    RS=1;   //1为指令,0为数据    RW=0;   //1为读,0为写    DATA=k;   //输入数据K到DATA    Delay_1ms(20); //延时20乘以120时间    E =0;    //0为关闭使能端,1为打开使能端    Delay_1ms(20);   //延时20乘以120时间 }  /*********************************************   LCD12864液晶命令写入子程序  *********************************************/ void Write_Cmd(uchar cmd) {      Busy();    //测忙     E=1;   //0为关闭使能端,1为打开使能端     RS=0;    //1为指令,0为数据     RW=0;   //1为读,0为写     DATA=cmd;    //输入命令cmd到DATA     Delay_1ms(20); //延时20乘以120时间      E=0;   //0为关闭使能端,1为打开使能端     Delay_1ms(20); //延时20乘以120时间 }  /*********************************************   LCD12864液晶数据显示子程序  *********************************************/ void Disp(uchar y,uchar x,uchar i,uchar *z)   {     uchar Address;    if(y==1){Address=0x80+x;}     //Y判断第几行,X判断第几列,0x80为液晶行初始地址    if(y==2){Address=0x90+x;}        if(y==3){Address=0x88+x;}    if(y==4){Address=0x98+x;}  Write_Cmd(Address);     //写入地址命令到LCD12864  while(i)       //写入显示数据的大小  {    Write_Data(*(z++));    //写入显示数据到LCD12864    i--;         }   }  /*********************************************   LCD12864液晶初始化子程序  *********************************************/ void Ini_Lcd(void)     {     PSB=1;      Delay_1ms(20);                  Write_Cmd(0x30);   //基本指令集     Delay_1ms(20);      Write_Cmd(0x02);   // 地址归位     Delay_1ms(20);      Write_Cmd(0x0c);   //整体显示打开,游标关闭     Delay_1ms(20);      Write_Cmd(0x06);   //游标右移     Delay_1ms(20);      Write_Cmd(0x80);   //设定显示的起始地址     Delay_1ms(20);      Write_Cmd(0x01);   //清除显示 }