HD44780: switch output from push pull to open drain
This commit is contained in:
parent
babc3a5789
commit
1133e6a296
|
@ -67,20 +67,54 @@
|
|||
/** @defgroup lcd_hd44780_gpio GPIO used to control the HD44780
|
||||
* @{
|
||||
*/
|
||||
/** register select
|
||||
* @note is pulled up by HD44780
|
||||
*/
|
||||
#define LCD_HD44780_GPIO_RS PB9 /**< register select */
|
||||
#if !LCD_HD44780_WRITE_ONLY
|
||||
/** select read or write
|
||||
* @note is pulled up by HD44780
|
||||
*/
|
||||
|
||||
#define LCD_HD44780_GPIO_RW PB10 /**< select read or write */
|
||||
#endif
|
||||
#define LCD_HD44780_GPIO_E PB11 /**< start data read/write */
|
||||
#define LCD_HD44780_GPIO_DB7 PB12 /**< data bit 7 */
|
||||
#define LCD_HD44780_GPIO_DB6 PB13 /**< data bit 6 */
|
||||
#define LCD_HD44780_GPIO_DB5 PB14 /**< data bit 5 */
|
||||
#define LCD_HD44780_GPIO_DB4 PB15 /**< data bit 4 */
|
||||
/** enable pin
|
||||
* @warning needs an external 10k pull-up resistor
|
||||
*/
|
||||
#define LCD_HD44780_GPIO_E PB11
|
||||
/** data bit
|
||||
* @note is pulled up by HD44780
|
||||
*/
|
||||
#define LCD_HD44780_GPIO_DB7 PB12
|
||||
/** data bit 6
|
||||
* @note is pulled up by HD44780
|
||||
*/
|
||||
#define LCD_HD44780_GPIO_DB6 PB13
|
||||
/** data bit 5
|
||||
* @note is pulled up by HD44780
|
||||
*/
|
||||
#define LCD_HD44780_GPIO_DB5 PB14
|
||||
/** data bit 4
|
||||
* @note is pulled up by HD44780
|
||||
*/
|
||||
#define LCD_HD44780_GPIO_DB4 PB15
|
||||
#if LCD_HD44780_INTERFACE_DL
|
||||
#define LCD_HD44780_GPIO_DB3 P /**< data bit 3 */
|
||||
#define LCD_HD44780_GPIO_DB2 P /**< data bit 2 */
|
||||
#define LCD_HD44780_GPIO_DB1 P /**< data bit 1 */
|
||||
#define LCD_HD44780_GPIO_DB0 P /**< data bit 0 */
|
||||
/** data bit 3
|
||||
* @note is pulled up by HD44780
|
||||
*/
|
||||
#define LCD_HD44780_GPIO_DB3 P
|
||||
/** data bit 2
|
||||
* @note is pulled up by HD44780
|
||||
*/
|
||||
#define LCD_HD44780_GPIO_DB2 P
|
||||
/** data bit 1
|
||||
* @note is pulled up by HD44780
|
||||
*/
|
||||
#define LCD_HD44780_GPIO_DB1 P
|
||||
/** data bit 0
|
||||
* @note is pulled up by HD44780
|
||||
*/
|
||||
#define LCD_HD44780_GPIO_DB0 P
|
||||
#endif
|
||||
/** @} */
|
||||
|
||||
|
@ -120,15 +154,15 @@ static void lcd_hd44780_db_direction(bool input)
|
|||
#if !LCD_HD44780_WRITE_ONLY
|
||||
gpio_clear(GPIO_PORT(LCD_HD44780_GPIO_RW), GPIO_PIN(LCD_HD44780_GPIO_RW)); // set low write
|
||||
#endif
|
||||
gpio_set_mode(GPIO_PORT(LCD_HD44780_GPIO_DB7), GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO_PIN(LCD_HD44780_GPIO_DB7));
|
||||
gpio_set_mode(GPIO_PORT(LCD_HD44780_GPIO_DB6), GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO_PIN(LCD_HD44780_GPIO_DB6));
|
||||
gpio_set_mode(GPIO_PORT(LCD_HD44780_GPIO_DB5), GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO_PIN(LCD_HD44780_GPIO_DB5));
|
||||
gpio_set_mode(GPIO_PORT(LCD_HD44780_GPIO_DB4), GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO_PIN(LCD_HD44780_GPIO_DB4));
|
||||
gpio_set_mode(GPIO_PORT(LCD_HD44780_GPIO_DB7), GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO_PIN(LCD_HD44780_GPIO_DB7));
|
||||
gpio_set_mode(GPIO_PORT(LCD_HD44780_GPIO_DB6), GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO_PIN(LCD_HD44780_GPIO_DB6));
|
||||
gpio_set_mode(GPIO_PORT(LCD_HD44780_GPIO_DB5), GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO_PIN(LCD_HD44780_GPIO_DB5));
|
||||
gpio_set_mode(GPIO_PORT(LCD_HD44780_GPIO_DB4), GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO_PIN(LCD_HD44780_GPIO_DB4));
|
||||
#if LCD_HD44780_INTERFACE_DL
|
||||
gpio_set_mode(GPIO_PORT(LCD_HD44780_GPIO_DB3), GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO_PIN(LCD_HD44780_GPIO_DB3));
|
||||
gpio_set_mode(GPIO_PORT(LCD_HD44780_GPIO_DB2), GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO_PIN(LCD_HD44780_GPIO_DB2));
|
||||
gpio_set_mode(GPIO_PORT(LCD_HD44780_GPIO_DB1), GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO_PIN(LCD_HD44780_GPIO_DB1));
|
||||
gpio_set_mode(GPIO_PORT(LCD_HD44780_GPIO_DB0), GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO_PIN(LCD_HD44780_GPIO_DB0));
|
||||
gpio_set_mode(GPIO_PORT(LCD_HD44780_GPIO_DB3), GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO_PIN(LCD_HD44780_GPIO_DB3));
|
||||
gpio_set_mode(GPIO_PORT(LCD_HD44780_GPIO_DB2), GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO_PIN(LCD_HD44780_GPIO_DB2));
|
||||
gpio_set_mode(GPIO_PORT(LCD_HD44780_GPIO_DB1), GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO_PIN(LCD_HD44780_GPIO_DB1));
|
||||
gpio_set_mode(GPIO_PORT(LCD_HD44780_GPIO_DB0), GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO_PIN(LCD_HD44780_GPIO_DB0));
|
||||
#endif
|
||||
}
|
||||
lcd_hd44780_db_input = input; // remember direction
|
||||
|
@ -282,15 +316,15 @@ void lcd_hd44780_setup(bool n_2lines, bool f_5x10)
|
|||
lcd_hd44780_db_input = true; // all lines are inputs
|
||||
rcc_periph_clock_enable(GPIO_RCC(LCD_HD44780_GPIO_RS)); // enable clock for GPIO port
|
||||
gpio_clear(GPIO_PORT(LCD_HD44780_GPIO_RS), GPIO_PIN(LCD_HD44780_GPIO_RS)); // set low to read busy flag
|
||||
gpio_set_mode(GPIO_PORT(LCD_HD44780_GPIO_RS), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO_PIN(LCD_HD44780_GPIO_RS)); // set GPIO as output
|
||||
gpio_set_mode(GPIO_PORT(LCD_HD44780_GPIO_RS), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO_PIN(LCD_HD44780_GPIO_RS)); // set GPIO as output
|
||||
#if !LCD_HD44780_WRITE_ONLY
|
||||
rcc_periph_clock_enable(GPIO_RCC(LCD_HD44780_GPIO_RW)); // enable clock for GPIO port
|
||||
gpio_set(GPIO_PORT(LCD_HD44780_GPIO_RW), GPIO_PIN(LCD_HD44780_GPIO_RW)); // set high to read
|
||||
gpio_set_mode(GPIO_PORT(LCD_HD44780_GPIO_RW), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO_PIN(LCD_HD44780_GPIO_RW)); // set GPIO as output
|
||||
gpio_set_mode(GPIO_PORT(LCD_HD44780_GPIO_RW), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO_PIN(LCD_HD44780_GPIO_RW)); // set GPIO as output
|
||||
#endif
|
||||
rcc_periph_clock_enable(GPIO_RCC(LCD_HD44780_GPIO_E)); // enable clock for GPIO port
|
||||
gpio_clear(GPIO_PORT(LCD_HD44780_GPIO_E), GPIO_PIN(LCD_HD44780_GPIO_E)); // start idle low
|
||||
gpio_set_mode(GPIO_PORT(LCD_HD44780_GPIO_E), GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO_PIN(LCD_HD44780_GPIO_E)); // set GPIO as output
|
||||
gpio_set_mode(GPIO_PORT(LCD_HD44780_GPIO_E), GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO_PIN(LCD_HD44780_GPIO_E)); // set GPIO as output
|
||||
// initialize device
|
||||
sleep_ms(40 + 2); // wait for display to initialise after power on: 15 ms for VCC > 4.5 V, 40 ms for VCC > 2.7 V
|
||||
lcd_hd44780_write(true, 0x30, true); // 1st function write set to go to state 1 (8-bit) or 2 (4-bit first nibble) (BF cannot be checked)
|
||||
|
|
Loading…
Reference in New Issue