SPLC792A驱动程序,16x2字符型,I2C接口

作者:Joey 分类: 液晶显示 发布于:2016-4-24 12:54 ė3909次浏览 60条评论


//           SPLC792A 模拟I2C测试程序
//***************************************************************************
//连线表:  CPU=STC11L60XE       Fosc=22.1184Mhz                             *
//***************************************************************************
//         SCL  SDA 须接4.7K上拉电阻                                        *
//***************************************************************************
#include <reg52.h>
#include <intrins.h>
#include "vi2c.h"

sbit RES=P3^5;	//复位信号
sbit Key=P1^1;	//延时按键


//延时函数(毫秒级)
void DelayMS(unsigned int MS)
{	//For 40M STC89C516    : usn=9  us=182
	//For 22.1184 STC11F60 : usn=45 us=182
	unsigned char us,usn,i;
	while(MS!=0)
	{
		usn = 45;
		while(usn!=0)
		{
			us=182;
			while (us!=0){us--;};
			usn--;
		}
		for(i=0;i<3;i++);
		MS--;
	}
}

//写指令函数
void WriteCommand(unsigned char CommandByte)
{
	unsigned char ControlByte=0x00;		//Control Byte,(Co)(A0)000000(A) Co=0 A0=0=后面的I2C数据是显示指令
										//Co=0是表示这是最后一个Control Byte(此处的指令意思为I2C总线控制命令,非显示指令)
										//后面的I2C数据是显示指令
	I2C_BufferWrite(&CommandByte, ControlByte, 1);
}

//写数据函数
void WriteData(unsigned char *pDAT,unsigned char length)
{
	unsigned char ControlByte=0x40;		//Control Byte,(Co)(A0)000000(A) Co=0 A0=1=后面的I2C数据是显示数据
										//Co=0是表示这是最后一个Control Byte(此处的指令意思为I2C总线控制命令,非显示指令)						
	I2C_BufferWrite(pDAT, ControlByte, length);
}

//测试架专用延时程序
void DelayKey(unsigned char Second , unsigned char MS100)
{						//输入精确到0.1S,是用,
	unsigned int i;
	for(i=0;i<Second*100+MS100*10;i++)
	{
		if(Key==0)
		{
			DelayMS(20);
			while(Key==0) {DelayMS(20);}
			break;
		}
		else DelayMS(10);
	}				
}

//初始化
void LcdInit(void)
{
	#define CONTRAST 20
	WriteCommand(0x38);	//Function set:8bit,2-line,IS=0
	DelayMS(1);
	WriteCommand(0x39);	//Function set:8bit,2-line,IS=1
	DelayMS(1);
	WriteCommand(0x50+(CONTRAST>>4));	//ICON OFF,bit[1:0]=Contrast bit[5:4]
	DelayMS(1);
	WriteCommand(0x70+(CONTRAST&0x0F));	//Contrast = 101000b
	DelayMS(1);
	WriteCommand(0x6B);	//Follower control ON,Rab=011b,即使是外供VLCD电压,此处V0还是受限于Rab这个曲线图
	DelayMS(100);
	WriteCommand(0x0C);	//Display ON,Cursor off,Blink off
	DelayMS(1);
	WriteCommand(0x01);	//Clear Display
	DelayMS(2);
	WriteCommand(0x06);	//Entry Mode Set
	DelayMS(1);
}

void SetCGRAM( unsigned char *puts )
{
	WriteCommand(0x38);	//Function set:8bit,2-line,IS=0
	DelayMS(1);
	WriteCommand(0x40);		//CGRAM start Address
	DelayMS(10);
	WriteData(puts,64);
}

void PutStr(unsigned char *puts)
{
	WriteCommand(0x80);	//AC=00H
	DelayMS(1);
	WriteData(puts,16);
	WriteCommand(0xC0);	//AC=40H
	DelayMS(1);
	WriteData(puts,16);
}

void ROMCheck(void)	//把CGROM字库后面的字体显示出来判断是俄文还是日文
{
	unsigned char i;
	unsigned char xdata msg[40];
	for(i=0;i<40;i++)
	{
		msg[i] = 0x80+i;
	}
	WriteCommand(0x80);	//AC=00H
	WriteData(msg,40);
	
	WriteCommand(0xC0);	//第二行显示,和第一行一样
	WriteData(msg,40);
}

void FullDDRAM(unsigned char fillchar)
{
	unsigned char i;
	WriteCommand(0x80);	//AC=00H
	DelayMS(1);
	for(i=0;i<128;i++)
	{
		WriteData(&fillchar,1);
		_nop_();
		_nop_();
	}
}

unsigned char code str1[]="SPLC792A 2014/0123456789ABCDEFGHIJKLM";
unsigned char code CUSTOM[]={
0xff,0x11,0x11,0x11,0x11,0x11,0x11,0xff,	//方框
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,	//全黑
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,	//全白
0x15,0x0a,0x15,0x0a,0x15,0x0a,0x15,0x0a,	//网点
0x0a,0x15,0x0a,0x15,0x0a,0x15,0x0a,0x15,	//网点
0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,	//横线1
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,	//横线2
0x15,0x15,0x15,0x15,0x15,0x15,0x15,0x15,	//竖线1

0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,	//竖线2
};

unsigned char code ICON_Table[]={
0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,
0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,
0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,
0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,
};

//图标ICON测试
void ShowICON(unsigned char n)
{
	unsigned char i;
	unsigned char xdata msg[16];
	WriteCommand(0x39);	//Function set:8bit,2-line,IS=1
	DelayMS(1);
	WriteCommand(0x40);	//Set ICON RAM Address
	DelayMS(1);
	WriteCommand(0x38);	//Function set:8bit,2-line,IS=0
	DelayMS(1);
	for(i=0;i<16;i++)
	{
		msg[i] = ICON_Table[16*n+i];
	}
	WriteData(msg,16);
}

void main(void)
{
	BL  = 0;
	RES = 1;
	RES = 0;	//复位
	DelayMS(100);
	RES = 1;
	DelayMS(1);
	LcdInit();
	SetCGRAM(CUSTOM);
	while(1)
	{
		FullDDRAM(0x00);	//方框
		DelayKey(0,6);
		PutStr(str1);
		DelayKey(0,6);
		ROMCheck();
		DelayKey(0,6);
		FullDDRAM(0x01);	//全黑
		DelayKey(0,6);
		FullDDRAM(0x02);	//全白
		DelayKey(0,6);
		FullDDRAM(0x03);	//网点1
		DelayKey(0,6);
		FullDDRAM(0x04);	//网点2
		DelayKey(0,6);
	}
}



其中模拟I2C底层请参考 http://www.lcdbbs.net/post-24.html

本文出自 LcdBBS,转载时请注明出处及相应链接。

0

Ɣ回顶部