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
程序很简单,毕竟我是初学嘛!
上了演示视频吧:
按顺序,循环作向左跑马灯,向右跑马灯,集体闪烁和流水灯演示
回复
有奖活动 | |
---|---|
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
【有奖活动】智能可穿戴设备AR/VR如何引领科技新潮流! | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
【有奖活动】震撼来袭!这场直播将直击工程师的心灵! |
打赏帖 | |
---|---|
【换取手持数字示波器】滞回比较电路分析被打赏30分 | |
【换取手持数字示波器】电流镜电路分析被打赏20分 | |
【换取手持数字示波器】基于状态变量推导实现有源滤波器被打赏20分 | |
玩转“DFRobot盖革计数器模块”准备工作认识模块知识分享被打赏30分 | |
【换取手持数字示波器】AHT10温度检测分享被打赏40分 | |
【换取手持数字示波器】ACM32F070开发板点亮LCD屏和触控按键,串口,ADC被打赏40分 | |
【换取手持数字示波器】ACM32F070LCD屏和触控按键功驱动蜂鸣器分享被打赏40分 | |
【换取手持数字示波器】国民技术PWM功能知识分享被打赏40分 | |
【换取手持数字示波器】放大器运放知识分享被打赏40分 | |
【分享评测,赢取加热台】+开关电源AC输入知识分享被打赏30分 |