⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 12232f.h

📁 这个是一个用Keil C51编写的全新LCD12232F带中文字库的液晶驱动程序示例
💻 H
字号:
/*******************************************************/
/*******   12232F Driver Written by Wangbiao    ********/
/***********    2006.3.1-2006.4.14    ******************/
/*******************************************************/
#include<intrins.h>
//-----------------------------------------------------------------------
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//-----------------------------------------------------------------------
sbit  RS=P3^7;
sbit  RW=P3^6;
sbit  Elcm=P3^5;
#define DATAPORT P1//data port !!!!!!!!!!
//----------------------------------------------------------------------
#define busy 0x80 //用于检查写忙信号
unsigned char Dis_Buff0[16],Dis_Buff1[16];//显示缓存区
//-----------------------外部函数----------------------------------------
void Init_Lcd12232F(void);
void Cls(unsigned char y);
void DispChar(unsigned char x,unsigned char y,char dataW);
void DispString(unsigned char x,unsigned char y,unsigned char *ptr);
void DispChinese(unsigned char x,unsigned char y,unsigned char *ptr);
void DispNumb(unsigned char x,unsigned char y,unsigned int n);//显示一组数字"1234"
//-----------------------------------------------------------------------
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//-----------------------------------------------------------------------
//-----------------------内部函数----------------------------------------
void delay5ms(void);
void delay(unsigned int n);
void WaitForEnable( void );
void LcdWrite_C( unsigned char CMD,unsigned char AttribC );
void LcdWrite_D( char dataW );
void Refresh(unsigned char y);
//-----------------------------------------------------------------------
//----------------------具体子函数---------------------------------------
// -----------------------------------------短延时
void delay5ms(void)
{	unsigned int i = 5552;
	while(i--);
}
//*********************************************//
//       delay nearly n*0.05s ;;n=20->1s      //
//********************************************//
void delay(unsigned int n)
{	unsigned int i;
	for(;n>0;n--)
	{	for(i=0;i<10000;) i++;  }
}
//****************************************************
/*=======================================================
正常读写操作之前必须检测LCD控制器状态: CS=1 RS=0 RW=1
DB7: 0 LCD控制器空闲; 1 LCD控制器忙
========================================================*/
void WaitForEnable( void )
{	DATAPORT = 0xff;
	RS =0; RW = 1; _nop_(); Elcm = 1; _nop_(); _nop_();
	while( DATAPORT & busy );
	Elcm = 0;
} 
/*=======================================================
写控制字符子程序: E=1 RS=0 RW=0
=======================================================*/
void LcdWrite_C( unsigned char CMD,unsigned char AttribC ) 
{	if (AttribC) WaitForEnable(); // 检测忙信号?
	RS = 0; RW = 0; _nop_();
	DATAPORT =CMD; _nop_(); // 送控制字子程序
	Elcm = 1;_nop_();_nop_();Elcm = 0; // 操作允许脉冲信号 
}
/*=======================================================*/
/*=======================================================
当前位置写字符子程序: E =1 RS=1 RW=0
=======================================================*/
void LcdWrite_D( char dataW ) 
{	WaitForEnable(); // 检测忙信号
	RS = 1; RW = 0; _nop_();
	DATAPORT = dataW; _nop_();
	Elcm = 1; _nop_(); _nop_(); Elcm = 0; // 操作允许脉冲信号 
}
/*=======================================================
当前位置读字符子程序: E =1 RS=1 RW=1
=======================================================*/
/*
unsigned char LcdRead_D(void) 
{	unsigned char dataR;
	//WaitForEnable(); // 检测忙信号
	RS = 1; RW = 1; _nop_();
	DATAPORT=0xff;//把DATAPORT置为高电平,只有置为高电平才能正确读入数据
	Elcm = 1; _nop_(); _nop_();_nop_(); 
	dataR = DATAPORT; _nop_();
	Elcm = 0; // 操作允许脉冲信号
    return dataR;
}
*/
//****************************************************
void Init_Lcd12232F(void)
{	LcdWrite_C(0x30,0);  //功能设定,8位数据,基本指令方式
	delay5ms();
	LcdWrite_C(0x30,0); 
	delay5ms();
	LcdWrite_C(0x30,0); 
	delay5ms();
    LcdWrite_C(0x01,1);  //清除显示
    LcdWrite_C(0x02,1);  //地址归位
    LcdWrite_C(0x06,1);  //点设定
    LcdWrite_C(0x0c,1);  //0c整体显示开,0e游标开,0f游标位置反白允许
    LcdWrite_C(0x40,1);  //设定CGRAM地址
	delay(1);//for no warning
}
/*=======================================================
显示刷新
========================================================*/
void Refresh(unsigned char y)
{	unsigned char i,j,pos=0;//pos=0!!!
	if(y) pos|=0x10;
	pos|=0x80;
	for(i=0;i<8;i++)
	{	LcdWrite_C(pos,1);
   		for(j=0;j<2;j++)
		{	WaitForEnable();
	    	if(y==0) LcdWrite_D(Dis_Buff0[i*2+j]);
			else LcdWrite_D(Dis_Buff1[i*2+j]);
		}
		pos++;
	}
}
/*=======================================================
按指定位置显示一个字符
=======================================================*/
void DispChar(unsigned char x,unsigned char y,char dataW) 
{	if(y==0) Dis_Buff0[x]=dataW;
	else Dis_Buff1[x]=dataW;
	Refresh(y);
}
/*=======================================================
按指定位置显示一串字符
=======================================================*/
void DispString(unsigned char x,unsigned char y,unsigned char *ptr) 
{	unsigned char i,len=0;//len=0!!!!!!!!
	while (ptr[len]>31){len++;};//取得要显示的个数
	for(i=0;i<len;i++) DispChar(x+i,y,*ptr++);
}
/*=======================================================
按指定位置显示中文字符串(x必须偶对齐取值为0~7)
=======================================================*/
void DispChinese(unsigned char x,unsigned char y,unsigned char *ptr)
{	unsigned char i,len=0;//len=0!!!!!!!!
	while (ptr[len]>31){len++;};//取得要显示的个数
	for(i=0;i<len;i++)
	{	if(y==0) Dis_Buff0[x*2+i]=*ptr++;
		else Dis_Buff1[x*2+i]=*ptr++;
	}
	Refresh(y);
}
/*=======================================================
按指定位置显示一个数字表(4位BCD码)
=======================================================*/
unsigned char code number[]="0123456789";//for dis table
void DispNumb(unsigned char x,unsigned char y,unsigned int n)
{	unsigned char digi[4];
	unsigned char i;
	digi[0]=n/1000;n=n-digi[0]*1000;
	digi[1]=n/100;n=n-digi[1]*100;
	digi[2]=n/10;n=n-digi[2]*10;
	digi[3]=n;
	for(i=0;i<4;i++) DispChar(x+i,y,number[(digi[i])]);
}
/*=======================================================
清屏(y=0->上半屏;y=1->下半屏)
=======================================================*/
void Cls(unsigned char y)	
{	unsigned char i;
	for(i=0;i<16;i++)
	{	if(y==0) Dis_Buff0[i]=' ';
		else Dis_Buff1[i]=' ';
	}
	Refresh(y);
}
//-------------------end LCD12232F.H-----------------------------------------	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -