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
| Port | Direction | Type | Description |
|---|---|---|---|
clk | in | 1 bit | Clock |
rst | in | 1 bit | Synchronous reset (active high) |
write | in | 1 bit | Request to display char |
char | in | 8-bit vector | Character to display |
lcd_d | out | 4-bit vector | Display data nibble |
lcd_rs | out | 1 bit | Register select, 0 for commands and 1 for character data |
lcd_e | out | 1 bit | Enable strobe; the display samples on its falling edge |
ready | out | 1 bit | High once startup is complete |
busy | out | 1 bit | High while a startup or character nibble sequence runs |
Behavior
- After reset is released,
busygoes high and the sequencer begins the startup ritual lcd_rsis low for every wake nibble and startup command nibble- Every nibble uses the same strobe shape
- First,
lcd_dandlcd_rsare set whilelcd_estays low for exactly 1 clock - Then
lcd_eis high for exactly 2 clocks while the data and register select remain stable - Then
lcd_efalls 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
0x3nibble, waits exactly 20 clocks, then sends another0x3 - It waits exactly 20 clocks, sends a third
0x3, waits exactly 20 clocks, then sends one0x2 - The
0x2nibble switches the display into four-bit mode - After the
0x2strobe, startup sends five full commands in order - Each command uses two consecutive nibble strobes, with the high nibble first
- Function set
0x28is followed by exactly 8 wait clocks - Display off
0x08is followed by exactly 8 wait clocks - Clear display
0x01is followed by exactly 40 wait clocks - Entry mode
0x06is followed by exactly 8 wait clocks - Display on
0x0Cis followed by exactly 8 wait clocks busyremains high from reset release through the final startup wait- After the final wait,
readygoes high,busygoes low, andreadystays high until reset - A high
writeis accepted only whenreadyis high andbusyis low charis 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_rshigh - 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
busyis high for the whole accepted character sequence, including both waitsreadyremains high during character writes- Writes that land before
readyrises, or whilebusyis still high, are ignored rsthigh 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_dandlcd_rson everylcd_efalling edge and checks each nibble's value and exact position - It checks the 100-clock wake wait and the
0x3,0x3,0x3,0x2ritual 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
busyandreadyfrom the contract and checks them on every clock, so ignored writes must leave no mark - It swaps
charone 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
everything is synchronous to clk; inputs are sampled on rising edges, and all outputs are registered.
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.
Click Run to execute your code. Output will appear here.