place

go home look ,look look

module display( input [2:0] mode_in, // 输入信号,用于选择状态机 input clk, // 输入时钟信号 output reg [3:0] led, // 输出寄存器,用于小灯显示 output reg [7:0] light, // 输出寄存器,用于控制数码管输出 output reg [5:0] place // 输出寄存器,用于控制数码管显示 ); parameter [7:0] a1=8'b10000000; // 定义常量a1 parameter [7:0] a2=8'b01000000; // 定义常量a2 parameter [7:0] a3=8'b00100000; // 定义常量a3 parameter [7:0] a4=8'b00010000; // 定义常量a4 parameter [7:0] a5=8'b00001000; // 定义常量a5 parameter [7:0] a6=8'b00000100; // 定义常量a6 parameter [7:0] a7=8'b00000010; // 定义常量a7 parameter [7:0] a8=8'b00000001; // 定义常量a8 parameter [7:0] c1=8'b00001100; // 定义常量c1 parameter [7:0] c2=8'b01100000; // 定义常量c2 parameter b0=6'b111110; // 定义常量b0 parameter b1=6'b111101; // 定义常量b1 parameter b2=6'b111011; // 定义常量b2 parameter b3=6'b110111; // 定义常量b3 parameter b4=6'b101111; // 定义常量b4 parameter b5=6'b011111; // 定义常量b5 parameter b6=6'b111100; // 定义常量b6 parameter b7=6'b111000; // 定义常量b7 parameter b8=6'b110000; // 定义常量b8 parameter b9=6'b100000; // 定义常量b9 parameter b10=6'b000000; // 定义常量b10 reg [3:0] count; // 定义4位计数器 reg [3:0] state = 4'b0000; // 定义状态寄存器state reg [3:0] state_next = 4'b0000; // 定义下一个状态寄存器state_next reg [3:0] state1 = 4'b0000; // 定义状态寄存器state1 reg [3:0] state_next1 = 4'b0000; // 定义下一个状态寄存器state_next1 reg [4:0] state2 = 5'b00000; // 定义状态寄存器state2 reg [4:0] state_next2 = 5'b00000; // 定义下一个状态寄存器state_next2 reg [3:0] state3 = 4'b0000; // 定义状态寄存器state3 reg [3:0] state_next3 = 4'b0000; // 定义下一个状态寄存器state_next3 reg [4:0] state4 = 5'b00000; // 定义状态寄存器state4 reg [4:0] state_next4 = 5'b00000; // 定义下一个状态寄存器state_next4 reg [3:0] state5 = 4'b0000; // 定义状态寄存器state5 reg [3:0] state_next5 = 4'b0000; // 定义下一个状态寄存器state_next5 reg [4:0] state6 = 5'b00000; // 定义状态寄存器state6 reg [4:0] state_next6 = 5'b00000; // 定义下一个状态寄存器state_next6 reg [5:0] state7 = 6'b000000; // 定义状态寄存器state7 reg [5:0] state_next7 = 6'b000000; // 定义下一个状态寄存器state_next7 always @ (posedge clk) // 时钟信号触发的always块 begin state <= state_next; // 更新状态寄存器 state1 <= state_next1; // 更新状态寄存器 state2 <= state_next2; // 更新状态寄存器 state3 <= state_next3; // 更新状态寄存器 state4 <= state_next4; // 更新状态寄存器 state5 <= state_next5; // 更新状态寄存器 state6 <= state_next6; // 更新状态寄存器 state7 <= state_next7; // 更新状态寄存器 end always @ (posedge clk) // 时钟信号触发的always块 begin if (count == 4'd15) // 如果计数器为15 begin count <= 4'd0; // 计数器清零 led = count; // 输出计数器值 end else begin count <= count + 1'b1; // 计数器加1 led = count; // 输出计数器值 end end always @ (posedge clk) // 时钟信号触发的always块 begin case(mode_in) // 根据输入信号S的值进行状态机选择 3'b000: // 当S为000时 begin case(state) // 根据状态state的值进行状态转移 4'b0000: state_next <= 4'b0001; // 当state为0000时,转移到0001 4'b0001: state_next <= 4'b0010; // 当state为0001时,转移到0010 4'b0010: state_next <= 4'b0011; // ... 4'b0011: state_next <= 4'b0100; 4'b0100: state_next <= 4'b0101; 4'b0101: state_next <= 4'b0110; 4'b0110: state_next <= 4'b0111; 4'b0111: state_next <= 4'b1000; 4'b1000: state_next <= 4'b1001; 4'b1001: state_next <= 4'b1010; 4'b1010: state_next <= 4'b1011; 4'b1011: state_next <= 4'b1100; 4'b1100: state_next <= 4'b1101; 4'b1101: state_next <= 4'b1110; 4'b1110: state_next <= 4'b1111; 4'b1111: state_next <= 4'b0000; endcase case(state_next) 4'd0: begin light=a1; place=b0; end 4'd1: place=b1; 4'd2: place=b2; 4'd3: place=b3; 4'd4: place=b4; 4'd5: place=b5; 4'd6: light=a2; 4'd7: light=a3; 4'd8: light=a4; 4'd9: place=b4; 4'd10: place=b3; 4'd11: place=b2; 4'd12: place=b1; 4'd13: place=b0; 4'd14: light=a5; 4'd15: light=a6; endcase end 3'b001: begin case(state1) 4'b0000: state_next1 <= 4'b0001; 4'b0001: state_next1 <= 4'b0010; 4'b0010: state_next1 <= 4'b0011; 4'b0011: state_next1 <= 4'b0100; 4'b0100: state_next1 <= 4'b0101; 4'b0101: state_next1 <= 4'b0110; 4'b0110: state_next1 <= 4'b0111; 4'b0111: state_next1 <= 4'b1000; 4'b1000: state_next1 <= 4'b1001; 4'b1001: state_next1 <= 4'b1010; 4'b1010: state_next1 <= 4'b1011; 4'b1011: state_next1 <= 4'b1100; 4'b1100: state_next1 <= 4'b1101; 4'b1101: state_next1 <= 4'b1110; 4'b1110: state_next1 <= 4'b1111; 4'b1111: state_next1 <= 4'b0000; endcase case(state_next1) 4'd0: begin light=a1; place=b0; end 4'd1: light=a6; 4'd2: light=a5; 4'd3: light=a4; 4'd4: place=b1; 4'd5: place=b2; 4'd6: place=b3; 4'd7: place=b4; 4'd8: place=b5; 4'd9: light=a3; 4'd10: light=a2; 4'd11: light=a1; 4'd12: place=b4; 4'd13: place=b3; 4'd14: place=b2; 4'd15: place=b1; endcase end 3'b010: begin case(state2) 5'd0: state_next2 <= 5'd1; 5'd1: state_next2 <= 5'd2; 5'd2: state_next2 <= 5'd3; 5'd3: state_next2 <= 5'd4; 5'd4: state_next2 <= 5'd5; 5'd5: state_next2 <= 5'd6; 5'd6: state_next2 <= 5'd7; 5'd7: state_next2 <= 5'd8; 5'd8: state_next2 <= 5'd9; 5'd9: state_next2 <= 5'd10; 5'd10: state_next2 <= 5'd11; 5'd11: state_next2 <= 5'd12; 5'd12: state_next2 <= 5'd13; 5'd13: state_next2 <= 5'd14; 5'd14: state_next2 <= 5'd15; 5'd15: state_next2 <= 5'd16; 5'd16: state_next2 <= 5'd17; 5'd17: state_next2 <= 5'd18; 5'd18: state_next2 <= 5'd19; 5'd19: state_next2 <= 5'd20; 5'd20: state_next2 <= 5'd21; 5'd21: state_next2 <= 5'd22; 5'd22: state_next2 <= 5'd23; 5'd23: state_next2 <= 5'd24; 5'd24: state_next2 <= 5'd25; 5'd25: state_next2 <= 5'd26; 5'd26: state_next2 <= 5'd27; 5'd27: state_next2 <= 5'd28; 5'd28: state_next2 <= 5'd29; 5'd29: state_next2 <= 5'd00; endcase case(state_next2) 5'd0: begin light=a1; place=b0; end 5'd1: place=b1; 5'd2: place=b2; 5'd3: place=b3; 5'd4: place=b4; 5'd5: place=b5; 5'd6: light=a2; 5'd7: light=a3; 5'd8: light=a4; 5'd9: place=b4; 5'd10: place=b3; 5'd11: place=b2; 5'd12: place=b1; 5'd13: place=b0; 5'd14: light=a5; 5'd15: light=a6; 5'd16: light=a5; 5'd17: light=a4; 5'd18: place=b1; 5'd19: place=b2; 5'd20: place=b3; 5'd21: place=b4; 5'd22: place=b5; 5'd23: light=a3; 5'd24: light=a2; 5'd25: light=a1; 5'd26: place=b4; 5'd27: place=b3; 5'd28: place=b2; 5'd29: place=b1; endcase end 3'b011: begin case(state3) 4'b0000: state_next3 <= 4'b0001; 4'b0001: state_next3 <= 4'b0010; 4'b0010: state_next3 <= 4'b0011; 4'b0011: state_next3 <= 4'b0100; 4'b0100: state_next3 <= 4'b0101; 4'b0101: state_next3 <= 4'b0110; 4'b0110: state_next3 <= 4'b0111; 4'b0111: state_next3 <= 4'b1000; 4'b1000: state_next3 <= 4'b1001; 4'b1001: state_next3 <= 4'b1010; 4'b1010: state_next3 <= 4'b1011; 4'b1011: state_next3 <= 4'b1100; 4'b1100: state_next3 <= 4'b1101; 4'b1101: state_next3 <= 4'b1110; 4'b1110: state_next3 <= 4'b1111; 4'b1111: state_next3 <= 4'b0000; endcase case(state_next3) 4'd0: begin light = c1; place = b0; end 4'd1: begin light = c2; place = b0; end 4'd2: begin light = c1; place = b1; end 4'd3: begin light = c2; place = b1; end 4'd4: begin light = c1; place = b2; end 4'd5: begin light = c2; place = b2; end 4'd6: begin light = c1; place = b3; end 4'd7: begin light = c2; place = b3; end 4'd8: begin light = c1; place = b4; end 4'd9: begin light = c2; place = b4; end 4'd10: begin light = c1; place = b5; end 4'd11: begin light = c2; place = b5; end 4'd12: begin light = 00000000; place = 000000; end endcase end 3'b100: begin case(state4) 5'd0: state_next4 <= 5'd1; 5'd1: state_next4 <= 5'd2; 5'd2: state_next4 <= 5'd3; 5'd3: state_next4 <= 5'd4; 5'd4: state_next4 <= 5'd5; 5'd5: state_next4 <= 5'd6; 5'd6: state_next4 <= 5'd7; 5'd7: state_next4 <= 5'd8; 5'd8: state_next4 <= 5'd9; 5'd9: state_next4 <= 5'd10; 5'd10: state_next4 <= 5'd11; 5'd11: state_next4 <= 5'd12; 5'd12: state_next4 <= 5'd13; 5'd13: state_next4 <= 5'd14; 5'd14: state_next4 <= 5'd15; 5'd15: state_next4 <= 5'd16; 5'd16: state_next4 <= 5'd17; 5'd17: state_next4 <= 5'd18; 5'd18: state_next4 <= 5'd19; 5'd19: state_next4 <= 5'd20; 5'd20: state_next4 <= 5'd21; 5'd21: state_next4 <= 5'd00; endcase case(state_next4) 5'd0: begin light = c1; place = b0; end 5'd1: begin light = c2; place = b0; end 5'd2: begin light = c1; place = b1; end 5'd3: begin light = c2; place = b1; end 5'd4: begin light = c1; place = b2; end 5'd5: begin light = c2; place = b2; end 5'd6: begin light = c1; place = b3; end 5'd7: begin light = c2; place = b3; end 5'd8: begin light = c1; place = b4; end 5'd9: begin light = c2; place = b4; end 5'd10: begin light = c1; place = b5; end 5'd11: begin light = c2; place = b5; end 5'd12: begin light = c1; place = b5; end 5'd13: begin light = c2; place = b4; end 5'd14: begin light = c1; place = b4; end 5'd15: begin light = c2; place = b3; end 5'd16: begin light = c1; place = b3; end 5'd17: begin light = c2; place = b2; end 5'd18: begin light = c1; place = b2; end 5'd19: begin light = c2; place = b1; end 5'd20: begin light = c1; place = b1; end 5'd21: begin light = c2; place = b0; end endcase end 3'b101: begin case(state5) 4'b0000: state_next5 <= 4'b0001; 4'b0001: state_next5 <= 4'b0010; 4'b0010: state_next5 <= 4'b0011; 4'b0011: state_next5 <= 4'b0100; 4'b0100: state_next5 <= 4'b0101; 4'b0101: state_next5 <= 4'b0110; 4'b0110: state_next5 <= 4'b0111; 4'b0111: state_next5 <= 4'b1000; 4'b1000: state_next5 <= 4'b1001; 4'b1001: state_next5 <= 4'b0000; endcase case(state_next5) 4'd0: begin light = c1; place = b0; end 4'd1: begin light = c1; place = b6; end 4'd2: begin light = c1; place = b7; end 4'd3: begin light = c1; place = b8; end 4'd4: begin light = c1; place = b9; end 4'd5: begin light = c1; place = b10; end 4'd6: begin light = c1; place = b9; end 4'd7: begin light = c1; place = b8; end 4'd8: begin light = c1; place = b7; end 4'd9: begin light = c1; place = b6; end endcase end 3'b110: begin case(state6) 5'd0: state_next6 <= 5'd1; 5'd1: state_next6 <= 5'd2; 5'd2: state_next6 <= 5'd3; 5'd3: state_next6 <= 5'd4; 5'd4: state_next6 <= 5'd5; 5'd5: state_next6 <= 5'd6; 5'd6: state_next6 <= 5'd7; 5'd7: state_next6 <= 5'd8; 5'd8: state_next6 <= 5'd9; 5'd9: state_next6 <= 5'd10; 5'd10: state_next6 <= 5'd11; 5'd11: state_next6 <= 5'd12; 5'd12: state_next6 <= 5'd13; 5'd13: state_next6 <= 5'd14; 5'd14: state_next6 <= 5'd15; 5'd15: state_next6 <= 5'd16; 5'd16: state_next6 <= 5'd17; 5'd17: state_next6 <= 5'd18; 5'd18: state_next6 <= 5'd19; 5'd19: state_next6 <= 5'd20; 5'd20: state_next6 <= 5'd21; 5'd21: state_next6 <= 5'd22; 5'd22: state_next6 <= 5'd23; 5'd23: state_next6 <= 5'd00; endcase case(state_next6) 5'd0: begin light=a5; place=b0; end 5'd1: light=a6; 5'd2: light=a1; 5'd3: light=a2; 5'd4: light=a3; 5'd5: light=a8; 5'd6: begin light=a4; place=b1; end 5'd7: light=a8; 5'd8: begin light=a5; place=b2; end 5'd9: light=a6; 5'd10: light=a1; 5'd11: light=a2; 5'd12: light=a3; 5'd13: light=a8; 5'd14: begin light=a4; place=b3; end 5'd15: light=a8; 5'd16: begin light=a5; place=b4; end 5'd17: light=a6; 5'd18: light=a1; 5'd19: light=a2; 5'd20: light=a3; 5'd21: light=a8; 5'd22: begin light=a4; place=b5; end 5'd23: light=a8; endcase end 3'b111: begin case(state7) 6'd0: state_next7 <= 6'd1; 6'd1: state_next7 <= 6'd2; 6'd2: state_next7 <= 6'd3; 6'd3: state_next7 <= 6'd4; 6'd4: state_next7 <= 6'd5; 6'd5: state_next7 <= 6'd6; 6'd6: state_next7 <= 6'd7; 6'd7: state_next7 <= 6'd8; 6'd8: state_next7 <= 6'd9; 6'd9: state_next7 <= 6'd10; 6'd10: state_next7 <= 6'd11; 6'd11: state_next7 <= 6'd12; 6'd12: state_next7 <= 6'd13; 6'd13: state_next7 <= 6'd14; 6'd14: state_next7 <= 6'd15; 6'd15: state_next7 <= 6'd16; 6'd16: state_next7 <= 6'd17; 6'd17: state_next7 <= 6'd18; 6'd18: state_next7 <= 6'd19; 6'd19: state_next7 <= 6'd20; 6'd20: state_next7 <= 6'd21; 6'd21: state_next7 <= 6'd22; 6'd22: state_next7 <= 6'd23; 6'd23: state_next7 <= 6'd24; 6'd24: state_next7 <= 6'd25; 6'd25: state_next7 <= 6'd26; 6'd26: state_next7 <= 6'd27; 6'd27: state_next7 <= 6'd28; 6'd28: state_next7 <= 6'd29; 6'd29: state_next7 <= 6'd30; 6'd30: state_next7 <= 6'd31; 6'd31: state_next7 <= 6'd32; 6'd32: state_next7 <= 6'd33; 6'd33: state_next7 <= 6'd34; 6'd34: state_next7 <= 6'd35; 6'd35: state_next7 <= 6'd36; 6'd36: state_next7 <= 6'd37; 6'd37: state_next7 <= 6'd38; 6'd38: state_next7 <= 6'd39; 6'd39: state_next7 <= 6'd40; 6'd40: state_next7 <= 6'd41; 6'd41: state_next7 <= 6'd42; 6'd42: state_next7 <= 6'd43; 6'd43: state_next7 <= 6'd44; 6'd44: state_next7 <= 6'd45; 6'd45: state_next7 <= 6'd00; endcase case(state_next7) 6'd0: begin light=a5; place=b0; end 6'd1: light=a6; 6'd2: light=a1; 6'd3: light=a2; 6'd4: light=a3; 6'd5: light=a8; 6'd6: begin light=a4; place=b1; end 6'd7: light=a8; 6'd8: begin light=a5; place=b2; end 6'd9: light=a6; 6'd10: light=a1; 6'd11: light=a2; 6'd12: light=a3; 6'd13: light=a8; 6'd14: begin light=a4; place=b3; end 6'd15: light=a8; 6'd16: begin light=a5; place=b4; end 6'd17: light=a6; 6'd18: light=a1; 6'd19: light=a2; 6'd20: light=a3; 6'd21: light=a8; 6'd22: begin light=a4; place=b5; end 6'd23: light=a3; 6'd24: light=a2; 6'd25: light=a1; 6'd26: light=a6; 6'd27: light=a5; 6'd28: begin light=a8; place=b4; end 6'd29: light=a4; 6'd30: begin light=a8; place=b3; end 6'd31: light=a3; 6'd32: light=a2; 6'd33: light=a1; 6'd34: light=a6; 6'd35: light=a5; 6'd36: begin light=a8; place=b2; end 6'd37: light=a4; 6'd38: begin light=a8; place=b1; end 6'd39: light=a3; 6'd40: light=a2; 6'd41: light=a1; 6'd42: light=a6; 6'd43: light=a5; 6'd44: begin light=a8; place=b0; end 6'd45: light=a4; endcase end endcase end endmodule 精简一下dispaly模块,不要改变原有的功能,直接给出优化后的代码
最新发布
05-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值