Skip to content

Instantly share code, notes, and snippets.

@Wonicon
Created May 4, 2016 16:51
Show Gist options
  • Save Wonicon/33f13db002b1123dd31f099e9ad83e12 to your computer and use it in GitHub Desktop.
Save Wonicon/33f13db002b1123dd31f099e9ad83e12 to your computer and use it in GitHub Desktop.
数码管
reg [7:0] an;
always @(posedge CLK100MHZ) begin
if (reset) begin
an <= 8'b1111_1110;
end
else begin
an <= { an[6:0], an[7] };
end
end
reg [2:0] idx;
always @(an) begin
case (an)
8'b11111110: idx = 0;
8'b11111101: idx = 1;
8'b11111011: idx = 2;
8'b11110111: idx = 3;
8'b11101111: idx = 4;
8'b11011111: idx = 5;
8'b10111111: idx = 6;
8'b01111111: idx = 7;
default: idx = 0;
endcase
end
wire [4:0] Byte = data[idx+:4];
reg [6:0] seg;
always @(Byte)
case (Byte)
4'h0: seg = 7'b1000000;
4'h1: seg = 7'b1111001;
4'h2: seg = 7'b0100100;
4'h3: seg = 7'b0110000;
4'h4: seg = 7'b0011001;
4'h5: seg = 7'b0010010;
4'h6: seg = 7'b0000010;
4'h7: seg = 7'b1111000;
4'h8: seg = 7'b0000000;
4'h9: seg = 7'b0011000;
4'hA: seg = 7'b0001000;
4'hB: seg = 7'b0000011;
4'hC: seg = 7'b1000110;
4'hD: seg = 7'b0100001;
4'hE: seg = 7'b0000110;
4'hF: seg = 7'b0001110;
default: seg = 7'b1001001;
endcase
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment