本帖最后由 徐林如风 于 2015-10-21 00:39 编辑
- module key_led(key_add, key_sub, Rst_n, out_sel, out_bit);
- input key_add;
- input key_sub;
- input Rst_n;
- output [5:0]out_sel;
- output [7:0]out_bit;
-
- reg [5:0]out_sel; //数码管段控制
- reg [7:0]out_bit; //数码管位控制
- reg [3:0]counter;
-
- always@(negedge key_add or negedge key_sub or negedge Rst_n)
- begin
- if (Rst_n == 0)
- counter <= 4'd0;
- else if (key_add == 0)
- counter <= counter + 1'b1;
- else if (key_sub == 0)
- counter <= counter - 1'b1;
- else
- counter <= counter;
- end
-
- always
- begin
- out_sel = 6'b011111;
- end
-
- always@(counter)
- begin
- case (counter)
- 4'd0: out_bit = 8'b1100_0000;
- 4'd1: out_bit = 8'b1111_1001;
- 4'd2: out_bit = 8'b1010_0100;
- 4'd3: out_bit = 8'b1011_0000;
- 4'd4: out_bit = 8'b1001_1001;
- 4'd5: out_bit = 8'b1001_0010;
- 4'd6: out_bit = 8'b1000_0010;
- 4'd7: out_bit = 8'b1111_1000;
- 4'd8: out_bit = 8'b1000_0000;
- 4'd9: out_bit = 8'b1001_1111;
- default: out_bit = 8'b1111_1111;
- endcase
- end
-
- endmodule
-
复制代码
一个很简单的功能,就是设定counter为计数器,key_add电平变化时counter加一,key_sub电平变化时counter减一,然后把counter的数值送到数码管中显示出来。在运行的时候总是出现一些很诡异的问题,不知是何原因,还请各位大神帮忙看看,谢谢了!
一周热门 更多>