-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} | ||
} |