



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
程序很简单,毕竟我是初学嘛!
上了演示视频吧:
按顺序,循环作向左跑马灯,向右跑马灯,集体闪烁和流水灯演示
回复
打赏帖 | |
---|---|
【STM32F769】AI之与本地deepseek对接被打赏50分 | |
Buck电路工作在CCM模式下电感电流的计算公式是什么?被打赏5分 | |
buck电路工作原理被打赏5分 | |
基于MSPM0L1306的MODBUS-RTU协议通讯实验被打赏100分 | |
我想要一部加热台+多合一调试工具被打赏18分 | |
每周了解几个硬件知识+485硬件知识分享被打赏10分 | |
【换取手持数字示波器】树莓派PICO调试器官方固件本地化部署实践被打赏24分 | |
【换取手持数字示波器】分享一个KEIL无法识别CMSIS-DAP调试器的解决办法被打赏20分 | |
【换取手持数字示波器】分享一个自制的ArduinoNano扩展板底板被打赏23分 | |
【换取手持示波器】树莓派PICOW网页烟花被打赏18分 |