Skip to content

Commit

Permalink
HD44780 LCD example
Browse files Browse the repository at this point in the history
  • Loading branch information
burrbull committed Jul 25, 2021
1 parent 9214d0b commit 3fd490c
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ mfrc522 = "0.2.0"
serde_derive = "1.0.90"
usb-device = "0.2.3"
usbd-serial = "0.1.0"
hd44780-driver = "0.4.0"

[dev-dependencies.byteorder]
default-features = false
Expand Down Expand Up @@ -150,3 +151,7 @@ required-features = ["has-can", "rt"]
[[example]]
name = "gpio_input"
required-features = ["stm32f103"]

[[example]]
name = "lcd"
required-features = ["stm32f103"]
62 changes: 62 additions & 0 deletions examples/lcd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//! HD44780 LCD 4-line mode test
#![deny(unsafe_code)]
#![no_std]
#![no_main]

extern crate panic_halt;

use cortex_m_rt::entry;
use hd44780_driver::{Cursor, CursorBlink, Display, DisplayMode, HD44780};
use stm32f1xx_hal::{afio::AfioExt, delay::Delay, flash::FlashExt, gpio::GpioExt, rcc::RccExt};

// Connections:
// VSS: GND
// VDD: 5V
// V0: 10k poti between 5V and GND
// RS: PD1
// RW: GND
// E: PD2
// D4-D7: PD4-PD7
// A: 5V
// K: GND

#[entry]
fn main() -> ! {
let cp = cortex_m::Peripherals::take().unwrap();
let dp = stm32f1xx_hal::pac::Peripherals::take().unwrap();

let mut flash = dp.FLASH.constrain();
let mut rcc = dp.RCC.constrain();
let gpioa = dp.GPIOA.split(&mut rcc.apb2);
let mut gpiob = dp.GPIOB.split(&mut rcc.apb2);
let mut afio = dp.AFIO.constrain(&mut rcc.apb2);

let (_pa15, pb3, pb4) = afio.mapr.disable_jtag(gpioa.pa15, gpiob.pb3, gpiob.pb4);

let clocks = rcc.cfgr.freeze(&mut flash.acr);
let mut delay = Delay::new(cp.SYST, clocks);

let d7 = pb3.into_push_pull_output(&mut gpiob.crl);
let d6 = pb4.into_push_pull_output(&mut gpiob.crl);
let d5 = gpiob.pb5.into_push_pull_output(&mut gpiob.crl);
let d4 = gpiob.pb6.into_push_pull_output(&mut gpiob.crl);
let rs = gpiob.pb7.into_push_pull_output(&mut gpiob.crl);
let en = gpiob.pb8.into_push_pull_output(&mut gpiob.crh);

let mut lcd = HD44780::new_4bit(rs, en, d4, d5, d6, d7, &mut delay).unwrap();
lcd.reset(&mut delay).unwrap();
lcd.clear(&mut delay).unwrap();
lcd.set_display_mode(
DisplayMode {
display: Display::On,
cursor_visibility: Cursor::Visible,
cursor_blink: CursorBlink::On,
},
&mut delay,
)
.unwrap();
lcd.write_str("Hello, world!", &mut delay).unwrap();

loop {}
}

0 comments on commit 3fd490c

Please sign in to comment.