题目:让led等按照指定的亮灭模式亮灭,亮灭模式位置,由用户随机指定。以0.25秒为一个变化周期,八个变化状态为一个循环
代码:
`timescale 1ns / 1ps
module cnt_led_3(
clk ,
rst_n,
ctrl,
led
);
input clk;
input rst_n;
input [7:0] ctrl;
output reg led;
parameter MCNT=100_000_000;
reg [26:0] cnt0;
always @(posedge clk or negedge rst_n)begin
if(!rst_n)
cnt0<=0;
else if(cnt0==MCNT-1)
cnt0<=0;
else
cnt0 <= cnt0 +1;
end
always @(posedge clk or negedge rst_n) begin
if(!rst_n)
led<=0;
else case(cnt0)
MCNT*1/8-1:led <=ctrl[0];
MCNT*2/8-1:led <=ctrl[1];
MCNT*3/8-1:led <=ctrl[2];
MCNT*4/8-1:led <=ctrl[3];
MCNT*5/8-1:led <=ctrl[4];
M