llliiivvveee进程贴
代码:
#####################################################
module s_led(clk,rest,led);
input clk;
input rest;
output [7:0] led;
reg [7:0] led;
reg [25:0] cnt;
always@(posedge clk or negedge rest)
begin
if(!rest)
cnt<=26'd0;
else
begin
if(cnt==26'd49999999)//产生1Hz的信号
cnt<=26'd0;
else
cnt<=cnt+26'd1;
end
end
always@(posedge clk or negedge rest)
begin
if(!rest)
led<=8'b11111111;
else
begin
if(cnt==26'd49999999)
led<=~led;
else
led<=led;
end
end
endmodule
#######################################
led流水灯
代码:
#####################################################
module led2(clk,rest,led);
input clk;
input rest;
output[7:0] led;
reg [7:0] led;
reg [24:0] cnt;
always@(posedge clk or negedge rest)/*2Hz时钟*/
begin
if(!rest)
cnt<=25'd0;
else
begin
if(cnt==25'd24999999)
cnt<=25'd0;
else
cnt<=cnt+25'd1;
end
end
always@(posedge clk or negedge rest)
begin
if(!rest)
led<=8'b11111111;
else
begin
if(cnt==24'd24999999)
if(led==8'b00000000)
led<=8'b11111111;
else
led<=led>>1;
else
led<=led;
end
end
endmodule
##########################################
led跑马灯
代码:
###################################################
module led_run(clk,rest,led);
input clk;
input rest;
output[7:0] led;
reg [7:0] led;
reg [24:0] cnt;
initial
begin
led<=8'b11111100;
end
always@(posedge clk or negedge rest)/*产生2Hz时钟*/
begin
if(!rest)
cnt<=25'd0;
else
begin
if(cnt==25'd24999999)
cnt<=25'd0;
else
cnt<=cnt+1'b1;
end
end
always@(posedge clk or negedge rest)
begin
if(!rest)
led<=8'b11111100;
else
begin
if(cnt==24'd24999999)
led<={led[6:0],led[7]};
else
led<=led;
end
end
endmodule
#########################################
led花样灯
代码
#############################################
module led_fler(clk,rest,led);
input clk;
input rest;
output[7:0] led;
reg [7:0] led;
reg [24:0] cnt;
reg [7:0] num;
reg [3:0] type;//花样灯款式
initial
begin
led<=8'b00000000;
num<=8'd0;
end
always@(posedge clk or negedge rest)
begin
if(!rest)
begin
cnt<=25'd0;
num<=8'd0;
end
else
begin
if(num==8'd29)
num<=8'd0;
else
begin
if(cnt==25'd24999999)
begin
cnt<=25'd0;
num<=num+8'd1;
end
else
cnt<=cnt+25'd1;
end
end
end
always@(posedge num or negedge rest)
begin
if(!rest)
type<=4'd0;
else if(num<8'd8)
type<=4'd0;
else if(num<8'd18)
type<=4'd1;
else if(num<8'd20)
type<=4'd2;
else if(num<8'd29)
type<=4'd3;
else
type<=4'd4;
end
always@(posedge clk or negedge rest)
begin
if(!rest)
led<=8'b00000000;
else
begin
case(type)
4'd0://闪烁
begin
if(cnt==25'd24999999)
led<=~led;
else
led<=led;
end
4'd1://流水灯
begin
if(cnt==25'd24999999)
led<=led<<1;
else
led<=led;
end
4'd2: led<=8'b11111110;//跑马灯设定
4'd3://跑马灯
begin
if(cnt==25'd24999999)
led<={led[6:0],led[7]};
else
led<=led;
end
4'd4:led<=8'b11111111;//清除等待重来
endcase
end
end
endmodule
#########################################
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |