1.实验要求
(1)系统时钟频率为50MHZ
(2)刷新时钟频率为1000HZ
(3)使用12位的拨码开关sw,两两做为一组,实现对六位数码管的控制显示
(4)数码管的显示有段码(seg)和位码(an)两个部分,段码的部分是显示数码管的数字,位码的部分显示数码管的位置,位码采用共阴极的显示。
2.代码设计
module smg(
input clk,
input [11:0] sw,
output [7:0] seg,
output [5:0] an
);
reg [14:0] cnt = 15'b0;
reg divclk = 0;
reg [1:0] disp_dat;
reg [2:0] disp_bit;
parameter half_cntvalue = 25000;
always @ (posedge clk )begin
if(cnt ==half_cntvalue)
begin
divclk <= ~divclk;
cnt <= 0;
end
else
cnt <= cnt + 1'b1;
end
always @ (posedge clk )begin
if(disp_bit > 5)
disp_bit <= 0;
else
disp_bit <= disp_bit + 1;
case(disp_bit)
0:begin
disp_dat = sw[1:0];
an = 6'b111110;
end
1:begin
disp_dat = sw[3:2];
an = 6'b111101;
end
2:begin
disp_dat = sw[5:4];
an = 6'b111011;
end
3:begin
disp_dat = sw[7:6];
an = 6'b110111;
end
4:begin
disp_dat = sw[9:8];
an = 6'b101111;
end
5:begin
disp_dat = sw[11:10];
an = 6'b011111;
end
defalut:begin
disp_dat = 0;
an = 6'b111111;
end
endcase
end
always @ (disp_dat)
begin
case(disp_dat)
0:seg = 8'h3f;
1:seg = 8'h06;
2:seg = 8'h3b;
3:seg = 8'h4f;
endcase
end
endmodule