Practice

Service LCD Startup

Gorseby Cold Store fitted a green two-line character display behind its fogged service-panel window. Four data pins drove it. After power-up, it stayed blank.

The old controller sent characters as soon as power arrived. This display family wakes in eight-bit mode, so it ignored them. It needs a fixed ritual of nibbles and waits before it listens in four-bit mode.

Your task: build the startup sequencer that performs this ritual exactly. Once ready, it sends each character as two timed nibbles, with the high nibble first.

Interface

PortDirectionTypeDescription
clk_iin1 bitClock
rst_iin1 bitSynchronous reset (active high)
write_iin1 bitRequest to display char_i
char_iin8-bit vectorCharacter to display
lcd_d_oout4-bit vectorDisplay data nibble
lcd_rs_oout1 bitRegister select, 0 for commands and 1 for character data
lcd_e_oout1 bitEnable strobe; the display samples on its falling edge
ready_oout1 bitHigh once startup is complete
busy_oout1 bitHigh while a startup or character nibble sequence runs

Behavior

  • After reset is released, busy_o goes high and the sequencer begins the startup ritual
  • lcd_rs_o is low for every wake nibble and startup command nibble
  • Every nibble uses the same strobe shape
  • First, lcd_d_o and lcd_rs_o are set while lcd_e_o stays low for exactly 1 clock
  • Then lcd_e_o is high for exactly 2 clocks while the data and register select remain stable
  • Then lcd_e_o falls low, and the display samples the nibble on that falling edge
  • The data and register select remain stable for 1 more clock after the falling edge
  • The wake ritual waits exactly 100 clocks before sending its first nibble
  • It sends one 0x3 nibble, waits exactly 20 clocks, then sends another 0x3
  • It waits exactly 20 clocks, sends a third 0x3, waits exactly 20 clocks, then sends one 0x2
  • The 0x2 nibble switches the display into four-bit mode
  • After the 0x2 strobe, startup sends five full commands in order
  • Each command uses two consecutive nibble strobes, with the high nibble first
  • Function set 0x28 is followed by exactly 8 wait clocks
  • Display off 0x08 is followed by exactly 8 wait clocks
  • Clear display 0x01 is followed by exactly 40 wait clocks
  • Entry mode 0x06 is followed by exactly 8 wait clocks
  • Display on 0x0C is followed by exactly 8 wait clocks
  • busy_o remains high from reset release through the final startup wait
  • After the final wait, ready_o goes high, busy_o goes low, and ready_o stays high until reset
  • A high write_i is accepted only when ready_o is high and busy_o is low
  • char_i is captured at acceptance, so later changes cannot affect the accepted character
  • An accepted character is sent as two nibbles, with the high nibble first and lcd_rs_o high
  • Character nibbles use the same strobe shape as startup nibbles
  • After the first character nibble, the sequencer waits exactly 4 clocks before starting the second nibble
  • After the second character nibble, the sequencer waits exactly 8 clocks
  • busy_o is high for the whole accepted character sequence, including both waits
  • ready_o remains high during character writes
  • Writes that land before ready_o rises, or while busy_o is still high, are ignored
  • rst_i high at any rising edge drives every output low and discards all current progress
  • When reset is released, the whole ritual restarts from the 100-clock wait

What the bench checks

  • The testbench plays the display: it samples lcd_d_o and lcd_rs_o on every lcd_e_o falling edge and checks each nibble's value and exact position
  • It checks the 100-clock wake wait and the 0x3, 0x3, 0x3, 0x2 ritual with its exact 20-clock gaps
  • It checks the five startup commands high nibble first, with 8 wait clocks after each and 40 after clear display
  • It checks every strobe's shape: 1 setup clock, exactly 2 enable clocks, and data stable 1 clock past the falling edge
  • It rebuilds busy_o and ready_o from the contract and checks them on every clock, so ignored writes must leave no mark
  • It swaps char_i one clock after acceptance and checks that the captured character is the one displayed
  • It resets during strobes and waits and checks a fresh ritual starting from the 100-clock wait

Constraints

TIMING: everything is synchronous to clk_i; inputs are sampled on rising edges, and all outputs are registered.

SCOPE: the display's R/W pin is tied low on this board, so nothing is ever read back and the busy flag is never polled. Clock counts are scaled stand-ins that preserve the ritual's shape, not real milliseconds.

Do not add ports.

Loading editor...

Click Run to execute your code. Output will appear here.