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

📄 s6b0724.c

📁 一个测试LCD的应用程序
💻 C
字号:
// Function for setting Column Address
void SetCA(uint8 CAddr)
{
	//CAddr's range is from 0 to LCD_CMAX
	//CAddr += 4;	// Remove this statement if LCD_ADC is 0xA0
	CAddr += 4;		// Special for the LCD whose first SEG is SEG4 but not SEG0
	SendByte(iCmd, CAddr & 0x0F);			// Lower 4-bit
	SendByte(iCmd, (CAddr >> 4) | 0x10);	// Higher 4-bit
}

// Function for setting Page Address
void SetPA(uint8 PAddr)
{
	//PAddr's range is from 0 to LCD_PMAX
	SendByte(iCmd, LCD_P0 + PAddr);
}

// Goto specific position
void Gotoxy(uint8 page, uint8 col)
{
	SetPA(page);
	SetCA(col);
}

#ifdef LCD_8BIT
// Read a data from LCD DDRAM
uint8 ReadData(uint8 PAddr, uint8 CAddr)
{
	uint8 dByte;
	Gotoxy(PAddr, CAddr);
	LCD_DataPort = 0xFF;	// Set the port as input
	LCD_CS = 0;
	LCD_A0 = iDat;
	#ifdef MCU_6800
		LCD_RW = 1;
		LCD_E  = 1;
		//delay4us();			// A dummy read
		LCD_E  = 0;
		//delay4us();
		LCD_E  = 1;
		//delay4us();
		dByte = LCD_DataPort;	// Actual read
		LCD_E  = 0;
	#else
		LCD_WR = 1;
		LCD_RD = 0;
		//delay4us();			// A dummy read
		LCD_RD = 1;
		//delay4us();
		LCD_RD = 0;
		//delay4us();
		dByte = LCD_DataPort;	// Actual read
		LCD_RD = 1;
	#endif
	LCD_CS = 1;
	return dByte;
}

// Reverse display of Page PAddr
void ReversePage(uint8 PAddr)
{
	uint8 col, Original;
	for (col = 0; col < LCD_CMAX; col++)
	{
		Original = ReadData(PAddr, col);
		SetCA(col);
		SendByte(iDat, ~Original);
	}
}
#endif
// Function for setting Contrast
void SetContrast(uint8 CValue)
{
	// CValue < 64
	SendByte(iCmd, 0x81);
	SendByte(iCmd, CValue);
}

// Set NLine Inversion
void InverseNLine(bit State, uint8 nLine)
{
	if (State)
	{
		// Enter N-Line Inversion
		SendByte(iCmd, 0x85);
		SendByte(iCmd, (nLine - 1) & 0x1F);	// nLine[1:32]
	}
	else
	{
		// Release N-Line Inversion
		SendByte(iCmd, 0x84);
	}
}
#ifdef LCD_ICOMAX
	// Set LCD specific Icon ON/OFF
	void SetIcon(uint8 State, uint8 index)
	{
		SetPA(LCD_PMAX);	// Goto Icon Page
		SetCA(ICONS[index]);
		SendByte(iDat, State);
	}
	
	// Turn On/Off all icons
	void Allicons(bit State)
	{
		uint8 i;
		for (i = 0; i < LCD_ICOMAX; i++)
		{
			if (State)
				SetIcon(0xFF, i);
			else
				SetIcon(0x00, i);
		}
	}
	
	// Display each Icon and then hide them one by one
	void ICON_Test(void)
	{
		uint8 i;
		Allicons(1);
		delay1s();
		Allicons(0);
		delay1s();
		for (i = 0; i < 2*LCD_ICOMAX; i++)
		{
			if (i < LCD_ICOMAX)
			{
				SetIcon(0xFF, i);
			}
			else
			{
				SetIcon(0x00, i - LCD_ICOMAX);
			}
			delay100ms();
		}
		delay500ms();
	}
#endif

// Tile LCD screen with two datas
void Tile(uint8 fst, uint8 snd)
{
	uint8 i,j;
	//SendByte(iCmd, LCD_OFF);
	for (i = 0; i < LCD_PMAX; i++)
	{
		Gotoxy(i, 0);
		for (j = 0; j < LCD_CMAX/2; j++)
		{
			SendByte(iDat, fst);
			SendByte(iDat, snd);
		}
	}
	//SendByte(iCmd, LCD_ON);
}

// Clear LCD screen
void Clear(void)
{
	Tile(0x00, 0x00);
	delay4us();
}

// Clear page X
void ClearPage(uint8 PAddr)
{
	uint8 Col = LCD_CMAX;
	Gotoxy(PAddr, 0);
	while(Col-- != 0)
	{
		SendByte(iDat, 0x00);
		//delay100ms();
	}
	SetCA(0);
}

// Wait some time and clear the screen
void wait_and_clear(void)
{
	DelayMs(1200);
	Clear();
}

// Function for initializing LCD
void LCD_Initial(void)
{
	LCD_RST = 0;
	DelayUs(100);
	LCD_RST = 1;
	DelayMs(100);
	
	SendByte(iCmd, LCD_OFF);
	SendByte(iCmd, LCD_BIAS);	// Set LCD power supply Bias Ratio
	SendByte(iCmd, LCD_ADC);	// Set ADC
	SendByte(iCmd, LCD_SHL);	// Set SHL
	SendByte(iCmd, 0x24);		// Set the Resister Ratio of Vreg

	SetContrast(45);			// Vop for LM33D2B
	
	SendByte(iCmd, 0x2F);		// LCD Power Control
	DelayMs(50);				// Wait 50ms for steady power	
	
	//SendByte(iCmd, 0xE4);		// Set IC Oscillator(EM62100 Only)
	// 0xE4: 31.4KHz; 0xE5: 26.3KHz
	SendByte(iCmd, LCD_DATN);	// Normal Display
	SendByte(iCmd, LCD_L0);		// Set first line of display
	Clear();
	SendByte(iCmd, LCD_ON);
}

#ifdef __LCD_TEST__
// Display LCD Test Graphics
	void LCD_Test(void)
	{
		uint8 i;
		uint8 code TestData[][2] =
		{
			// Standard graphics for LCD Testing
			{0xFF,0xFF},	// 1. All
			{0x00,0x00},	// 2. None	
			{0xFF,0x00},	// 3. Virtical 1
			{0x00,0xFF},	// 4. Virtical 2
			{0xAA,0xAA},	// 5. Horizontal 1
			{0x55,0x55},	// 6. Horizontal 2
			{0xAA,0x55},	// 7. Stars 2
			{0x55,0xAA},	// 8. Stars 2
		};
		for (i = 0; i < 8; i++)
		{
			Tile(TestData[i][0], TestData[i][1]);
			wait_and_clear();
		}
		#ifdef LCD_ICOMAX
			ICON_Test();
		#endif
	}
#endif

⌨️ 快捷键说明

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