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

📄 hg16016002g.c

📁 基于1698的160×160的液晶驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
}

//Delay Times(s Level)
#pragma disable
void delayms()
{
	uint ui_dlay1,ui_dlay2;
	ui_dlay2 = DELAYMS;
	while (ui_dlay2-- >0)
	{
		for (ui_dlay1=0; ui_dlay1<500; ui_dlay1++)
		for (ui_dlay1=0; ui_dlay1<500; ui_dlay1++);
	}
}

//Interrupt 0 
#pragma disable
void Func_int0() interrupt 0 using 1
{
	if (ui_pause == 0)
 		ui_pause = 1;
	else
		ui_pause = 0;


	if ( ui_pause == 1 )
		while (1)
		{
			if (PAUSE == 0)
				return;
		}
}

//Write Instruction Code
#pragma disable
void wr_cmd(uchar uc_cmd)
{
	E_PORT = 0;
	_nop_();
	_nop_();

	RS_PORT = 0;
	_nop_();
	_nop_();

	RW_PORT = 0;
	_nop_();
	_nop_();

	CS_PORT = 0;
	_nop_();
	_nop_();

	DataPort = uc_cmd;
	_nop_();
	_nop_();

	E_PORT = 1;
	_nop_();
	_nop_();

	E_PORT = 0;
	_nop_();
	_nop_();

	CS_PORT = 1;
	_nop_();
	_nop_();
}

//Write Display RAM Data
#pragma disable
void wr_dat(uchar uc_dat)
{
	E_PORT = 0;
	_nop_();
	_nop_();

	RS_PORT = 1;
	_nop_();
	_nop_();

	RW_PORT = 0;
	_nop_();
	_nop_();

	CS_PORT = 0;
	_nop_();
	_nop_();

	DataPort = uc_dat;
	_nop_();
	_nop_();

	E_PORT = 1;
	_nop_();
	_nop_();

	E_PORT = 0;
	_nop_();
	_nop_();

	CS_PORT = 1;
	_nop_();
	_nop_();
	
}


//Display Control Setup
#pragma disable
void Intitial(void)
{
	wr_cmd(0xE2);//System Reset
	wr_cmd(0xAE);//Set Display Disable

	wr_cmd(0x24);//Set Temperature Compensation (00-0.00%)
	wr_cmd(0x2A);//Set Power Control (Interal VLCD;Panel loading definition<13nF)
	wr_cmd(0xEA); //Set LCD Bias ratio:1/11
	
    wr_cmd(0x81); //Set gain and potentiometer Mode
	wr_cmd(0x3F); //Program Gain:01;PM value:xx

	wr_cmd(0x89); //Set RAM Address Control
	wr_cmd(0xC4); //Set LCD Maping Control (MY=1, MX=0)
	
	wr_cmd(0x84); //Set Partial Display Off

	wr_cmd(0xD6); //Set Color Mode (64K)
	wr_cmd(0xD1); //Set Color Pattern (RGB)
	wr_cmd(0xDE); //Set COM Scan Function

	wr_cmd(0xAF); //Set Display Enable
}

void DispRows(uchar dat1,uchar dat2)
{
	uchar uc_RowCnt,uc_ColCnt;
	uchar uc_RowAddrH,uc_RowAddrL;
	
	for (uc_RowCnt=0;uc_RowCnt<160;uc_RowCnt++)
	{
		uc_RowAddrH =uc_RowCnt /16;
		uc_RowAddrL =uc_RowCnt %16;
 
		wr_cmd(0x70 |uc_RowAddrH); //Set Row Address(MSB)
		wr_cmd(0x60 |uc_RowAddrL); //Set Row Address(LSB)

		wr_cmd(0x12);//Set Address(MSB)
		wr_cmd(0x05);//Set Address(LSB)

		for (uc_ColCnt=0;uc_ColCnt<56;uc_ColCnt++)
		{
			if (uc_RowCnt %2==0)
			{
				wr_dat(dat1);
				wr_dat(dat1);
			}
			else
			{
				wr_dat(dat2);
				wr_dat(dat2);
			}
		};
	}
	delayms();
}

void DispColumns(uchar dat1,uchar dat2)
{
	uchar uc_RowCnt,uc_ColCnt;
	uchar uc_RowAddrH,uc_RowAddrL;
	
	for (uc_RowCnt=0;uc_RowCnt<160;uc_RowCnt++)
	{
		uc_RowAddrH =uc_RowCnt /16;
		uc_RowAddrL =uc_RowCnt %16;
 
		wr_cmd(0x70 |uc_RowAddrH); //Set Row Address(MSB)
		wr_cmd(0x60 |uc_RowAddrL); //Set Row Address(LSB)

		wr_cmd(0x12);//Set Address(MSB)
		wr_cmd(0x05);//Set Address(LSB)

		for (uc_ColCnt=0;uc_ColCnt<56;uc_ColCnt++)
		{
			wr_dat(dat1);
			wr_dat(dat2);
		};
	}
	delayms();
}

#pragma disable
void DisplayBorder()
{
	uint uc_RowCnt,uc_ColCnt;
	uchar uc_RowAddrH,uc_RowAddrL;
	
	//The First Line
	wr_cmd(0x70); //Set Row Address(MSB)
	wr_cmd(0x60); //Set Row Address(LSB)

	wr_cmd(0x12);//Set Address(MSB) 112->HEX
	wr_cmd(0x05);//Set Address(LSB)

	for (uc_ColCnt=0;uc_ColCnt<56;uc_ColCnt++)
	{
		wr_dat(0xFF);
		wr_dat(0xFF);
	};

	//The Middle Lines
	for (uc_RowCnt=1;uc_RowCnt<159;uc_RowCnt++)
	{
		uc_RowAddrH =uc_RowCnt /16;
		uc_RowAddrL =uc_RowCnt %16;

		wr_cmd(0x70 |uc_RowAddrH); //Set Row Address(MSB)
		wr_cmd(0x60 |uc_RowAddrL); //Set Row Address(LSB)

		wr_cmd(0x12);//Set Address(MSB) 112->HEX
		wr_cmd(0x05);//Set Address(LSB)

		wr_dat(0x07);
		wr_dat(0xE0);
		
		for (uc_ColCnt=0;uc_ColCnt<52;uc_ColCnt++)
		{
			wr_dat(0x00);
			wr_dat(0x00);
		};
		
		wr_dat(0x07);
		wr_dat(0xE0);
	};


	//The Last Line
	uc_RowAddrH =159 /16;
	uc_RowAddrL =uc_RowCnt %16;

	wr_cmd(0x70 |uc_RowAddrH ); //Set Row Address(MSB)
	wr_cmd(0x60 |uc_RowAddrL); //Set Row Address(LSB)

	wr_cmd(0x12);//Set Address(MSB) 112->HEX
	wr_cmd(0x05);//Set Address(LSB)

	for (uc_ColCnt=0;uc_ColCnt<56;uc_ColCnt++)
	{
		wr_dat(0xFF);
		wr_dat(0xFF);
	};
	delayms();
}

void main()
{
 	EA=1; //Interurupt Enabled

	IT0 = 1;//INT0 Low Level Trigger

	EX0 = 1;//INT0 Enabled

 	RST_PORT = 0;
	delay(250);
	delay(250);
	
	RST_PORT = 1;
	delay(250);
	delay(250);
	
	//UC1608 Initial
	Intitial();
	delay(50);

	while (1)
	{
		DispRows(0xFF,0xFF); //All Dots Display
		DispRows(0x00,0x00); //Clear Screen
		
		DispRows(0xFF,0x00); //Seperate Rows I
		DispRows(0x00,0xFF); //Seperate Rows II

		DispColumns(0x07,0xE0); //Seperate Columns I
		DispColumns(0x00,0x1F); //Seperate Columns II
		DispColumns(0xF8,0x1F); //Seperate Columns III

		DisplayBorder();
	}
	
}

⌨️ 快捷键说明

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