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

📄 st7920.c

📁 一个测试LCD的应用程序
💻 C
字号:
// Functions for ST7920

// Write Data or Command to LCD
void SendByte(bit DatCmd, uint8 dByte)
{
	LCD_DataPort = 0x00;
	LCD_RS = DatCmd;
	LCD_RW = 0;
	LCD_E = 1;
	LCD_DataPort = dByte;
	DelayUs(20);
	LCD_E = 0;
	LCD_RW = 1;
	LCD_DataPort = 0xFF;
	DelayUs(100);
}

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

// Set the LCD working mode(Gaphic/Character)
void SetMode(uint8 icmode)
{
	SendByte(iCmd, icmode);
}

// Set Icon ON/OFF
void SetIcon(uint8 Addr, dByte)
{
	SendByte(iCmd, LCD_GMODE);	// IS[1:0]: 01
	SendByte(iCmd, 0x40 + Addr);	// Set ICON Address
	SendByte(iDat, dByte);			// Set ICON Data
}

// Move Cursor or display
void Move(uint8 dir)
{
	SendByte(iCmd, LCD_CMODE);	// IS[1:0]: 00
	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 Clear(void)
{
	SetMode(LCD_CMODE);
	SendByte(iCmd, LCD_CLS);
	DelayMs(5);
	// 2ms delay is Necessary after sending LCD_CLS command !!!
}

// Wait some time and clear screen
void wait_and_clear(void)
{
	DelayMs(1200);
	Clear();
}
// Tile screen with one data
void Tile(uint8 tData)
{
	uint8 i, k;
	SetMode(LCD_CMODE);	
	for (i = 0; i < LCD_ROW; i++)
	{
		Gotoxy(i + 1, 0);
		for (k = 0; k < LCD_COL; k++)
		{
			SendByte(iDat, tData);
		}
	}
}

// Tile screen with a Chinese Symbol
void cTile(uint16 Hanzi)
{
	uint8 i, k;
	SetMode(LCD_CMODE);
	for (i = 0; i < LCD_ROW; i++)
	{
		Gotoxy(i + 1, 0);
		for (k = 0; k < LCD_XMAX; k++)
		{
			SendByte(iDat, Hanzi>>8);
			SendByte(iDat, Hanzi & 0x00FF);
		}
	}
}

// Call built-in Charactors
void CallBuiltinChar(void)
{
	uint8 i;
	// 0xA140 ~ 0xA15F
	for (i = 0; i < 32; i++)
	{
		SendByte(iDat, 0xA1);
		SendByte(iDat, 0x40 + i);
	}
	wait_and_clear();
	
	// 0xA1B0 ~ 0xA1CF
	for (i = 0; i < 32; i++)
	{
		SendByte(iDat, 0xA1);
		SendByte(iDat, 0xB0 + i);
	}
	wait_and_clear();
	
	// 0xA440 ~ 0xA45F
	for (i = 0; i < 32; i++)
	{
		SendByte(iDat, 0xA4);
		SendByte(iDat, 0x40 + i);
	}
	wait_and_clear();	
}
// LCD initialize procedure
void LCD_Initial(void)
{
	DelayMs(100);				// Wait for internal initialization
	
	SendByte(iCmd, LCD_CMODE);
	SendByte(iCmd, LCD_ON);
	Clear();
	SendByte(iCmd, LCD_ENTRY);	// Entry Mode Set
}

⌨️ 快捷键说明

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