|
发表于 2006-10-31 21:54:15
|
显示全部楼层
// synopsys translate_off
`timescale 1 ns / 10 ps
// synopsys translate_on
//这是四个数码管,分时给数据,但人眼看不出来闪烁,呵呵
module sevenseg
(
clk,
reset,
number1, //四个管子分为两组
number2,
dp1, //四个小数点
dp2,
dp3,
dp4,
out_a,
out_b,
out_c,
out_d,
out_e,
out_f,
out_g,
out_dp,
out_sel
);
input clk;
input reset;
input [7:0] number1;
input [7:0] number2;
input dp1;
input dp2;
input dp3;
input dp4;
output out_a;
output out_b;
output out_c;
output out_d;
output out_e;
output out_f;
output out_g;
output out_dp;
output [3:0] out_sel;
wire clk;
wire reset;
wire [7:0] number1;
wire [7:0] number2;
wire dp1;
wire dp2;
wire dp3;
wire dp4;
reg out_a;
reg out_b;
reg out_c;
reg out_d;
reg out_e;
reg out_f;
reg out_g;
reg out_dp;
reg [3:0] out_sel;
reg [9:0]cnt;
reg [3:0]count;
wire [6:0]discode;
always @(posedge reset or posedge clk)
begin
if(reset==1)
cnt <= 10'd0;
else
begin
cnt <= cnt + 10'd1;
end
end
always @(posedge reset or posedge clk)
begin
if(reset==1)
begin
out_sel <= 4'd0;
out_dp <= 1'd1;
end
else
begin
if(cnt<=10'd255)
begin
out_sel <= 4'd1;
out_dp <= ~dp1;
end
else if(cnt<=10'd511)
begin
out_sel <= 4'd2;
out_dp <= ~dp2;
end
else if(cnt<=10'd761)
begin
out_sel <= 4'd4;
out_dp <= ~dp3;
end
else
begin
out_sel <= 4'd8;
out_dp <= ~dp4;
end
end
end
always @(posedge reset or posedge clk)
begin
if(reset==1)
begin
count <= 4'd0;
end
else
begin
if(cnt<=10'd255) count <= number1[7:4];
else if(cnt<=10'd511) count <= number1[3:0];
else if(cnt<=10'd761) count <= number2[7:4];
else count <= number2[3:0];
end
end
always @(posedge reset or posedge clk)
begin
if(reset==1)
begin
out_a <= 1'd1;
out_b <= 1'd1;
out_c <= 1'd1;
out_d <= 1'd1;
out_e <= 1'd1;
out_f <= 1'd1;
out_g <= 1'd1;
end
else
begin
{out_a,out_b,out_c,out_d,out_e,out_f,out_g} <= discode;
end
end
segdec segdec1 (count,discode);
endmodule
module segdec
(
count,
discode
);
input [3:0]count;
output [6:0]discode;
reg [6:0]discode;
always @ (count)
begin
discode = 7'b1111111;
case(count)
4'd0: discode = 7'b0000001;
4'd1: discode = 7'b1001111;
4'd2: discode = 7'b0010010;
4'd3: discode = 7'b0000110;
4'd4: discode = 7'b1001100;
4'd5: discode = 7'b0100100;
4'd6: discode = 7'b0100000;
4'd7: discode = 7'b0001111;
4'd8: discode = 7'b0000000;
4'd9: discode = 7'b0000100;
4'd10: discode = 7'b0001000;
4'd11: discode = 7'b1100000;
4'd12: discode = 7'b0110001;
4'd13: discode = 7'b1000010;
4'd14: discode = 7'b0110000;
4'd15: discode = 7'b0111000;
endcase
end
endmodule |
|