这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » DIY与开源设计 » 电子DIY » llliiivvveee进程贴

共5条 1/1 1 跳转至

llliiivvveee进程贴

菜鸟
2012-11-08 19:34:09     打赏
led 闪烁灯 2012.11.8
led流水灯 2012.11.8
led跑马灯 2012.11.8
led花样灯 2012.11.13



关键词: llliiivvveee     进程    

菜鸟
2012-11-08 19:48:09     打赏
2楼
led 闪烁灯


代码:
#####################################################
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
#######################################

菜鸟
2012-11-08 20:21:04     打赏
3楼

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
##########################################


菜鸟
2012-11-08 20:46:54     打赏
4楼

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

#########################################


菜鸟
2012-11-13 23:37:31     打赏
5楼

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

#########################################


共5条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]