代码根据动态显示的方式写了一下,麻烦给看一下,谢谢啦~
module sell(reset,clk,seg,dig);
input reset,clk;
output[7:0] seg;
output[7:0] dig;
reg[2:0] D; //状态
reg temp1,temp2; //引入临时变量主要是为了强调下降沿判断为激励有效信号,是其安全可靠
reg[7:0] seg_r; //定义数码管输出寄存器
reg[7:0] dig_r; //定义数码管选择输出寄存器
reg[3:0] disp_dat; //定义数码管显示数据寄存器
reg[1:0] count; //定义计数寄存器
parameter idle=0,half=1,one=2,two=3,three=4; // idle,one,half,two,three为中间状态变量
assign dig = dig_r; //输出数码管选择
assign seg = seg_r; //输出数码管译码结果
always@(posedge clk) //数码管动态扫描显示计数
begin
count <= count+1'b1;
end
always@(posedge clk or negedge reset)
begin
if(!reset) //下降沿复位信号有效
begin
D <= idle;
temp1 <= 0;
temp2 <= 0;
case(count) //使八个数码管首位四个数码管显示0.0 0.0
2'b00 : begin dig_r <= 8'b0111_1111; disp_dat <= 8'h0; end
2'b01 : begin dig_r <= 8'b1011_1111; disp_dat <= 8'h9; end
2'b10 : begin dig_r <= 8'b1111_1101; disp_dat <= 8'h0; end
2'b11 : begin dig_r <= 8'b1111_1110; disp_dat <= 8'h9; end
endcase
end
case(D)
idle:
if(temp1)
begin
case(count) //使八个数码管首位四个数码管显示0.5 00
2'b00 : begin dig_r <= 8'b0111_1111; disp_dat <= 8'h0; end
2'b01 : begin dig_r <= 8'b1011_1111; disp_dat <= 8'h5; end
2'b10 : begin dig_r <= 8'b1111_1101; disp_dat <= 8'h9; end
2'b11 : begin dig_r <= 8'b1111_1110; disp_dat <= 8'h9; end
endcase
D <= half;
end
else if(temp2)
begin
case(count) //使八个数码管首位四个数码管显示1.0 00
2'b00 : begin dig_r <= 8'b0111_1111; disp_dat <= 8'h1; end
2'b01 : begin dig_r <= 8'b1011_1111; disp_dat <= 8'h9; end
2'b10 : begin dig_r <= 8'b1111_1101; disp_dat <= 8'h9; end
2'b11 : begin dig_r <= 8'b1111_1110; disp_dat <= 8'h9; end
endcase
D <= one;
end
half:
if(temp1)
begin
case(count) //使八个数码管首位四个数码管显示1.0 00
2'b00 : begin dig_r <= 8'b0111_1111; disp_dat <= 8'h1; end
2'b01 : begin dig_r <= 8'b1011_1111; disp_dat <= 8'h9; end
2'b10 : begin dig_r <= 8'b1111_1101; disp_dat <= 8'h9; end
2'b11 : begin dig_r <= 8'b1111_1110; disp_dat <= 8'h9; end
endcase
D <= one;
end
else if(temp2)
begin
case(count) //使八个数码管首位四个数码管显示1.5 00
2'b00 : begin dig_r <= 8'b0111_1111; disp_dat <= 8'h1; end
2'b01 : begin dig_r <= 8'b1011_1111; disp_dat <= 8'h5; end
2'b10 : begin dig_r <= 8'b1111_1101; disp_dat <= 8'h9; end
2'b11 : begin dig_r <= 8'b1111_1110; disp_dat <= 8'h9; end
endcase
D <= two;
end
one:
if(temp1)
begin
case(count) //使八个数码管首位四个数码管显示1.5 00
2'b00 : begin dig_r <= 8'b0111_1111; disp_dat <= 8'h1; end
2'b01 : begin dig_r <= 8'b1011_1111; disp_dat <= 8'h5; end
2'b10 : begin dig_r <= 8'b1111_1101; disp_dat <= 8'h9; end
2'b11 : begin dig_r <= 8'b1111_1110; disp_dat <= 8'h9; end
endcase
D <= two;
end
else if(temp2)
begin
case(count) //使八个数码管首位四个数码管显示2.0 00
2'b00 : begin dig_r <= 8'b0111_1111; disp_dat <= 8'h2; end
2'b01 : begin dig_r <= 8'b1011_1111; disp_dat <= 8'h9; end
2'b10 : begin dig_r <= 8'b1111_1101; disp_dat <= 8'h9; end
2'b11 : begin dig_r <= 8'b1111_1110; disp_dat <= 8'h9; end
endcase
D <= three;
end
two:
if(temp1)
begin
case(count) //使八个数码管首位四个数码管显示2.0 00
2'b00 : begin dig_r <= 8'b0111_1111; disp_dat <= 8'h2; end
2'b01 : begin dig_r <= 8'b1011_1111; disp_dat <= 8'h9; end
2'b10 : begin dig_r <= 8'b1111_1101; disp_dat <= 8'h9; end
2'b11 : begin dig_r <= 8'b1111_1110; disp_dat <= 8'h9; end
endcase
D <= three;
end
else if(temp2)
begin
case(count) //使八个数码管首位四个数码管显示2.5 00
2'b00 : begin dig_r <= 8'b0111_1111; disp_dat <= 8'h2; end
2'b01 : begin dig_r <= 8'b1011_1111; disp_dat <= 8'h5; end
2'b10 : begin dig_r <= 8'b1111_1101; disp_dat <= 8'h9; end
2'b11 : begin dig_r <= 8'b1111_1110; disp_dat <= 8'h9; end
endcase
D <= idle;
end
three:
if(temp1)
begin
D <= idle;
case(count) //使八个数码管首位四个数码管显示2.5 00
2'b00 : begin dig_r <= 8'b0111_1111; disp_dat <= 8'h2; end
2'b01 : begin dig_r <= 8'b1011_1111; disp_dat <= 8'h5; end
2'b10 : begin dig_r <= 8'b1111_1101; disp_dat <= 8'h9; end
2'b11 : begin dig_r <= 8'b1111_1110; disp_dat <= 8'h9; end
endcase
end
else if({temp2,one_dollar}==2'b10)
begin
case(count) //使八个数码管首位四个数码管显示3.0 0.5
2'b00 : begin dig_r <= 8'b0111_1111; disp_dat <= 8'h3; end
2'b01 : begin dig_r <= 8'b1011_1111; disp_dat <= 8'h9; end
2'b10 : begin dig_r <= 8'b1111_1101; disp_dat <= 8'h0; end
2'b11 : begin dig_r <= 8'b1111_1110; disp_dat <= 8'h5; end
endcase
D <= idle;
end
default:
begin
case(count) //使八个数码管首位四个数码管显示0.0 0.0
2'b00 : begin dig_r <= 8'b0111_1111; disp_dat <= 8'h0; end
2'b01 : begin dig_r <= 8'b1011_1111; disp_dat <= 8'h9; end
2'b10 : begin dig_r <= 8'b1111_1101; disp_dat <= 8'h0; end
2'b11 : begin dig_r <= 8'b1111_1110; disp_dat <= 8'h9; end
endcase
D <= idle;
end
endcase
end
always@(disp_dat)
begin
case(disp_dat) //八段译码
4'h0: seg_r = 8'h40; //显示0.
4'h1: seg_r = 8'h79; //显示1.
4'h2: seg_r = 8'h24; //显示2.
4'h3: seg_r = 8'h30; //显示3.
4'h4: seg_r = 8'h12; //显示5.
4'h5: seg_r = 8'h92; //显示5
4'h6: seg_r = 8'hb0; //显示3
4'h7: seg_r = 8'ha4; //显示2
4'h8: seg_r = 8'hf9; //显示1
4'h9: seg_r = 8'hc0; //显示0
default: seg_r = 8'hff; //不做显示
endcase
end
endmodule
代码根据动态显示的方式写了一下,麻烦给看一下,谢谢啦~
module sell(reset,clk,seg,dig);
input reset,clk;
output[7:0] seg;
output[7:0] dig;
reg[2:0] D; //状态
reg temp1,temp2; //引入临时变量主要是为了强调下降沿判断为激励有效信号,是其安全可靠
reg[7:0] seg_r; //定义数码管输出寄存器
reg[7:0] dig_r; //定义数码管选择输出寄存器
reg[3:0] disp_dat; //定义数码管显示数据寄存器
reg[1:0] count; //定义计数寄存器
parameter idle=0,half=1,one=2,two=3,three=4; // idle,one,half,two,three为中间状态变量
assign dig = dig_r; //输出数码管选择
assign seg = seg_r; //输出数码管译码结果
always@(posedge clk) //数码管动态扫描显示计数
begin
count <= count+1'b1;
end
always@(posedge clk or negedge reset)
begin
if(!reset) //下降沿复位信号有效
begin
D <= idle;
temp1 <= 0;
temp2 <= 0;
case(count) //使八个数码管首位四个数码管显示0.0 0.0
2'b00 : begin dig_r <= 8'b0111_1111; disp_dat <= 8'h0; end
2'b01 : begin dig_r <= 8'b1011_1111; disp_dat <= 8'h9; end
2'b10 : begin dig_r <= 8'b1111_1101; disp_dat <= 8'h0; end
2'b11 : begin dig_r <= 8'b1111_1110; disp_dat <= 8'h9; end
endcase
end
case(D)
idle:
if(temp1)
begin
case(count) //使八个数码管首位四个数码管显示0.5 00
2'b00 : begin dig_r <= 8'b0111_1111; disp_dat <= 8'h0; end
2'b01 : begin dig_r <= 8'b1011_1111; disp_dat <= 8'h5; end
2'b10 : begin dig_r <= 8'b1111_1101; disp_dat <= 8'h9; end
2'b11 : begin dig_r <= 8'b1111_1110; disp_dat <= 8'h9; end
endcase
D <= half;
end
else if(temp2)
begin
case(count) //使八个数码管首位四个数码管显示1.0 00
2'b00 : begin dig_r <= 8'b0111_1111; disp_dat <= 8'h1; end
2'b01 : begin dig_r <= 8'b1011_1111; disp_dat <= 8'h9; end
2'b10 : begin dig_r <= 8'b1111_1101; disp_dat <= 8'h9; end
2'b11 : begin dig_r <= 8'b1111_1110; disp_dat <= 8'h9; end
endcase
D <= one;
end
half:
if(temp1)
begin
case(count) //使八个数码管首位四个数码管显示1.0 00
2'b00 : begin dig_r <= 8'b0111_1111; disp_dat <= 8'h1; end
2'b01 : begin dig_r <= 8'b1011_1111; disp_dat <= 8'h9; end
2'b10 : begin dig_r <= 8'b1111_1101; disp_dat <= 8'h9; end
2'b11 : begin dig_r <= 8'b1111_1110; disp_dat <= 8'h9; end
endcase
D <= one;
end
else if(temp2)
begin
case(count) //使八个数码管首位四个数码管显示1.5 00
2'b00 : begin dig_r <= 8'b0111_1111; disp_dat <= 8'h1; end
2'b01 : begin dig_r <= 8'b1011_1111; disp_dat <= 8'h5; end
2'b10 : begin dig_r <= 8'b1111_1101; disp_dat <= 8'h9; end
2'b11 : begin dig_r <= 8'b1111_1110; disp_dat <= 8'h9; end
endcase
D <= two;
end
one:
if(temp1)
begin
case(count) //使八个数码管首位四个数码管显示1.5 00
2'b00 : begin dig_r <= 8'b0111_1111; disp_dat <= 8'h1; end
2'b01 : begin dig_r <= 8'b1011_1111; disp_dat <= 8'h5; end
2'b10 : begin dig_r <= 8'b1111_1101; disp_dat <= 8'h9; end
2'b11 : begin dig_r <= 8'b1111_1110; disp_dat <= 8'h9; end
endcase
D <= two;
end
else if(temp2)
begin
case(count) //使八个数码管首位四个数码管显示2.0 00
2'b00 : begin dig_r <= 8'b0111_1111; disp_dat <= 8'h2; end
2'b01 : begin dig_r <= 8'b1011_1111; disp_dat <= 8'h9; end
2'b10 : begin dig_r <= 8'b1111_1101; disp_dat <= 8'h9; end
2'b11 : begin dig_r <= 8'b1111_1110; disp_dat <= 8'h9; end
endcase
D <= three;
end
two:
if(temp1)
begin
case(count) //使八个数码管首位四个数码管显示2.0 00
2'b00 : begin dig_r <= 8'b0111_1111; disp_dat <= 8'h2; end
2'b01 : begin dig_r <= 8'b1011_1111; disp_dat <= 8'h9; end
2'b10 : begin dig_r <= 8'b1111_1101; disp_dat <= 8'h9; end
2'b11 : begin dig_r <= 8'b1111_1110; disp_dat <= 8'h9; end
endcase
D <= three;
end
else if(temp2)
begin
case(count) //使八个数码管首位四个数码管显示2.5 00
2'b00 : begin dig_r <= 8'b0111_1111; disp_dat <= 8'h2; end
2'b01 : begin dig_r <= 8'b1011_1111; disp_dat <= 8'h5; end
2'b10 : begin dig_r <= 8'b1111_1101; disp_dat <= 8'h9; end
2'b11 : begin dig_r <= 8'b1111_1110; disp_dat <= 8'h9; end
endcase
D <= idle;
end
three:
if(temp1)
begin
D <= idle;
case(count) //使八个数码管首位四个数码管显示2.5 00
2'b00 : begin dig_r <= 8'b0111_1111; disp_dat <= 8'h2; end
2'b01 : begin dig_r <= 8'b1011_1111; disp_dat <= 8'h5; end
2'b10 : begin dig_r <= 8'b1111_1101; disp_dat <= 8'h9; end
2'b11 : begin dig_r <= 8'b1111_1110; disp_dat <= 8'h9; end
endcase
end
else if({temp2,one_dollar}==2'b10)
begin
case(count) //使八个数码管首位四个数码管显示3.0 0.5
2'b00 : begin dig_r <= 8'b0111_1111; disp_dat <= 8'h3; end
2'b01 : begin dig_r <= 8'b1011_1111; disp_dat <= 8'h9; end
2'b10 : begin dig_r <= 8'b1111_1101; disp_dat <= 8'h0; end
2'b11 : begin dig_r <= 8'b1111_1110; disp_dat <= 8'h5; end
endcase
D <= idle;
end
default:
begin
case(count) //使八个数码管首位四个数码管显示0.0 0.0
2'b00 : begin dig_r <= 8'b0111_1111; disp_dat <= 8'h0; end
2'b01 : begin dig_r <= 8'b1011_1111; disp_dat <= 8'h9; end
2'b10 : begin dig_r <= 8'b1111_1101; disp_dat <= 8'h0; end
2'b11 : begin dig_r <= 8'b1111_1110; disp_dat <= 8'h9; end
endcase
D <= idle;
end
endcase
end
always@(disp_dat)
begin
case(disp_dat) //八段译码
4'h0: seg_r = 8'h40; //显示0.
4'h1: seg_r = 8'h79; //显示1.
4'h2: seg_r = 8'h24; //显示2.
4'h3: seg_r = 8'h30; //显示3.
4'h4: seg_r = 8'h12; //显示5.
4'h5: seg_r = 8'h92; //显示5
4'h6: seg_r = 8'hb0; //显示3
4'h7: seg_r = 8'ha4; //显示2
4'h8: seg_r = 8'hf9; //显示1
4'h9: seg_r = 8'hc0; //显示0
default: seg_r = 8'hff; //不做显示
endcase
end
endmodule
举报