本帖最后由 springvirus 于 2019-7-2 11:30 编辑
因为偶的板子是Cyclone系列的片子,实在太老,所以用的quartus II 9.1
先感受下verilog结构和仿真操作,改天烧到俺的板子试试
仿真要修改下程序里计数器的最大值,实际在板子上跑时,再改回实际所需的值,比如这里流水灯的200ms间隔
module FPGA_EP1C6Q240_led (
input sys_clk,
input sys_rst_n,
output reg [3:0] led,
//7 seg shumaguan segment select
output reg [7:0] seg_sel,
//7 seg shumaguan bit select
output reg [1:0] bit_sel
);
reg [23:0] counter;
reg [7:0] magic_liushui_counter;
always @(posedge sys_clk or negedge sys_rst_n)
begin
if(!sys_rst_n)
begin
counter <= 24'd0;
magic_liushui_counter <= 8'd0;
end
//else if(counter < 24'd1000_0000)
else if(counter < 24'd4)
counter <= counter + 24'd1;
//else if(counter == 24'd1000_0000)
else if(counter == 24'd4)
begin
counter <= 24'd0;
if(magic_liushui_counter < 8'd7)
magic_liushui_counter <= magic_liushui_counter + 8'd1;
else if(magic_liushui_counter == 8'd7)
magic_liushui_counter <= 8'd0;
end
end
//high level turn on the led, low level turn off the led
//when counter == 24'd1000_0000, level 1 left shift,
//[3:0] = 0001 -> [3:0] = 0010 -> [3:0] = 0100 -> [3:0] = 1000
always @(posedge sys_clk or negedge sys_rst_n)
begin
if(!sys_rst_n)
begin
led <= 4'b0001;
//when power on, sgsel0 and sgsel1 are valid both.
bit_sel <= 2'b11;
end
//else if(counter == 24'd1000_0000)
else if(counter == 24'd4)
begin
led[3:0] <= {led[2:0], led[3]};
if(magic_liushui_counter == 8'd0)
//seg a is on
seg_sel <= 8'b0000_0001;
else if(magic_liushui_counter == 8'd1)
//seg b is on
seg_sel <= 8'b0000_0010;
else if(magic_liushui_counter == 8'd2)
//seg g is on
seg_sel <= 8'b0100_0000;
else if(magic_liushui_counter == 8'd3)
//seg e is on
seg_sel <= 8'b0001_0000;
else if(magic_liushui_counter == 8'd4)
//seg d is on
seg_sel <= 8'b0000_1000;
else if(magic_liushui_counter == 8'd5)
//seg c is on
seg_sel <= 8'b0000_0100;
else if(magic_liushui_counter == 8'd6)
//seg g is on
seg_sel <= 8'b0100_0000;
else if(magic_liushui_counter == 8'd7)
//seg f is on
seg_sel <= 8'b0010_0000;
end
else
led <= led;
end
endmodule
|
@21ic小喇叭 :哈哈,感觉FPGA有些难
恭喜