📄 lcd.c
字号:
/*******************************************************************************
* Function Name : LCD_SendMasterData
* Description : Display one byte data to master LCD.
* Input : - Data: the user expected data to display on master LCD.
* Output : None
* Return : None
*******************************************************************************/
void LCD_SendMasterData(u8 Data)
{
/* Check the master status */
LCD_CheckMasterStatus();
/* Configure Data lines as Output */
LCD_DataLinesConfig(Output);
/* Start the master send data sequence */
LCD_CtrlLinesWrite(GPIO9, CtrlPin_E1, Bit_RESET); /* E1 = 0 */
LCD_CtrlLinesWrite(GPIO9, CtrlPin_RW, Bit_RESET); /* RW = 0 */
LCD_CtrlLinesWrite(GPIO9, CtrlPin_DI, Bit_SET); /* DI = 1 */
LCD_CtrlLinesWrite(GPIO9, CtrlPin_E1, Bit_SET); /* E1 = 1 */
/* Write data to the master */
LCD_DataLinesWrite(GPIO8, (u32)Data);
LCD_CtrlLinesWrite(GPIO9, CtrlPin_E1, Bit_RESET); /* E1 = 0 */
}
/*******************************************************************************
* Function Name : LCD_ReadMasterData
* Description : Read master byte data displayed on master LCD.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
u32 LCD_ReadMasterData(void)
{
u32 MasterData = 0;
/* Check the master status */
LCD_CheckMasterStatus();
/* Configure Data lines as Input */
LCD_DataLinesConfig(Input);
/* Start the master read data sequence */
LCD_CtrlLinesWrite(GPIO9, CtrlPin_E1, Bit_RESET); /* E1 = 0 */
LCD_CtrlLinesWrite(GPIO9, CtrlPin_RW, Bit_SET); /* RW = 1 */
LCD_CtrlLinesWrite(GPIO9, CtrlPin_DI, Bit_SET); /* DI = 1 */
LCD_CtrlLinesWrite(GPIO9, CtrlPin_E1, Bit_SET); /* E1 = 1 */
/* Read data from the master */
MasterData = (GPIO_Read(GPIO8));
LCD_CtrlLinesWrite(GPIO9, CtrlPin_E1, Bit_RESET); /* E1 = 0 */
/* Read the master returned data */
return MasterData;
}
/*******************************************************************************
* Function Name : LCD_SendSlaveData
* Description : Display one byte data to slave LCD.
* Input : - Data: the user expected data to display on slave LCD.
* Output : None
* Return : None
*******************************************************************************/
void LCD_SendSlaveData(u8 Data)
{
/* Check the slave status */
LCD_CheckSlaveStatus();
/* Configure Data lines as Output */
LCD_DataLinesConfig(Output);
/* Start the slave send data sequence */
LCD_CtrlLinesWrite(GPIO9, CtrlPin_E2, Bit_RESET); /* E2 = 0 */
LCD_CtrlLinesWrite(GPIO9, CtrlPin_RW, Bit_RESET); /* RW = 0 */
LCD_CtrlLinesWrite(GPIO9, CtrlPin_DI, Bit_SET); /* DI = 1 */
LCD_CtrlLinesWrite(GPIO9, CtrlPin_E2, Bit_SET); /* E2 = 1 */
/* Write data to the slave */
LCD_DataLinesWrite(GPIO8, (u32)Data);
LCD_CtrlLinesWrite(GPIO9, CtrlPin_E2, Bit_RESET); /* E2 = 0 */
}
/*******************************************************************************
* Function Name : LCD_ReadSlaveData
* Description : Read slave byte data displayed on slave LCD.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
u32 LCD_ReadSlaveData(void)
{
u32 SlaveData = 0;
/* Check the slave status */
LCD_CheckSlaveStatus();
/* Configure Data lines as Input */
LCD_DataLinesConfig(Input);
/* Start the slave read data sequence */
LCD_CtrlLinesWrite(GPIO9, CtrlPin_E2, Bit_RESET); /* E2 = 0 */
LCD_CtrlLinesWrite(GPIO9, CtrlPin_RW, Bit_SET); /* RW = 1 */
LCD_CtrlLinesWrite(GPIO9, CtrlPin_DI, Bit_SET); /* DI = 1 */
LCD_CtrlLinesWrite(GPIO9, CtrlPin_E2, Bit_SET); /* E2 = 1 */
/* Read data from the slave */
SlaveData = GPIO_Read(GPIO8);
LCD_CtrlLinesWrite(GPIO9, CtrlPin_E2, Bit_RESET); /* E2 = 0 */
/* Read the slave returned data */
return SlaveData;
}
/*******************************************************************************
* Function Name : LCD_Init
* Description : Initialize master and slave LCD.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void LCD_Init(void)
{
/* Enable GPIO Clock */
/* Configure control lines signals as output mode */
LCD_CtrlLinesConfig();
/* Master LCD Init */
LCD_SendMasterCmd(SOFTWARE_RESET);
LCD_SendMasterCmd(DISPLAY_OFF);
LCD_SendMasterCmd(DYNAMIC_DRIVE);
LCD_SendMasterCmd(DUTY_CYCLE);
LCD_SendMasterCmd(CLOCKWISE_OUTPUT);
LCD_SendMasterCmd(READ_MODIFY_WRITE_OFF);
LCD_SendMasterCmd(START_COLUMN); /* Set master column address to 0 */
LCD_SendMasterCmd(START_LINE); /* Set master display start line to 0 */
LCD_SendMasterCmd(DISPLAY_ON );
/* Slave LCD Init */
LCD_SendSlaveCmd(SOFTWARE_RESET);
LCD_SendSlaveCmd(DISPLAY_OFF);
LCD_SendSlaveCmd(DYNAMIC_DRIVE);
LCD_SendSlaveCmd(DUTY_CYCLE);
LCD_SendSlaveCmd(CLOCKWISE_OUTPUT);
LCD_SendSlaveCmd(READ_MODIFY_WRITE_OFF);
LCD_SendSlaveCmd(START_COLUMN ); /* Set slave column address to 0 */
LCD_SendSlaveCmd(START_LINE); /* Set slave display start line to 0 */
LCD_SendSlaveCmd(DISPLAY_ON);
/* Clear LCD */
LCD_Clear();
/* Set current Page to 0 for Master and Slave LCDs */
LCD_SetSlavePage(0);
LCD_SetMasterPage(0);
}
/*******************************************************************************
* Function Name : LCD_SetSlavePage
* Description : Set the display page of slave LCD, the page range is 0 to 3,
* make sure the input will not exceed this range ,otherwise it
* will reach a undecided result.
* Input : - Page: specifies the expected display page of slave LCD
* Output : None
* Return : None
*******************************************************************************/
void LCD_SetSlavePage(u8 Page)
{
static u8 ucLastPage = 255;
/* Set Slave page */
if( Page != ucLastPage )
{
LCD_SendSlaveCmd(0xB8|Page);
ucLastPage = Page;
}
}
/*******************************************************************************
* Function Name : LCD_SetMasterPage
* Description : Set the display page of master LCD, the page range is 0 to 3,
* make sure the input will not exceed this range ,otherwise it
* will reach a undecided result.
* Input : - Page: specifies the expected display page of master LCD
* Output : None
* Return : None
*******************************************************************************/
void LCD_SetMasterPage(u8 Page)
{
static u8 ulLastPage = 255;
/* Set Master page */
if( Page != ulLastPage )
{
LCD_SendMasterCmd(0xB8|Page);
ulLastPage = Page;
}
}
/*******************************************************************************
* Function Name : SetAddress
* Description : Set the display column of slave LCD. Column range is 0 to 61.
* Input : - Address: specifies the expected display column of slave LCD
* Output : None
* Return : None
*******************************************************************************/
void LCD_SetSlaveColumn(u8 Address)
{
/* Set Slave column address */
LCD_SendSlaveCmd(Address&0x7F);
}
/*******************************************************************************
* Function Name : LCD_SetMasterColumn
* Description : Set the display column of master LCD. Column range is 0 to 61.
* Input : - Address: specifies the expected display column of slave LCD
* Output : None
* Return : None
*******************************************************************************/
void LCD_SetMasterColumn(u8 Address)
{
/* Set Master column address */
LCD_SendMasterCmd(Address&0x7F);
}
/*******************************************************************************
* Function Name : LCD_SetTextColor
* Description : Set the text color for LCD.
* Input : - TextColor: BlackText: character on black, bottom on white.
* WhiteText: character on white, bottom on black.
* Output : None
* Return : None
*******************************************************************************/
void LCD_SetTextColor(TextColorMode_TypeDef TextColor)
{
if(TextColor)
{
/* Set White Text color */
TextMode=WhiteText;
}
else
{
/* Set Black Text color */
TextMode=BlackText;
}
}
/*******************************************************************************
* Function Name : LCD_Clear
* Description : Clear the Master and Slave LCDs display.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void LCD_Clear(void)
{
u8 Page = 0, Column = 0;
/* Clear master and slave LCDs page by page */
for (Page=0; Page<4; Page++)
{
/* Set master and slave page by page */
LCD_SetMasterPage(Page);
LCD_SetSlavePage(Page);
/* Set master and slave column address */
LCD_SetMasterColumn(0);
LCD_SetSlaveColumn(0);
/* Send empty data to master and slave column address on the selected page */
for (Column=0; Column<61; Column++)
{
LCD_SendSlaveData(0);
LCD_SendMasterData(0);
}
}
}
/*******************************************************************************
* Function Name : LCD_ClearLine
* Description : Clear the selected line of the LCD.
* Input : - Line: the Line to clear.
* - Line1 (Page0&1): clear the first line
* - Line2 (Page2&3): clear the second line
* Output : None
* Return : None
*******************************************************************************/
void LCD_ClearLine(u8 Line)
{
u8 Page = 0, Column = 0;
/* Clear the slected master and slave line */
for (Page=Line; Page<Line+2; Page++)
{
/* Set master and slave page by page */
LCD_SetMasterPage(Page);
LCD_SetSlavePage(Page);
/* Set master and slave column address */
LCD_SetMasterColumn(0);
LCD_SetSlaveColumn(0);
/* Send empty data to master and slave column address on the selected page */
for (Column=0; Column<61; Column++)
{
LCD_SendSlaveData(0);
LCD_SendMasterData(0);
}
}
}
/*******************************************************************************
* Function Name : LCD_ClearMaster
* Description : Clear the master LCD.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void LCD_ClearMaster(void)
{
u8 Page = 0, Column = 0;
/* Clear all master LCD pages */
for (Page=0; Page<4; Page++)
{
/* Set master page by page */
LCD_SetMasterPage(Page);
/* Set master column address */
LCD_SetMasterColumn(0);
/* Send empty data to master column address on the selected page */
for (Column=0; Column<61; Column++)
{
LCD_SendMasterData(0);
}
}
}
/*******************************************************************************
* Function Name : LCD_ClearSlave
* Description : Clear the slave LCD.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void LCD_ClearSlave()
{
u8 Page = 0, Column = 0;
/* Clear all slave LCD pages */
for (Page=0; Page<4; Page++)
{
/* Set slave page by page */
LCD_SetSlavePage(Page);
/* Set slave column address */
LCD_SetSlaveColumn(0);
/* Send empty data to slave column address on the selected page */
for (Column=0; Column<61; Column++)
{
LCD_SendSlaveData(0);
}
}
}
/*******************************************************************************
* Function Name : LCD_DrawChar
* Description : Draw a character in LCD.
* Note:
* the LCD can only display two line character,so page 0 and 1
* is to display the first line, page2 and page 3 is to display
* the second line.
* Input : - Line: the Line where to display the character shape .
* - Line1 (Page0&1): display character on the first line
* - Line2 (Page2&3): display character on the second line
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -