#lcd-display #hd44780 #devices #mode #pin #screen

no-std lcd

Hitachi HD44780-compatible LCD screen support for embedded development

7 unstable releases

0.4.1 Jan 3, 2022
0.4.0 Jan 3, 2022
0.4.0-alpha.0 Feb 15, 2021
0.3.0 Sep 27, 2017
0.1.1 Sep 11, 2017

#709 in Embedded development

Download history 18/week @ 2024-06-17 28/week @ 2024-06-24 16/week @ 2024-07-01 10/week @ 2024-07-08 13/week @ 2024-07-15 18/week @ 2024-07-22 27/week @ 2024-07-29 16/week @ 2024-08-05 20/week @ 2024-08-12 12/week @ 2024-08-19 9/week @ 2024-08-26 7/week @ 2024-09-02 17/week @ 2024-09-09 9/week @ 2024-09-16 52/week @ 2024-09-23 21/week @ 2024-09-30

99 downloads per month
Used in lcd-pcf8574

MIT/Apache

22KB
300 lines

crates.io crates.io CircleCI Codecov

lcd

Library that implements low-level protocol to the Hitachi HD44780-compatible LCD device.

Provides high-level API to the Hitachi HD44780-compatible LCD device. Uses 4-bit mode by default (only uses 4 data pins) plus two control pins (R/S and EN). R/W pin is not used and should be wired for "write" (low-level, 0).

The implementation is completely stateless. Client is free to reuse the same Display object or to create one every time access to LCD is required.

Display also implements core::fmt::Write trait, so it could be used as a target of write! macro.

This library does not depend on std crate and could be used in bare metal embedded development.

Examples

use core::fmt::Write; // for write!
use lcd::*;

// implement HAL...
struct HW {
    // any data needed to access low-level peripherals
}

// implement `Hardware` trait to give access to LCD pins
impl Hardware for HW {
    fn rs(&mut self, bit: bool) {
        // should set R/S pin on LCD screen
    }
    fn enable(&mut self, bit: bool) {
        // should set EN pin on LCD screen
    }
    fn data(&mut self, data: u8) {
        // should set data bits to the LCD screen (only lowest 4 bits are used in 4-bit mode).
    }

    // optionally, override the following function to switch to 8-bit mode
    fn mode(&self) -> lcd::FunctionMode {
        lcd::FunctionMode::Bit8
    }

    // optionally, implement the following three functions to enable polling busy flag instead of delay
    fn can_read(&self) -> bool {
        true
    }

    fn rw(&mut self, bit: bool) {
        // configure pins for input _before_ setting R/W to 1
        // configure pins for output _after_ setting R/W to 0
    }
    fn read_data(&mut self) -> u8 {
        0 // read data from the port
    }
}

// implement `Delay` trait to allow library to sleep for the given amount of time
impl Delay for HW {
    fn delay_us(&mut self, delay_usec: u32) {
        // should sleep for the given amount of microseconds
    }
}


// create HAL and LCD instances
let hw = HW { /* ... */ };
let mut lcd = Display::new(hw);

// initialization
lcd.init(FunctionLine::Line2, FunctionDots::Dots5x8);
lcd.display(
    DisplayMode::DisplayOn,
    DisplayCursor::CursorOff,
    DisplayBlink::BlinkOff);
lcd.entry_mode(EntryModeDirection::EntryRight, EntryModeShift::NoShift);

// print something
write!(&mut lcd, "Hello, my number today is {: >4}", 42).unwrap();

See lcd-example-bluepill for the working example for the Blue Pill development board.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps