stc89c52+12864带中文字库液晶显示中文

// Header: 12864带中文字库液晶模块显示文字C程序实例
// File Name: 
// Author:
// Date:

#include <stdio.h>
#include <math.h>
#include <reg52.h>
#include <string.h>

sbit    RS =P2^5; //注意:一定要看12864液晶模块的资料,来确定怎样操作
sbit    WRD=P2^6;
sbit    E=  P2^7;
sbit    PSB=P2^3;
sbit    RES=P2^4;

void TransferData(char data1,bit DI);
void delayms(unsigned int n);
void delay(unsigned int m);
void lcd_mesg(unsigned char code *addr1);


//下面来定义要显示的汉字,8*4
unsigned char code IC_DAT[]={
	"世界您好!      "
	"程序初始化      "
	"                "
	"                "
};

unsigned char code IC_DAT2[]={
	"爱一个人难却还爱"
	"交结朋友可路更宽"
	"诚实守信加油努力"
	"成功做人成功做事"
};

void initinal(void)           //初始化,12864有要求的要写上
{
	delay(40);
	PSB=1;   //并口工作模式
	delay(1);
	RES=0; //复位
	delay(1);
	RES=1;   //复位置高
	delay(10);
	TransferData(0x30,0);
	delay(100);
	TransferData(0x30,0);
	delay(37);
	TransferData(0x08,0);
	delay(100);
	TransferData(0x10,0);
	delay(100);
	TransferData(0x0C,0);
	delay(100);
	TransferData(0x01,0);
	delay(10);
	TransferData(0x06,0);
	delay(100);
}


void main(void)            //分两屏来不断显示上面定义的IC_DAT和IC_DAT2汉字
{
	while(1)
	{
	   initinal();//调用LCD字库初始化程序
	   delay(100);
	   lcd_mesg(IC_DAT);
	   delayms(240);                   //延时程序必要的,长与短,自己调节
	   delayms(240);
	
	   initinal();
	   delay(100);
	   lcd_mesg(IC_DAT2);
	   delayms(240);
	   delayms(240);
	}
}


void lcd_mesg(unsigned char code *addr1)   //显示汉字函数,8*4=32
{
	unsigned char i;
	TransferData(0x80,0);
	delay(100);
	for(i=0;i<32;i++)
	   {
	    TransferData(*addr1,1);
	    addr1++;
	   }
	   TransferData(0x90,0);
	   delay(100);
	   for(i=32;i<64;i++)
	   {
	    TransferData(*addr1,1);
	    addr1++;
	   }
}

   
void TransferData(char data1,bit DI) //传送数据或是命令,当DI=0时,传送命令,当DI=1时,传送数据
{
	WRD=0;
	RS=DI;
	delay(1);
	P0=data1;
	E=1;
	delay(1);
	E=0;
}



void delayms(unsigned int n)    //延时子程序
{
	unsigned int i,j;
	for(i=0;i<n;i++)
	for(j=0;j<2000;j++);
}

void delay(unsigned int m)
	{
		unsigned int i,j;
		for(i=0;i<m;i++)
		for(j=0;j<10;j++);
	}

你可能感兴趣的:(c,工作,Date,File,header,delay)