📄 segmain.v
字号:
module segmain(clk,reset_n,datain,seg_data,seg_com);
input clk;
input reset_n;
input [15:0] datain;
output [7:0]seg_data;
output [3:0]seg_com;
reg [3:0]seg_com;
reg [7:0]seg_data;
reg [3:0]bcd_led;
reg [36:0]count;
always @(posedge clk)
begin
if(!reset_n)
count<=0;
else
count<=count+1'b1;
end
always @(count[13:12] or datain )
begin
case(count[13:12])
2'b00:
begin
//bcd_led = 4'h0;//;
seg_data = LedSegOutput(datain[15:12]);
seg_com = 4'b1110;
end
2'b01:
begin
seg_data = LedSegOutput(datain[11:8]);
seg_com=4'b1101;
end
2'b10:
begin
seg_data = LedSegOutput(datain[7:4]);
seg_com=4'b1011;
end
2'b11:
begin
seg_data = LedSegOutput(datain[3:0]);
seg_com=4'b0111;
end
endcase
end
function [7:0] LedSegOutput;
input [3:0]LedBcd;
case (LedBcd)
4'h0:LedSegOutput=8'hc0;// 0
4'h1:LedSegOutput=8'hf9;// 1
4'h2:LedSegOutput=8'ha4;// 2
4'h3:LedSegOutput=8'hb0;// 3
4'h4:LedSegOutput=8'h99;// 4
4'h5:LedSegOutput=8'h92;// 5
4'h6:LedSegOutput=8'h82;// 6
4'h7:LedSegOutput=8'hf8;// 7
4'h8:LedSegOutput=8'h80;// 8
4'h9:LedSegOutput=8'h90;// 9
4'ha:LedSegOutput=8'h88;// A
4'hb:LedSegOutput=8'h83;// b
4'hc:LedSegOutput=8'hc6;// c
4'hd:LedSegOutput=8'ha1;// D
4'he:LedSegOutput=8'h86;// E
4'hf:LedSegOutput=8'h8e;// F
endcase
endfunction
endmodule
/**************************************************************
-- DESCRIPTION : BIN to seven segments converter
-- segment encoding
-- a
-- +---+
-- f | | b
-- +---+ <- g
-- e | | c
-- +---+
-- d
-- Outputs (data_out) active : low
**************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -