📄 lcdiof.c
字号:
// ------------------ The Basic I/O functions for LCD --------------------------
/* FileName: lcdiof.c
Version : 0.7
Last Updated: 2007-3-8
Description:
This library contains the necessary functions for input and output data
to the controller IC of LCM.
Program Coder: Seeseawe
*/
#ifdef __PORT_CONFIG__
// Port configuration of MCU
void PortConfig(void)
{
LCD_HPM = 0;
#if defined(MCU_6800_8BIT)
LCD_PS = 1;
LCD_C86 = 1;
#elif defined(MCU_6800_4BIT)
LCD_PS = 1;
LCD_C86 = 1;
#elif defined(MCU_8080_8BIT)
LCD_PS = 1;
LCD_C86 = 0;
#elif defined(MCU_8080_4BIT)
LCD_PS = 1;
LCD_C86 = 0;
#elif defined(LCD_4SPI)
P3 = 0xFF;
LCD_DataPort = 0xFF;
LCD_PS = 0;
LCD_C86 = 0;
#elif defined(LCD_3SPI)
P3 = 0xFF;
LCD_DataPort = 0xFF;
LCD_PS = 0;
LCD_C86 = 1;
#elif defined(LCD_I2C)
P3 = 0xFF;
LCD_DataPort = 0xFF;
LCD_PS = 1;
LCD_C86 = 1;
#endif
}
#endif
#ifdef LCD_RST
// Reset LCD
void LCD_Reset(void)
{
LCD_RST = 0;
DelayMs(1);
LCD_RST = 1;
DelayMs(30);
}
#endif
// Function for sending a byte to LCD
void SendByte(bit DatCmd, uint8 dByte)
{
#ifdef MCU_6800_8BIT
LCD_DataPort = 0x00; // Set the port as Output
LCD_Enable();
LCD_A0 = DatCmd;
LCD_RW = 0;
LCD_E = 1;
LCD_DataPort = dByte;
LCD_E = 0;
LCD_RW = 1;
LCD_Disable();
#elif defined(MCU_6800_4BIT)
LCD_DataPort = 0x0F;
LCD_Enable();
LCD_A0 = DatCmd;
LCD_RW = 0;
LCD_E = 1;
LCD_DataPort = dByte & 0xF0; //Higher 4-bit
LCD_E = 0;
LCD_E = 1;
LCD_DataPort = dByte << 4; //Lower 4-bit
LCD_E = 0;
LCD_RW = 1;
LCD_Disable();
#elif defined(MCU_8080_8BIT)
LCD_DataPort = 0x00; // Set the port as Output
LCD_Enable();
LCD_A0 = DatCmd;
LCD_RD = 1;
LCD_WR = 0;
LCD_DataPort = dByte;
LCD_WR = 1;
LCD_Disable();
#elif defined(MCU_8080_4BIT)
LCD_DataPort = 0x0F;
LCD_Enable();
LCD_A0 = DatCmd;
LCD_RD = 1;
LCD_WR = 0;
LCD_DataPort = dByte & 0xF0; //Higher 4-bit
LCD_WR = 1;
LCD_WR = 0;
LCD_DataPort = dByte << 4; //Lower 4-bit
LCD_WR = 1;
LCD_Disable();
#elif defined(LCD_4SPI)
LCD_Enable();
LCD_A0 = DatCmd;
spi_sendbyte(dByte);
LCD_Disable();
#elif defined(LCD_3SPI)
LCD_Enable();
spi_sendbit(DatCmd); // Sendout LCD_A0
spi_sendbyte(dByte);
LCD_Disable();
#elif defined(LCD_I2C)
I2C_Start();
I2C_SendByte(LCD_I2C_ADDR);
if (DatCmd == iDat)
{
I2C_SendByte(0x40);
}
else
{
I2C_SendByte(0x00);
}
I2C_SendByte(dByte);
I2C_Stop();
#endif
//DelayUs(100); // Special Delay for Character LCD
}
#ifdef LCD_READABLE
// Read a data from LCD DDRAM
// Page Address & Column Address should be set at first.
// E.G. Gotoxy(PAddr, CAddr);
uint8 LCD_ReadData(void)
{
uint8 dByte;
SendByte(iCmd, 0xE0); // Enter RMW Mode
#if defined(MCU_6800_8BIT)
LCD_DataPort = 0xFF; // Set the port as input
LCD_Enable();
LCD_A0 = iDat;
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;
LCD_Disable();
#elif defined(MCU_8080_8BIT)
LCD_DataPort = 0xFF; // Set the port as input
LCD_Enable();
LCD_A0 = iDat;
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;
LCD_Disable();
#elif defined(LCD_4SPI)
LCD_Enable();
LCD_A0 = DatCmd;
dByte = spi_readbyte();
LCD_Disable();
#elif defined(LCD_3SPI)
LCD_Enable();
spi_sendbit(DatCmd); // Sendout LCD_A0
dByte = spi_readbyte();
LCD_Disable();
#elif defined(LCD_I2C)
I2C_Start();
I2C_SendByte(LCD_I2C_ADDR | 0x01);
dByte = I2C_ReadByte();
I2C_SendAck(1);
I2C_Stop();
#endif
SendByte(iCmd, 0xEE); // Enter RMW Mode
return dByte;
}
// Send a byte overlayed with the orginal data
void AndByte(uint8 dByte)
{
uint8 OldData;
OldData = LCD_ReadData();
SendByte(iDat, OldData|dByte);
}
#endif
// Write a Byte of data to the LCD
void LCD_WriteData(uint8 dByte)
{
#ifdef LCD_READABLE
AndByte(dByte);
#else
SendByte(iDat, dByte);
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -