/********************************************************************************************* Function name : HD44780_Init Author : Grant Phillips Date Modified : 16/10/2013 Compiler : Keil ARM-MDK (uVision V4.70.0.0) Description : Initializes the HD44780 lcd module Special Note(s) : NONE Parameters : NONE Return value : NONE *********************************************************************************************/ void HD44780_Init(void) { //GPIO Initialization GPIO_InitTypeDef GPIO_InitStruct; /* Configure the peripheral clocks for the HD44780 data and control lines */ //RCC_AHBPeriphClockCmd(HD44780_RCC_AHBPeriph, ENABLE); __GPIOC_CLK_ENABLE(); /* Configure the HD44780 Data lines (DB7 - DB4) as outputs*/ GPIO_InitStruct.Pin = HD44780_DATABIT7 | HD44780_DATABIT6 | HD44780_DATABIT5 | HD44780_DATABIT4; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Alternate = 0; HAL_GPIO_Init(HD44780_DATAPORT, &GPIO_InitStruct); /* Configure the HD44780 Control lines (RS, RW, EN) as outputs*/ GPIO_InitStruct.Pin = HD44780_RS_BIT | HD44780_RW_BIT | HD44780_EN_BIT; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Alternate = 0; HAL_GPIO_Init(HD44780_DATAPORT, &GPIO_InitStruct); /* clear control bits */ hd44780_EN_Off(); hd44780_RS_Off(); hd44780_RW_Off(); /* wait initial delay for LCD to settle */ /* reset procedure - 3 function calls resets the device */ hd44780_init_delay(); hd44780_wr_hi_nibble( HD44780_CMD_RESET ); hd44780_init_delay2(); hd44780_wr_hi_nibble( HD44780_CMD_RESET ); hd44780_init_delay3(); hd44780_wr_hi_nibble( HD44780_CMD_RESET ); #if HD44780_CONF_BUS == HD44780_FUNC_BUS_4BIT /* 4bit interface */ hd44780_wr_hi_nibble( HD44780_CMD_FUNCTION ); #endif /* HD44780_CONF_BUS == HD44780_FUNC_BUS_4BIT */ /* sets the configured values - can be set again only after reset */ hd44780_function( HD44780_CONF_BUS, HD44780_CONF_LINES, HD44780_CONF_FONT ); /* turn the display on with no cursor or blinking */ hd44780_display( HD44780_DISP_ON, HD44780_DISP_CURS_OFF, HD44780_DISP_BLINK_OFF ); /* clear the display */ hd44780_clear(); /* addr increment, shift cursor */ hd44780_entry( HD44780_ENTRY_ADDR_INC, HD44780_ENTRY_SHIFT_CURS ); }
/* 4bit bus version */ void hd44780_write( unsigned char data ) { /* send the data bits - high nibble first */ hd44780_wr_hi_nibble( data ); hd44780_wr_lo_nibble( data ); }