08 · Switches, keys, LEDs and the 7-segment display

The board's own inputs and outputs, done properly: debounced switches and keys, a press counter in decimal, and text scrolling across the six digits.

Verified on the board 2026-10-24 (text mode) Quartus Prime Lite 17.1 No shield needed Skill: use-board-io
Download board_io.qar (full project)

The repo keeps the full project (.qar, plus the sources here) but no prebuilt bitstream: one build (a few minutes) makes the .sof on your computer.

What you will see

Two photos of the 7-segment display a second apart, showing 'o dE10' and then 'E10-LI': the message scrolling.

Mode7-segmentLEDs
SW9 up"HELLO dE10-LItE BKM" scrolls; SW3..SW0 set the speedA light running back and forth
SW9 downNumber of KEY0 presses (0 to 999999); KEY1 resets itLEDR mirrors the switches

Your PC (python scripts/de10.py log): SW=3FF, KEY0 down count=000005, KEY1 down: reset.

Block diagram

SW9..0KEY1..0 debounce10 ms steady press → counterKEY1 resets scrolling messagespeed from SW3..0 bin2bcd + seg7_charSW9 picks the mode HEX5..HEX0 LEDR9..0 line_printer → USB

The parts

ThingPinsKnow this
SW9..SW0F15 B14 A14 A13 B12 A12 C12 D12 C11 C101 = up. They bounce like buttons when flipped: debounce them
KEY1, KEY0A7, B80 when pressed (pull-up). Schmitt-trigger inputs, but still bounce
LEDR9..LEDR0B11 A11 D14 E14 C13 D13 B10 A10 A9 A81 = on
HEX5..HEX08 pins each0 = segment on (active low); bit 7 is the decimal point

All pins are in lib/board/de10_lite_pins.csv; scripts/new_project.py assigns them from your top module's port names.

Showing text: seg7_char

seg7_char c(.ch("E"), .dp(1'b0), .seg(HEX5));     // any ASCII: digits, most letters, - _ =

lib/rtl/seg7_char.sv turns an ASCII character into segments: digits, the letters that have a fair 7-segment shape (A b C d E F G H I J L n o P q r S t U y), and a dash for the rest. Numbers in decimal: bin2bcd then 8'h30 + digit.

Counting presses: debounce, then an edge

debounce #(.N(12), .STEADY(500_000)) deb(.clk(clk), .in({~KEY, SW}), .out({key_down, sw}));  // 10 ms
always @(posedge clk) key_d <= key_down;
wire [1:0] press = key_down & ~key_d;     // one clock per press

Without the debounce a single press often counts 2 to 5 times.

Measured on the board

Count mode (SW9 down, KEY0 / KEY1) needs someone at the board; it is still to be checked by hand.

Run it

python scripts/de10.py build examples/08_board_io
python scripts/de10.py program examples/08_board_io
python scripts/de10.py log 30

Build it yourself

python scripts/new_project.py examples/08_board_io board_io_top --lib print debounce bcd seg7
python scripts/de10.py build examples/08_board_io

Files

FileWhat
src/board_io_top.svThe example
lib/rtl/seg7_char.svASCII to 7-segment
lib/rtl/debounce.sv, bin2bcd.svDebouncer; binary to decimal