



2、FPGA各种LED点亮法:
按照活动提供的教程,我将LED的点亮方法跑了一遍,并完成了作业!
程序:
module Led_sample(sys_clk,sys_rstn,Led);//输入输出信号定义
input sys_clk;//全局时钟,50HZ
input sys_rstn; //复位信号,低电平有效
output [7:0] Led;//输出信号
//寄存器定义
reg [7:0] Led; //Led寄存器
reg [24:0] delay_cnt; //延时计数器
reg [24:0] cnt; //秒数
//逻辑部分
always@(posedge sys_clk or negedge sys_rstn)
begin
if(!sys_rstn)
begin
delay_cnt<=25'd0;
cnt<=25'd1;
end
else
begin
if(delay_cnt==25'd24999999)
begin
delay_cnt<=25'd0;
cnt<=cnt+1'b1;
begin
if(cnt==25'd63)
cnt<=25'd0;
end
end
else
delay_cnt<=delay_cnt+1'b1;
end
end
always@(posedge sys_clk or negedge sys_rstn)
begin
if(!sys_rstn)
Led<=8'b11111110;//由左向右
else
begin
if(delay_cnt==25'd24999999)
begin
case(cnt/25'd16)
25'd0:
begin
Led<={Led[6:0],Led[7]};//由左向右
if(cnt==25'd15)
Led<=8'b01111111;//由左向右
end
25'd1:
begin
Led<={Led[0],Led[7:1]};//由右向左
if(cnt==25'd31)
Led<=8'b11111111;//由右向左
end
25'd2:
begin
Led<=~Led;
if(cnt==25'd47)
Led<=8'b11111111;
end
25'd3:
begin
Led<=Led<<1;
if(Led==8'b00000000)
Led<=8'b11111111;
if(cnt==25'd63)
Led<=8'b11111110;
end
endcase
end
else
Led<=Led;
end
end
endmodule
程序很简单,毕竟我是初学嘛!
上了演示视频吧:
按顺序,循环作向左跑马灯,向右跑马灯,集体闪烁和流水灯演示
回复
打赏帖 | |
---|---|
【我踩过的那些坑】DRC使用位置错误导致的问题被打赏100分 | |
我踩过的那些坑之混合OTL功放与落地音箱被打赏50分 | |
汽车电子中巡航控制系统的使用被打赏10分 | |
【我踩过的那些坑】工作那些年踩过的记忆深刻的坑被打赏100分 | |
分享汽车电子中巡航控制系统知识被打赏10分 | |
分享安全气囊系统的检修注意事项被打赏10分 | |
分享电子控制安全气囊计算机知识点被打赏10分 | |
【分享开发笔记,赚取电动螺丝刀】【OZONE】使用方法总结被打赏20分 | |
【分享开发笔记,赚取电动螺丝刀】【S32K314】芯片启动流程分析被打赏40分 | |
【分享开发笔记,赚取电动螺丝刀】【S32K146】S32DS RTD 驱动环境搭建被打赏12分 |