mirror of
https://github.com/italicsjenga/rp-hal-boards.git
synced 2025-01-11 04:51:31 +11:00
Add HD44780 example (#60)
* Added HD44780 lcd example * Formatting lcd_display.rs * Formatting Cargo.toml * Fixed import formatting issue * Fixed line with spaces
This commit is contained in:
parent
f310d92b64
commit
a02c8131ff
|
@ -21,6 +21,7 @@ paste = "1.0"
|
|||
cortex-m-rt = "0.6.14"
|
||||
panic-halt = "0.2.0"
|
||||
rp2040-boot2 = { git = "https://github.com/rp-rs/rp2040-boot2-rs", branch="main" }
|
||||
hd44780-driver = "0.4.0"
|
||||
|
||||
[features]
|
||||
rt = ["rp2040-pac/rt"]
|
||||
rt = ["rp2040-pac/rt"]
|
||||
|
|
52
rp2040-hal/examples/lcd_display.rs
Normal file
52
rp2040-hal/examples/lcd_display.rs
Normal file
|
@ -0,0 +1,52 @@
|
|||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
use hal::pac;
|
||||
use hal::sio::Sio;
|
||||
use hd44780_driver as hd44780;
|
||||
use panic_halt as _;
|
||||
use rp2040_hal as hal;
|
||||
|
||||
#[link_section = ".boot2"]
|
||||
#[used]
|
||||
pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER;
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let mut pac = pac::Peripherals::take().unwrap();
|
||||
let core = pac::CorePeripherals::take().unwrap();
|
||||
|
||||
// AHL bus speed default
|
||||
let mut delay_provider = cortex_m::delay::Delay::new(core.SYST, 12_000_000);
|
||||
|
||||
let sio = Sio::new(pac.SIO);
|
||||
let pins = hal::gpio::Pins::new(
|
||||
pac.IO_BANK0,
|
||||
pac.PADS_BANK0,
|
||||
sio.gpio_bank0,
|
||||
&mut pac.RESETS,
|
||||
);
|
||||
|
||||
let lcd = hd44780::HD44780::new_4bit(
|
||||
pins.gpio16.into_push_pull_output(), // Register Select
|
||||
pins.gpio17.into_push_pull_output(), // Enable
|
||||
pins.gpio18.into_push_pull_output(), // d4
|
||||
pins.gpio19.into_push_pull_output(), // d5
|
||||
pins.gpio20.into_push_pull_output(), // d6
|
||||
pins.gpio21.into_push_pull_output(), // d7
|
||||
&mut delay_provider,
|
||||
);
|
||||
|
||||
let mut lcd = lcd.unwrap();
|
||||
|
||||
lcd.reset(&mut delay_provider).unwrap();
|
||||
lcd.clear(&mut delay_provider).unwrap();
|
||||
lcd.write_str("rp-hal on", &mut delay_provider).unwrap();
|
||||
lcd.set_cursor_pos(40, &mut delay_provider).unwrap();
|
||||
lcd.set_cursor_visibility(hd44780::Cursor::Visible, &mut delay_provider)
|
||||
.unwrap();
|
||||
lcd.write_str("HD44780!", &mut delay_provider).unwrap();
|
||||
|
||||
loop {}
|
||||
}
|
Loading…
Reference in a new issue