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

📄 ocm12232c-1lcd演示程序.c

📁 STC89C51驱动OCM12232C-1液晶显示屏的演示程序
💻 C
字号:
#include <reg51.h>
//*******************************************************
//硬件配置
sbit 	SLCD_CS			=P2^5;
sbit 	SLCD_STD		=P2^4;
sbit 	SLCD_SCLK		=P2^3;
#define SLCD_WIDTH		15		//LCD Width
#define SLCD_NextLine	SLCDSendCmd(0x00,0x90)	//换行命定
//*******************************************************
void SLCDSendCmd(unsigned char cmd,unsigned char param);//OK
void SLCDInit(unsigned char mode);//OK
void SLCDCls(void);//OK
void SLCDSendChar(unsigned char);//OK
void SLCDSendString(const unsigned  char *);//OK
void SLCDSendNum2(unsigned char num);
void Delay(unsigned char t);

void main()
{
	SLCDInit(0);	//0-Text Mode
	while(1)
	{
		SLCDCls();		//Clear the LCD
		SLCDSendString("MCS51 实验平台\nLCD 演示程序");	//Print a String
		Delay(100);
		SLCDCls();			//Clear the LCD
		SLCDSendChar('W');	//Print a Char
		SLCDSendChar('e');	
		SLCDSendChar('l');	
		SLCDSendChar('c');
		SLCDSendChar('o');
		SLCDSendChar('m');
		SLCDSendChar('e');
		SLCDSendChar('\n');
		SLCDSendNum2(20);	//Print a number
		SLCDSendNum2(0);	
		SLCDSendNum2(7);
		SLCDSendChar('.');
		SLCDSendNum2(4);
		SLCDSendChar('.');
		SLCDSendNum2(6);
		Delay(100);
    }

}

/***************************************************
*******************串口LCD函数库******************
***************************************************/

/**************************************************
 延时函数
 e.g.:Delay(5);
 p.s.:高手也可以用以下宏代替
 #define DELAY(t)	{unsigned int i;while(i=1000,t--)while(i--);}
***************************************************/
void Delay(unsigned char t)
{
	unsigned int i;
	while(i=1000,t--)while(i--);
}
/**************************************************
 私有函数,除非十分了解,否则请勿调用!
***************************************************/
void SLCDSendByte(unsigned char dat)	
{
	unsigned char i=0;
	unsigned char a=0;	    
	SLCD_CS=1;
	for(;i<8;i++)
	{
		if (dat&0x80)
			//SLCDSendBit(1);
			SLCD_STD=1;
		else
			//SLCDSendBit(0);
			SLCD_STD=0;
		SLCD_SCLK=1;
		SLCD_SCLK=0;
		dat<<=1;
		for(a=0;a<10;a++);
	}
	SLCD_CS=0;
}
/**************************************************
 字符串显示函数(ASCII码、汉字)
 e.g.:SLCDSendString("The String you want to show!");
 p.s.:可以用\n换行,也可以自动换行!类似ANSI C里面的printf();
***************************************************/
void SLCDSendString(unsigned char *s)
{
	unsigned char i=0;
	while(s[i])
	{
		if (s[i]=='\n') SLCD_NextLine;
		else 			SLCDSendCmd(0x02,s[i]);
		i++;
		if (i%15==0) SLCD_NextLine;
	};
}
/**************************************************
 字符显示函数(ASCII码)
 e.g.:SLCDSendChar('c');
 p.s.:类似ANSI C里面的putch();
***************************************************/
void SLCDSendChar(unsigned char ch)
{
	if(ch=='\n') 	SLCD_NextLine;
	else			SLCDSendCmd(0x02,ch);
}
/**************************************************
 1字节(2位16进制数)10进制数字显示函数(0~255)
 e.g.:SLCDSendNum2(232);
 p.s.:类似ANSI C里面的putch();
***************************************************/
void SLCDSendNum2(unsigned char num)
{
	unsigned char a,b,c;
	a=num/100;
	b=(num%100)/10;
	c=num%10;
	if(a!=0) SLCDSendCmd(0x02,a+'0');
	if(b!=0) SLCDSendCmd(0x02,b+'0');
	SLCDSendCmd(0x02,c+'0');
}
/**************************************************
 私有函数,除非十分了解,否则请勿调用!
***************************************************/
void SLCDSendCmd(unsigned char cmd,unsigned char param)
//格式:cmd=******RS,RW;
//      val=DB7~DB0
{
	unsigned char a;
	a=cmd;
	cmd&=0x02;
	a&=0x01;
	a<<=2;
	cmd|=a;
	cmd|=0xf8;
	SLCDSendByte(cmd);

	a=param;
	a&=0xf0;
	param<<=4;
	param&=0xf0;
	SLCDSendByte(a);
	SLCDSendByte(param);
	SLCD_CS=0;
}
/**************************************************
 清屏函数
 e.g.:SLCDCls();
***************************************************/
void SLCDCls(void)
{
	SLCDSendCmd(0x00,0x01);
}
/**************************************************
 初始化函数
 e.g.:SLCDInit(0);
 p.s.:0~Text Mode
      1~Graphic Mode(暂时不提供)
***************************************************/
void SLCDInit(unsigned char mode)
{
	SLCDSendCmd(0x00,0x30);
	SLCDSendCmd(0x00,0x01);
	SLCDSendCmd(0x00,0x06);
	SLCDSendCmd(0x00,0x0c);
	if(mode==0)
 	{
		SLCDSendCmd(0x00,0x30);
		SLCDSendCmd(0x00,0x80);
	}
}

⌨️ 快捷键说明

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