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

📄 pcf2119.c

📁 应用于测试LCD driver
💻 C
字号:
// Functions for PCF2113 18com/60seg LCD Controller and Driver

// Write a string to LCD
void SendStr(uint8 code *ptString)
{
	while((*ptString)!='\0')
	{
		SendByte(iDat, *ptString++);
	}
}

// Move Cursor or display
void Move(uint8 dir)
{
	SendByte(iCmd, dir);
}

// Goto specific location
void Gotoxy(uint8 Row, uint8 Col)
{
	switch (Row)
	{
		#if defined(LCD_L2)
		case 2:
			SendByte(iCmd, LCD_L2 + Col); break;
		#endif
		#if defined(LCD_L3)
		case 3:
			SendByte(iCmd, LCD_L3 + Col); break;
		#endif
		#if defined(LCD_L4)
		case 4:
			SendByte(iCmd, LCD_L4 + Col); break;
		#endif
		default:
			SendByte(iCmd, LCD_L1 + Col); break;
	}
}

// Clear LCD Screen
void LCD_CLS(void)
{
	SendByte(iCmd, 0x01);
	DelayMs(5);
	// 2ms delay is Necessary after sending LCD_CLS command !!!
}

// Wait some time and clear screen
void wait_and_clear(void)
{
	DelayMs(1000);
	LCD_CLS();
}

// Fill CGRAM with array CGRAM[]
void FillCGRAM(void)
{
	uint8 i;
	SendByte(iCmd, LCD_CGRAM_ADDR);
	for (i = 0; i < LCD_CGMAX; i++)
	{
		SendByte(iDat, CGRAM[i]);
	}
}

// Show All patterns in CGRAM
void ShowCGRAM(void)
{
	uint8 i;
	for (i = 0; i < 8; i++)
	{
		Tile(i);
		wait_and_clear();
	}
}

// Tile screen with one data
void Tile(uint8 tData)
{
	uint8 k;
	SendByte(iCmd, LCD_L1);
	for (k = 0; k < LCD_CHAR; k++)
	{
		SendByte(iDat, tData);
	}
}

// Show the built-in Charactors
void CallBultinChar(void)
{
	uint8 i, k, CurrentData;
	uint8 FrameNumber;
	if (256%LCD_CHAR != 0)
		FrameNumber= 256/LCD_CHAR + 1;
	else
		FrameNumber= 256/LCD_CHAR;
		
	for (i = 0; i < FrameNumber; i++)
	{
		for (k = 0; k < LCD_CHAR; k++)
		{
			if (k%LCD_COL == 0)
			{
				switch (k)
				{
					case 0:
					SendByte(iCmd, 0x80); break;
					case LCD_COL:
					SendByte(iCmd, 0xC0); break;
					case 2*LCD_COL:
					SendByte(iCmd, 0x80 + LCD_COL); break;
					case 3*LCD_COL:
					SendByte(iCmd, 0xC0 + LCD_COL); break;
					default:
					SendByte(iCmd, 0x80);
				}
			}
			CurrentData = k + i*LCD_CHAR;
			SendByte(iDat, CurrentData);
			if (CurrentData == 255)
			break;
		}
		wait_and_clear();
		if (CurrentData == 255)
		break;
	}
}

// LCD initialize procedure
void LCD_Init(void)
{
	//PortConfig();
	LCD_Reset();
	DelayMs(100);				// Wait for internal initialization
	#ifdef MCU_6800_4BIT		
		LCD_A0 = iCmd;			// LCD_RS = iCmd;
		LCD_RW = 0;
		LCD_E = 1;
		LCD_DataPort = 0x20;	// Set Interface to 4-bit		
		LCD_E = 0;
		DelayUs(50);
		SendByte(iCmd, LCD_FUNCTION_SET);	// Function Set
	#else
		SendByte(iCmd, LCD_FUNCTION_SET);	// Function Set
	#endif
	DelayMs(5);
	SendByte(iCmd, LCD_FUNCTION_SET);		// Function Set
	SendByte(iCmd, LCD_ON);
	LCD_CLS();
	SendByte(iCmd, 0x04 + 0x02);			// Entry Mode Set
	// D1: I/D(Cursor Inc Dir) 0: INC, 1: DEC
	// D0: S(Shift Display) 0: freeze, 1: shift
	
	SendByte(iCmd, LCD_FUNCTION_SET | 0x01);	// Extended Function Set H = 1
	SendByte(iCmd, 0x02 + 0);	// Screen Config.(No impact if SL = 1/M = 1)
	// D0: 0(L/R screen connection: Normal)
	//     1(L/R screen connection: Mirror)
	
	SendByte(iCmd, 0x04 + 0);	// Display Config.
	// D1: 0(Column Data: Left to Right)
	//     1(Column Data: Right to Left)
	// D0: 0(Row Data: Top to Bottom; ICON row is 17~18)
	//     1(Row Data: Bottom to Top; ICON row is 18~17)
	
	SendByte(iCmd, 0x08 + 0);	// ICON Control
	// D2: 0: full display(Chars and ICONs), 1: Only ICONs.
	// D1: 0: Don't blink ICONs, 1: Blick ICONs.
	// D0: Direct Mode(0: Disable, 1: Enable)
	
	SendByte(iCmd, 0x10 + 0);	// Temperature Coefficient
	// D[1:0] = [0 ~ 3] 4 values are valid
	
	SendByte(iCmd, 0x40 + 2);	// Booster stage
	// D[1:0] = [0 ~ 2]: 3 values are valid
	// 00: 2X, 01: 3X, 10: 4X, 11: Invalid
	
	SendByte(iCmd, 0x80 + 0x00 + 53);	// Set Vlcd
	SendByte(iCmd, 0x80 + 0x10 + 53);	// Set Vlcd
	// D6: 0: Va(Char Mode), 1: Vb(ICON Mode)
	// D[5:0]: Vop fine tune
	// Vop = (D[5:0]*0.08 + 1.82)
	// Vop = 4.80V 		
	
	SendByte(iCmd, LCD_FUNCTION_SET);	// Resume Basic Instruction Mode
}

⌨️ 快捷键说明

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