EXPERIMENT: simple display features test
This commit is contained in:
parent
e019c23620
commit
c3596588b1
@ -66,63 +66,6 @@ static void MX_I2C1_Init(void);
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
void lcd_send_cmd (char cmd)
|
||||
{
|
||||
char data_u, data_l;
|
||||
uint8_t data_t[4];
|
||||
data_u = (cmd & 0xf0);
|
||||
data_l = ((cmd << 4) & 0xf0);
|
||||
data_t[0] = data_u|0x0C; //en=1, rs=0
|
||||
data_t[1] = data_u|0x08; //en=0, rs=0
|
||||
data_t[2] = data_l|0x0C; //en=1, rs=0
|
||||
data_t[3] = data_l|0x08; //en=0, rs=0
|
||||
HAL_I2C_Master_Transmit (&hi2c1, SLAVE_ADDRESS_LCD, (uint8_t *) data_t, 4, 100);
|
||||
}
|
||||
|
||||
void lcd_send_data (char data)
|
||||
{
|
||||
char data_u, data_l;
|
||||
uint8_t data_t[4];
|
||||
data_u = (data&0xf0);
|
||||
data_l = ((data<<4)&0xf0);
|
||||
data_t[0] = data_u|0x0D; //en=1, rs=1
|
||||
data_t[1] = data_u|0x09; //en=0, rs=1
|
||||
data_t[2] = data_l|0x0D; //en=1, rs=1
|
||||
data_t[3] = data_l|0x09; //en=0, rs=1
|
||||
HAL_I2C_Master_Transmit (&hi2c1, SLAVE_ADDRESS_LCD,(uint8_t *) data_t, 4, 100);
|
||||
}
|
||||
|
||||
void lcd_init (void)
|
||||
{
|
||||
// Initialization by Instruction (from HD44780U Datasheet)
|
||||
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); // Wait for command execution lengt
|
||||
|
||||
lcd_send_cmd (0x20); // Set Interface to 4-bit mode
|
||||
HAL_Delay(10);
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
void lcd_send_string (char *str) {
|
||||
while (*str) lcd_send_data(*str++);
|
||||
}
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/**
|
||||
@ -161,8 +104,9 @@ int main(void)
|
||||
char buf [] = "Hallo THM";
|
||||
//CDC_Transmit_FS(buf, sizeof(buf));
|
||||
|
||||
floatpump::LCD_I2C_Driver display(hi2c1, SLAVE_ADDRESS_LCD);
|
||||
display.LCDInitialize();
|
||||
auto &display = floatpump::LCD_I2C_Driver::getInstance(hi2c1, SLAVE_ADDRESS_LCD);
|
||||
display.LCDSetBacklight(false);
|
||||
HAL_Delay(1000);
|
||||
display.LCDSetBacklight(true);
|
||||
display.LCDSendCString(buf);
|
||||
HAL_Delay(1000);
|
||||
@ -175,7 +119,7 @@ int main(void)
|
||||
|
||||
HAL_Delay(1000);
|
||||
display.LCDSetCursor(18, 3);
|
||||
display.LCDSendCString("XX");
|
||||
//display.LCDSendCString("XX");
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user