Hello !
I've been working on with a librabry I've found on website.
It workes sometimes and sometimes no due to some delay issues. Although I have a question to ask here.
- Does HD44780 when powered up works in 4 bit more or 8 bit mode ? Couldn't find in datasheet or perhaps I am blind
: https://www.sparkfun.com/datasheets/LCD/HD44780.pdf
- What if in initialization I send 0011 and after that 0000 ? I know I have to send 0011 but I sent into the same pin later 0000. In Init I've sent 0011 and 0000, the librabry I took it didn't mention anything about it.
- How it logically works (theoretically), that sending the display mode 0011 which switches to 8 bit mode still can read in 4 bit mode while initialization.
- Last question, how does it also work logically that reading 3 times 0011 it ignores the rest data **** but repeating the same command after the third time : 0011, we must add the rest so it reads it like 0011 0000. And then it works as 8 bit mode.
This is the library :
Init :
Send command :
Send to LCD :
I've been working on with a librabry I've found on website.
It workes sometimes and sometimes no due to some delay issues. Although I have a question to ask here.
- Does HD44780 when powered up works in 4 bit more or 8 bit mode ? Couldn't find in datasheet or perhaps I am blind
- What if in initialization I send 0011 and after that 0000 ? I know I have to send 0011 but I sent into the same pin later 0000. In Init I've sent 0011 and 0000, the librabry I took it didn't mention anything about it.
- How it logically works (theoretically), that sending the display mode 0011 which switches to 8 bit mode still can read in 4 bit mode while initialization.
- Last question, how does it also work logically that reading 3 times 0011 it ignores the rest data **** but repeating the same command after the third time : 0011, we must add the rest so it reads it like 0011 0000. And then it works as 8 bit mode.
This is the library :
Init :
C:
void lcd_init (void)
{
// 4 bit initialisation
HAL_Delay(50); // wait for >40ms
lcd_send_cmd (0x30);
HAL_Delay(5); // wait for >4.1ms
lcd_send_cmd (0x30);
HAL_Delay(1); // wait for >100us
lcd_send_cmd (0x30);
HAL_Delay(10);
lcd_send_cmd (0x20); // 4bit mode
HAL_Delay(10);
// dislay initialisation
lcd_send_cmd (0x28); // Function set --> DL=0 (4 bit mode), N = 1 (2 line display) F = 0 (5x8 characters)
HAL_Delay(1);
lcd_send_cmd (0x08); //Display on/off control --> D=0,C=0, B=0 ---> display off
HAL_Delay(1);
lcd_send_cmd (0x01); // clear display
HAL_Delay(1);
HAL_Delay(1);
lcd_send_cmd (0x06); //Entry mode set --> I/D = 1 (increment cursor) & S = 0 (no shift)
HAL_Delay(1);
lcd_send_cmd (0x0C); //Display on/off control --> D = 1, C and B = 0. (Cursor and blink, last two bits)
}
C:
void lcd_send_cmd (char cmd)
{
char datatosend;
/* send upper nibble first */
datatosend = ((cmd>>4)&0x0f);
send_to_lcd(datatosend,0); // RS must be 0 while sending command
/* send Lower Nibble */
datatosend = ((cmd)&0x0f);
send_to_lcd(datatosend, 0);
}
C:
void send_to_lcd (char data, int rs)
{
HAL_GPIO_WritePin(RS_GPIO_Port, RS_Pin, rs); // rs = 1 for data, rs=0 for command
/* write the data to the respective pin */
HAL_GPIO_WritePin(D7_GPIO_Port, D7_Pin, ((data>>3)&0x01));
HAL_GPIO_WritePin(D6_GPIO_Port, D6_Pin, ((data>>2)&0x01));
HAL_GPIO_WritePin(D5_GPIO_Port, D5_Pin, ((data>>1)&0x01));
HAL_GPIO_WritePin(D4_GPIO_Port, D4_Pin, ((data>>0)&0x01));
/* Toggle EN PIN to send the data
* if the HCLK > 100 MHz, use the 20 us delay
* if the LCD still doesn't work, increase the delay to 50, 80 or 100..
*/
HAL_GPIO_WritePin(EN_GPIO_Port, EN_Pin, 1);
delay (20);
HAL_GPIO_WritePin(EN_GPIO_Port, EN_Pin, 0);
delay (20);
}


