markcheng的个人空间 https://blog.eetop.cn/1482181 [收藏] [复制] [分享] [RSS]

空间首页 动态 记录 日志 相册 主题 分享 留言板 个人资料

日志

Verlig小程序-verilog呼吸灯代码

已有 1777 次阅读| 2017-10-26 13:48 |个人分类:基于FPGA开发板实验开发|系统分类:硬件设计

module breathing_lamp(
input wire sclk,
input wire rst_n,
output reg [7:0] dout
);
parameter CHEN=50000-1;
reg [15:0] cnt;
reg [15:0] on_temp;
reg temp_flag;
wire wire_temp_flag;
reg led_direction;
reg[11:0] temp;

//counter of the 1000divider cnt=0~49999
always @(posedge sclk or negedge rst_n)
if(rst_n==1'd0)
begin
cnt<=16'd0;
temp_flag<=1'd0;
end
else if (cnt==CHEN)
begin
cnt<=16'd0;
temp_flag<=1'b1;
end
else
begin
cnt<=cnt+16'd1;
temp_flag<=1'b0;
end
assign wire_temp_flag=temp_flag;
always @(posedge wire_temp_flag or negedge rst_n)
if(rst_n==1'd0)
begin
led_direction<=1'd0;
temp<=16'd0;
end
else if (led_direction==1'd0)
begin
temp<=temp+16'd1;
if (temp==12'd1000)
led_direction<=1'd1;
end
else if (led_direction==1'd1)
begin
temp<=temp-16'd1;
if (temp==12'd0)
led_direction<=1'd0;
end
always @(posedge wire_temp_flag or negedge rst_n)
if(rst_n==1'd0)
on_temp<=16'd0;
else if (led_direction==1'd0)
on_temp=on_temp+16'd50;
else if (led_direction==1'd1)
on_temp=on_temp-16'd50;
always @(posedge sclk or negedge rst_n)
    if(rst_n==1'd0)
dout<=8'd0;
else if (cnt<on_temp)
dout<=8'b1111_1111;
else dout<=8'd0;
endmodule




点赞

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 注册

  • 关注TA
  • 加好友
  • 联系TA
  • 0

    周排名
  • 0

    月排名
  • 0

    总排名
  • 0

    关注
  • 1

    粉丝
  • 0

    好友
  • 0

    获赞
  • 0

    评论
  • 355

    访问数
关闭

站长推荐 上一条 /1 下一条

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-4-27 15:39 , Processed in 0.012336 second(s), 8 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
返回顶部