📄 lcdiof.c
字号:
// ------------------ The Basic I/O functions for LCD --------------------------
/* FileName: lcdiof.c
Version : 0.1
Last Updated: 2007-4-25
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)
{
//PortDir(LCD_CtrlPort_DDR, 0xFF);
//PortDir(LCD_DataPort_DDR, 0xFF);
#if defined(MCU_6800_8BIT)
sbi(LCD_CtrlPort, LCD_BM1);
sbi(LCD_CtrlPort, LCD_BM0);
#elif defined(MCU_6800_4BIT)
sbi(LCD_CtrlPort, LCD_PS);
sbi(LCD_CtrlPort, LCD_C86);
#elif defined(MCU_8080_8BIT)
sbi(LCD_CtrlPort, LCD_BM1);
cbi(LCD_CtrlPort, LCD_BM0);
#elif defined(MCU_8080_4BIT)
sbi(LCD_CtrlPort, LCD_PS);
cbi(LCD_CtrlPort, LCD_C86);
#elif defined(LCD_4SPI)
LCD_DataPort = 0xFF;
cbi(LCD_CtrlPort, LCD_BM1);
cbi(LCD_CtrlPort, LCD_BM0);
sbi(LCD_DataPort, LCD_SM1);
cbi(LCD_DataPort, LCD_SM0);
cbi(LCD_CtrlPort, LCD_WR1);
cbi(LCD_CtrlPort, LCD_WR0);
#elif defined(LCD_3SPI)
spi_init();
/*
cbi(LCD_CtrlPort, LCD_BM1);
sbi(LCD_CtrlPort, LCD_BM0);
sbi(LCD_DataPort, LCD_SM1);
cbi(LCD_DataPort, LCD_SM0);
cbi(LCD_CtrlPort, LCD_WR1);
cbi(LCD_CtrlPort, LCD_WR0);
cbi(LCD_CtrlPort, LCD_A0);
*/
#elif defined(LCD_I2C)
LCD_DataPort_DDR |= (1 << I2C_SDA)|(1 << I2C_SCL);
LCD_DataPort |= (1 << I2C_SDA)|(1 << I2C_SCL);
//sbi(LCD_CtrlPort, LCD_PS);
//sbi(LCD_CtrlPort, LCD_C86);
#endif
}
#endif
#ifdef LCD_RST
// Reset LCD
void LCD_Reset(void)
{
cbi(LCD_CtrlPort, LCD_RST);
DelayUs(10);
sbi(LCD_CtrlPort, LCD_RST);
DelayMs(100);
}
#endif
// Function for sending a byte to LCD
void SendByte(uint8 DatCmd, uint8 dByte)
{
#ifdef MCU_6800_8BIT
PortDir(LCD_DataPort_DDR, 0xFF); // Set the port as Output
LCD_Enable();
//LCD_A0 = DatCmd;
if (DatCmd)
sbi(LCD_CtrlPort, LCD_A0);
else
cbi(LCD_CtrlPort, LCD_A0);
//LCD_RW = 0;
cbi(LCD_CtrlPort, LCD_RW);
//LCD_E = 1;
sbi(LCD_CtrlPort, LCD_E);
LCD_DataPort = dByte;
//LCD_E = 0;
cbi(LCD_CtrlPort, LCD_E);
//LCD_RW = 1;
sbi(LCD_CtrlPort, LCD_RW);
LCD_Disable();
#elif defined(MCU_6800_4BIT)
PortDir(LCD_DataPort_DDR, 0xF0);
LCD_Enable();
if (DatCmd)
sbi(LCD_CtrlPort, LCD_A0);
else
cbi(LCD_CtrlPort, LCD_A0);
cbi(LCD_CtrlPort, LCD_RW);
sbi(LCD_CtrlPort, LCD_E);
LCD_DataPort = dByte & 0xF0; //Higher 4-bit
cbi(LCD_CtrlPort, LCD_E);
sbi(LCD_CtrlPort, LCD_E);
LCD_DataPort = dByte << 4; //Lower 4-bit
cbi(LCD_CtrlPort, LCD_E);
sbi(LCD_CtrlPort, LCD_RW);
LCD_Disable();
#elif defined(MCU_8080_8BIT)
PortDir(LCD_DataPort_DDR, 0xFF); // Set the port as Output
LCD_Enable();
if (DatCmd)
sbi(LCD_CtrlPort, LCD_A0);
else
cbi(LCD_CtrlPort, LCD_A0);
sbi(LCD_CtrlPort, LCD_RD);
cbi(LCD_CtrlPort, LCD_WR);
LCD_DataPort = dByte;
sbi(LCD_CtrlPort, LCD_WR);
LCD_Disable();
#elif defined(MCU_8080_4BIT)
PortDir(LCD_DataPort_DDR, 0xFF);
LCD_Enable();
if (DatCmd)
sbi(LCD_CtrlPort, LCD_A0);
else
cbi(LCD_CtrlPort, LCD_A0);
sbi(LCD_CtrlPort, LCD_RD);
cbi(LCD_CtrlPort, LCD_WR);
LCD_DataPort = dByte & 0xF0; //Higher 4-bit
sbi(LCD_CtrlPort, LCD_WR);
cbi(LCD_CtrlPort, LCD_WR);
LCD_DataPort = dByte << 4; //Lower 4-bit
sbi(LCD_CtrlPort, LCD_WR);
LCD_Disable();
#elif defined(LCD_4SPI)
LCD_Enable();
if (DatCmd)
sbi(LCD_CtrlPort, LCD_A0);
else
cbi(LCD_CtrlPort, LCD_A0);
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, 0xEF); // Enter RMW Mode
#if defined(MCU_6800_8BIT)
PortDir(LCD_DataPort_DDR, 0x00); // Set the port as input
LCD_Enable();
//LCD_A0 = iDat;
if (iDat)
sbi(LCD_CtrlPort, LCD_A0);
else
cbi(LCD_CtrlPort, LCD_A0);
sbi(LCD_CtrlPort, LCD_E);
DelayUs(4); // A dummy read
cbi(LCD_CtrlPort, LCD_E);
DelayUs(4);
sbi(LCD_CtrlPort, LCD_E);
DelayUs(4);
dByte = LCD_DataPins; // Actual read
cbi(LCD_CtrlPort, LCD_E);
LCD_Disable();
#elif defined(MCU_8080_8BIT)
PortDir(LCD_DataPort_DDR, 0x00); // Set the port as input
LCD_Enable();
//LCD_A0 = iDat;
if (iDat)
sbi(LCD_CtrlPort, LCD_A0);
else
cbi(LCD_CtrlPort, LCD_A0);
sbi(LCD_CtrlPort, LCD_WR);
cbi(LCD_CtrlPort, LCD_RD);
DelayUs(4); // A dummy read
sbi(LCD_CtrlPort, LCD_RD);
DelayUs(4);
cbi(LCD_CtrlPort, LCD_RD);
DelayUs(4);
dByte = LCD_DataPins; // Actual read
sbi(LCD_CtrlPort, LCD_RD);
LCD_Disable();
#elif defined(LCD_4SPI)
LCD_Enable();
//LCD_A0 = iDat;
if (iDat)
sbi(LCD_CtrlPort, LCD_A0);
else
cbi(LCD_CtrlPort, LCD_A0);
dByte = spi_readbyte();
LCD_Disable();
#elif defined(LCD_3SPI)
LCD_Enable();
spi_sendbit(iDat); // 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 + -