Last active
February 6, 2020 20:03
-
-
Save niw/16fec684ea7927ceb36230361e738470 to your computer and use it in GitHub Desktop.
Learning Chisel: Mux to decode unsigned integer to 7-seg LED
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import chisel3._ | |
import chisel3.util._ | |
class SevenSegLED extends Module { | |
val io = IO(new Bundle { | |
val input = Input(UInt(4.W)) | |
val output = Output(UInt(8.W)) | |
}) | |
io.output := MuxCase( | |
"b1111_1111".U, | |
Seq( | |
(io.input === "h0".U) -> "b1100_0000".U, | |
(io.input === "h1".U) -> "b1111_1001".U, | |
(io.input === "h2".U) -> "b1010_0100".U, | |
(io.input === "h3".U) -> "b1011_0000".U, | |
(io.input === "h4".U) -> "b1001_1001".U, | |
(io.input === "h5".U) -> "b1001_0010".U, | |
(io.input === "h6".U) -> "b1000_0010".U, | |
(io.input === "h7".U) -> "b1111_1000".U, | |
(io.input === "h8".U) -> "b1000_0000".U, | |
(io.input === "h9".U) -> "b1001_1000".U, | |
(io.input === "hA".U) -> "b1000_1000".U, | |
(io.input === "hB".U) -> "b1000_0011".U, | |
(io.input === "hC".U) -> "b1100_0110".U, | |
(io.input === "hD".U) -> "b1010_0001".U, | |
(io.input === "hE".U) -> "b1000_0110".U, | |
(io.input === "hF".U) -> "b1000_1110".U, | |
) | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment