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
clkin1 bitClock
rstin1 bitSynchronous reset (active high)
writein1 bitRequest to display char
charin8-bit vectorCharacter to display
lcd_dout4-bit vectorDisplay data nibble
lcd_rsout1 bitRegister select, 0 for commands and 1 for character data
lcd_eout1 bitEnable strobe; the display samples on its falling edge
readyout1 bitHigh once startup is complete
busyout1 bitHigh while a startup or character nibble sequence runs

Behavior

  • After reset is released, busy goes high and the sequencer begins the startup ritual
  • lcd_rs is low for every wake nibble and startup command nibble
  • Every nibble uses the same strobe shape
  • First, lcd_d and lcd_rs are set while lcd_e stays low for exactly 1 clock
  • Then lcd_e is high for exactly 2 clocks while the data and register select remain stable
  • Then lcd_e 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 remains high from reset release through the final startup wait
  • After the final wait, ready goes high, busy goes low, and ready stays high until reset
  • A high write is accepted only when ready is high and busy is low
  • char 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 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 is high for the whole accepted character sequence, including both waits
  • ready remains high during character writes
  • Writes that land before ready rises, or while busy is still high, are ignored
  • rst 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 and lcd_rs on every lcd_e 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 and ready from the contract and checks them on every clock, so ignored writes must leave no mark
  • It swaps char 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; 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.