module led(
input clk,
input reset,
output reg[7:0] dtube_data,
output reg[3:0] dtube_cs_n
);
parameter NUM0 = 8'h3f,//c0,
NUM1 = 8'h06,//f9,
NUM2 = 8'h5b,//a4,
NUM3 = 8'h4f,//b0,
NUM4 = 8'h66,//99,
NUM5 = 8'h6d,//92,
NUM6 = 8'h7d,//82,
NUM7 = 8'h07,//F8,
NUM8 = 8'h7f,//80,
NUM9 = 8'h6f,//90,
NUMA = 8'h77,//88,
NUMB = 8'h7c,//83,
NUMC = 8'h39,//c6,
NUMD = 8'h5e,//a1,
NUME = 8'h79,//86,
NUMF = 8'h71,//8e;
NDOT = 8'h80;
reg [25:0] cnt;
reg[15:0] led_drive;
reg[3:0] current_led_drive;
reg[7:0] cs_cnt;
//1s
always@(posedge clk)
begin
if(!reset) cnt<=0;
else if(cnt>26'd49_999_999) cnt<=0;
else
cnt<=cnt+1'b1;
end
//leddrive
always@(posedge clk)
begin
if(!reset) led_drive<=16'b0;
else if(cnt==26'd49_999_999) led_drive<=led_drive+1'b1;
else led_drive<=led_drive;
end
always@(posedge clk)
begin
if(!reset) cs_cnt<=7'b0;
else cs_cnt<=cs_cnt+1'b1;
end
always@(posedge clk)
begin
if(!reset) dtube_cs_n<=4'b1;
else
begin
case(cs_cnt[7:6])
2'b00:begin
dtube_cs_n<=4'b1110;
current_led_drive<=led_drive[3:0];
end
2'b01:begin
dtube_cs_n<=4'b1101;
current_led_drive<=led_drive[7:4];
end
2'b10:begin
dtube_cs_n<=4'b1011;
current_led_drive<=led_drive[11:8];
end
2'b11:begin
dtube_cs_n<=4'b0111;
current_led_drive<=led_drive[15:12];
end
endcase
end
end
always@(posedge clk)
begin
case(current_led_drive)
4'b0000:dtube_data<=NUM0;
4'b0001:dtube_data<=NUM1;
4'b0010:dtube_data<=NUM2;
4'b0011:dtube_data<=NUM3;
4'b0100:dtube_data<=NUM4;
4'b0101:dtube_data<=NUM5;
4'b0110:dtube_data<=NUM6;
4'b0111:dtube_data<=NUM7;
4'b1000:dtube_data<=NUM8;
4'b1001:dtube_data<=NUM9;
4'b1010:dtube_data<=NUMA;
4'b1011:dtube_data<=NUMB;
4'b1100:dtube_data<=NUMC;
4'b1101:dtube_data<=NUMD;
4'b1110:dtube_data<=NUME;
4'b1111:dtube_data<=NUMF;
endcase
end
endmodule
数码管驱动
最新推荐文章于 2024-08-28 16:03:16 发布