



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
程序很简单,毕竟我是初学嘛!
上了演示视频吧:
按顺序,循环作向左跑马灯,向右跑马灯,集体闪烁和流水灯演示
回复
打赏帖 | |
---|---|
VOFA+波形显示+JYD-31蓝牙发送和解析不定长数据被打赏10分 | |
宏定义和const关键字定义被打赏5分 | |
换取逻辑分析仪】STM32G4从入门到大师之五:ADC中断方式单路采集电压被打赏16分 | |
【换取逻辑分析仪】STM32G4从入门到大师之四:ADC查询方式单路采集电压被打赏14分 | |
【分享开发笔记,赚取电动螺丝刀】几个单片机I2S外设的BLCK时钟对比被打赏20分 | |
【功率监测与控制系统DIY活动成果贴】DIY功率计与LabVIEW数据采集被打赏100分 | |
【分享开发笔记,赚取电动螺丝刀】使用ESP32S3调试I2S音频模块MAX98357被打赏22分 | |
【Freertos】任务管理被打赏10分 | |
分享博世的两种不同的喷射系统模式被打赏5分 | |
汽车+开路实验与短路实验被打赏10分 |