void Init_LCD(void) { char k; ddr_lcd = 0xFF; for (k=0;k<3;k++) { _delay_ms(15); CLEAR_LCD_E;port_lcd&= ~0xF0; // Load data to port port_lcd|=0x30; SET_LCD_WRITE ; // Set LCD to write SET_LCD_CMD; // Set LCD to command _delay_us(5); SET_LCD_E; // Write data to LCD _delay_us(3); CLEAR_LCD_E; _delay_us(5); // Disable LCD port_lcd&= ~0xF0; } //delay_ms(5); LCD_Write4Control (0x20); _delay_ms(1); LCD_WriteControl (0x2F); //Разрядность шины 4, кол-во строк 2, шрифт 5x10. LCD_Clear();//Очистить дисплей, установить курсор в начальную позицию. LCD_WriteControl (0x06);//Сдвиг курсора вправо. LCD_WriteControl (0x0E);//Включить дисплей, зажечь курсор. }
// *************************************************** // // *** Position the LCD cursor at "row", "column". *** // // *************************************************** // void LCD_Cursor (char row, char column) { switch (row) { case 1: LCD_WriteControl (0x80 + column - 1); break; case 2: LCD_WriteControl (0xc0 + column - 1); break; case 3: LCD_WriteControl (0x94 + column - 1); break; case 4: LCD_WriteControl (0xd4 + column - 1); break; default: break; } }
/** ****************************************************************************** ** ** Function Name : LCD_Cursor ** ** Description : Position the LCD cursor at "row", "column". ** ** Passed Parameters : None ** ** Modified Data : None ** ** Return Value : None ** ****************************************************************************** */ void LCD_Cursor( uint8 row, uint8 column ) { switch( row ) { case 1: LCD_WriteControl( 1, 0x80 + column - 1 ); break; case 2: LCD_WriteControl( 1, 0xc0 + column - 1 ); break; case 3: LCD_WriteControl( 2, 0x80 + column - 1 ); break; case 4: LCD_WriteControl( 2, 0xc0 + column - 1 ); break; default: break; } }
/** ****************************************************************************** ** ** Function Name : LCD_DefineCharacter ** ** Description : Define dot pattern for user-defined character. ** ** Passed Parameters : address = address of character( 0x00-0x07 ) ** pattern = pointer to 8-byte array containing ** the dot pattern ** Modified Data : None ** ** Return Value : None ** ****************************************************************************** */ void LCD_DefineChar( uint8 address, const uint8 *pattern ) { uint8 i; LCD_WriteControl( 1, 0x40 +( address << 3 ) ); LCD_WriteControl( 2, 0x40 +( address << 3 ) ); for( i=0; i<8; i++ ) { LCD_WriteData( 1, *pattern++ ); LCD_WriteData( 2, *pattern++ ); } }
/** ****************************************************************************** ** ** Function Name : LCD_InitDriver ** ** Description : Initialize the LCD driver. ** ** Passed Parameters : None ** ** Modified Data : None ** ** Return Value : None ** ****************************************************************************** */ static void LCD_InitDriver( void ) { LCD_WriteControl( 1, 0x38 ); Delay(10); LCD_WriteControl( 1, 0x38 ); Delay(10); LCD_WriteControl( 1, 0x38 ); Delay(10); LCD_WriteControl( 1, 0x06 ); Delay(10); LCD_WriteControl( 1, 0x0c ); Delay(10); LCD_WriteControl( 2, 0x38 ); Delay(10); LCD_WriteControl( 2, 0x38 ); Delay(10); LCD_WriteControl( 2, 0x38 ); Delay(10); LCD_WriteControl( 2, 0x06 ); Delay(10); LCD_WriteControl( 2, 0x0c ); Delay(10); }
/******************************************************************************* * Function Name: LCD_Init ******************************************************************************** * * Summary: * Perform initialization required for components normal work. * This function initializes the LCD hardware module as follows: * Enable 4-bit interface * Clear the display * Enable auto cursor increment * Resets the cursor to start position * Also loads custom character set to LCD if it was defined in the customizer. * * Parameters: * None. * * Return: * None. * * Reentrant: * No. * *******************************************************************************/ void LCD_Init(void) { /* INIT CODE */ CyDelay(40u); /* Delay 40 ms */ LCD_WrCntrlNib(LCD_DISPLAY_8_BIT_INIT); /* Selects 8-bit mode */ CyDelay(5u); /* Delay 5 ms */ LCD_WrCntrlNib(LCD_DISPLAY_8_BIT_INIT); /* Selects 8-bit mode */ CyDelay(15u); /* Delay 15 ms */ LCD_WrCntrlNib(LCD_DISPLAY_8_BIT_INIT); /* Selects 8-bit mode */ CyDelay(1u); /* Delay 1 ms */ LCD_WrCntrlNib(LCD_DISPLAY_4_BIT_INIT); /* Selects 4-bit mode */ CyDelay(5u); /* Delay 5 ms */ LCD_WriteControl(LCD_CURSOR_AUTO_INCR_ON); /* Incr Cursor After Writes */ LCD_WriteControl(LCD_DISPLAY_CURSOR_ON); /* Turn Display, Cursor ON */ LCD_WriteControl(LCD_DISPLAY_2_LINES_5x10); /* 2 Lines by 5x10 Characters */ LCD_WriteControl(LCD_DISPLAY_CURSOR_OFF); /* Turn Display, Cursor OFF */ LCD_WriteControl(LCD_CLEAR_DISPLAY); /* Clear LCD Screen */ LCD_WriteControl(LCD_DISPLAY_ON_CURSOR_OFF); /* Turn Display ON, Cursor OFF */ LCD_WriteControl(LCD_RESET_CURSOR_POSITION); /* Set Cursor to 0,0 */ CyDelay(5u); #if(LCD_CUSTOM_CHAR_SET != LCD_NONE) LCD_LoadCustomFonts(LCD_customFonts); #endif /* LCD_CUSTOM_CHAR_SET != LCD_NONE */ }
/******************************************************************************* * Function Name: LCD_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_LoadCustomFonts(uint8 const customData[]) { uint8 indexU8; LCD_IsReady(); /* Set starting address in the LCD Module. * Optionally: Read the current address to restore at a later time. */ LCD_WriteControl(LCD_CGRAM_0); /* Load in the 64 bytes of CustomChar Data */ for(indexU8 = 0u; indexU8 < LCD_CUSTOM_CHAR_SET_LEN; indexU8++) { LCD_WriteData(customData[indexU8]); } LCD_IsReady(); LCD_WriteControl(LCD_DDRAM_0); }
/******************************************************************************* * Function Name: LCD_Position ******************************************************************************** * * Summary: * Moves active cursor location to a point specified by the input arguments * * Parameters: * row: Specific row of LCD module to be written * column: Column of LCD module to be written * * Return: * None. * * Note: * This only applies for LCD displays which use the 2X40 address mode. * This results in Row 2 offset from row one by 0x28. * When there are more than 2 rows, each row must be fewer than 20 characters. * *******************************************************************************/ void LCD_Position(uint8 row, uint8 column) { switch (row) { case (uint8)0: LCD_WriteControl(LCD_ROW_0_START + column); break; case (uint8) 1: LCD_WriteControl(LCD_ROW_1_START + column); break; case (uint8) 2: LCD_WriteControl(LCD_ROW_2_START + column); break; case (uint8) 3: LCD_WriteControl(LCD_ROW_3_START + column); break; default: /* if default case is hit, invalid row argument was passed.*/ break; } }
/** ****************************************************************************** ** ** Function Name : LCD_CursorLeft ** ** Description : Move the cursor left by one character. ** ** Passed Parameters : None ** ** Modified Data : None ** ** Return Value : None ** ****************************************************************************** */ void LCD_CursorLeft( void ) { LCD_WriteControl( 1, 0x10 ); }
// ************************** // // *** Turn the cursor on *** // // ************************** // void LCD_Cursor_On (void) { LCD_WriteControl (LCD_CURS_ON); }
/** ****************************************************************************** ** ** Function Name : LCD_DisplayOn ** ** Description : Turn On LCD. ** ** Passed Parameters : None ** ** Modified Data : None ** ** Return Value : None ** ****************************************************************************** */ void LCD_DisplayOn( void ) { LCD_WriteControl( 1, 0x0c ); LCD_WriteControl( 2, 0x0c ); }
// *************************** // // *** Turn the cursor off *** // // *************************** // void LCD_Cursor_Off (void) { LCD_WriteControl (LCD_ON); }
/** ****************************************************************************** ** ** Function Name : LCD_CursorOff ** ** Description : Turns the cursor off. ** ** Passed Parameters : None ** ** Modified Data : None ** ** Return Value : None ** ****************************************************************************** */ void LCD_CursorOff( void ) { LCD_WriteControl( 1, 0x0c ); }
/** ****************************************************************************** ** ** Function Name : LCD_DisplayOff ** ** Description : Turn Off LCD. ** ** Passed Parameters : None ** ** Modified Data : None ** ** Return Value : None ** ****************************************************************************** */ void LCD_DisplayOff( void ) { LCD_WriteControl( 1, 0x08 ); LCD_WriteControl( 2, 0x08 ); }
/** ****************************************************************************** ** ** Function Name : LCD_CursorRight ** ** Description : Move the cursor right by one character. ** ** Passed Parameters : None ** ** Modified Data : None ** ** Return Value : None ** ****************************************************************************** */ void LCD_CursorRight( void ) { LCD_WriteControl( 1, 0x14 ); }
/** ****************************************************************************** ** ** Function Name : LCD_CursorOn ** ** Description : Turns the cursor on. ** ** Passed Parameters : None ** ** Modified Data : None ** ** Return Value : None ** ****************************************************************************** */ void LCD_CursorOn( void ) { LCD_WriteControl( 1, 0x0d ); }
// ************************************************ // // *** Clear the LCD screen (also homes cursor) *** // // ************************************************ // void LCD_Clear(void) { LCD_WriteControl(0x01); }
void LCD_Display_Off (void) { LCD_WriteControl(LCD_OFF); }
/** ****************************************************************************** ** ** Function Name : LCD_Home ** ** Description : Position the LCD cursor at row 1, col 1. ** ** Passed Parameters : None ** ** Modified Data : None ** ** Return Value : None ** ****************************************************************************** */ void LCD_Home( void ) { LCD_WriteControl( 1, 0x02 ); }
/** ****************************************************************************** ** ** Function Name : LCD_Clear ** ** Description : Clear the LCD screen(also homes cursor). ** ** Passed Parameters : None ** ** Modified Data : None ** ** Return Value : None ** ****************************************************************************** */ void LCD_Clear(void) { LCD_WriteControl( 1, 0x01 ); LCD_WriteControl( 2, 0x01 ); }
void LCD_Display_On (void) { LCD_WriteControl(LCD_ON); }