/******************************************************************************* * Function Name: LCD_Char_1_WrDatNib ******************************************************************************** * * Summary: * Writes a data nibble to the LCD module. * * Parameters: * nibble: byte containing nibble in least significant nibble to be written * to LCD module. * * Return: * None. * *******************************************************************************/ static void LCD_Char_1_WrDatNib(uint8 nibble) { LCD_Char_1_IsReady(); /* RS shoul be low to select data register */ LCD_Char_1_PORT_DR_REG |= LCD_Char_1_RS; /* Reset RW for write operation */ LCD_Char_1_PORT_DR_REG &= ((uint8)(~LCD_Char_1_RW)); /* Two following lines of code will provide us with 40ns delay */ /* Clear data pins */ LCD_Char_1_PORT_DR_REG &= ((uint8)(~LCD_Char_1_DATA_MASK)); /* Write in data, bring E high*/ #if(0u != LCD_Char_1_PORT_SHIFT) /* MISRA forbids shift by 0 so need to handle that */ LCD_Char_1_PORT_DR_REG |= (LCD_Char_1_E | ((uint8)(((uint8) nibble) << LCD_Char_1_PORT_SHIFT))); #else LCD_Char_1_PORT_DR_REG |= (LCD_Char_1_E | nibble); #endif /* (0u != LCD_Char_1_PORT_SHIFT) */ /* Minimum of 230 ns delay */ CyDelayUs(1u); LCD_Char_1_PORT_DR_REG &= ((uint8)(~LCD_Char_1_E)); }
/******************************************************************************* * Function Name: LCD_Char_1_LoadCustomFonts ******************************************************************************** * * Summary: * Loads 8 custom font characters into the LCD Module for use. Cannot use * characters from two different font sets at once, but font sets can be * switched out during runtime. * * Parameters: * customData: pointer to a constant array of 64 bytes representing 8 custom * font characters. * Return: * None. * * Theory: * Prior to using this function user need to import the pointer to custom * font array to your project by writting the following in the source code file * where custom font will be used: * extern uint8 const CYCODE LCD_Char_customFonts[]; * This function is not automatically called by the Start() routine and must be * called manually by the user. *******************************************************************************/ void LCD_Char_1_LoadCustomFonts(const uint8* customData) { uint8 indexU8; LCD_Char_1_IsReady(); /* Set starting address in the LCD Module */ /* Optionally: Read the current address to restore at a later time */ LCD_Char_1_WriteControl(LCD_Char_1_CGRAM_0); /* Load in the 64 bytes of CustomChar Data */ for(indexU8 = 0u; indexU8 < LCD_Char_1_CUSTOM_CHAR_SET_LEN; indexU8++) { /* Delay between each write */ LCD_Char_1_WriteData(customData[indexU8]); } LCD_Char_1_IsReady(); LCD_Char_1_WriteControl(LCD_Char_1_DDRAM_0); }
/******************************************************************************* * Function Name: LCD_Char_1_WriteData ******************************************************************************** * * Summary: * Writes a data byte to the LCD module's Data Display RAM. * * Parameters: * dByte: Byte to be written to the LCD module * * Return: * None. * *******************************************************************************/ void LCD_Char_1_WriteData(uint8 dByte) { uint8 nibble; LCD_Char_1_IsReady(); nibble = dByte >> LCD_Char_1_NIBBLE_SHIFT; /* Write high nibble */ LCD_Char_1_WrDatNib(nibble); nibble = dByte & LCD_Char_1_NIBBLE_MASK; /* Write low nibble */ LCD_Char_1_WrDatNib(nibble); }
/******************************************************************************* * Function Name: LCD_Char_1_WriteControl ******************************************************************************** * * Summary: * Writes a command byte to the LCD module. * * Parameters: * cByte: The byte to be written to theLCD module * * Return: * None. * *******************************************************************************/ void LCD_Char_1_WriteControl(uint8 cByte) { uint8 nibble; LCD_Char_1_IsReady(); nibble = cByte >> LCD_Char_1_NIBBLE_SHIFT; /* WrCntrlNib(High Nibble) */ LCD_Char_1_WrCntrlNib(nibble); nibble = cByte & LCD_Char_1_NIBBLE_MASK; /* WrCntrlNib(Low Nibble) */ LCD_Char_1_WrCntrlNib(nibble); }