名称:可调定时器设计Verilog代码Quartus仿真(文末获取)
软件:Quartus
语言:Verilog
代码功能:
EDA技术
设计一个可调的定时器,定时时间默认为x秒(x=个人学号%10+5),定时器具
有启动,复位,到时警告功能(比如点亮一个LED灯)。(100分)。
要求
1.写出设计文件xx(xx命名规则为tmer姓名首字母2位学号,如 timer jl12)(40分)
2会用 Quartus软件建工程并进行编译(20分)(编译完成截图保存,图片命名为编译结果)
4仿真结果截图(20分)(仿真完成截图保存,图片命名为仿真结果)5工程文件的提交(20分)
1. 工程文件
2. 程序文件
3. 程序编译
4. Testbench
5. 仿真图
部分代码展示:
//默认7秒 module timer_fjd_42( input clk,//1KHz时钟 input rst_p,//复位 input set_key,//按键调时间1~60秒 input start_key,//启动 output reg led,//led到时警告 output reg [1:0] SEL,//数码管位选 output [7:0] SEG//数码管段选,低电平亮 ); reg [2:0] state=3'd0; parameter s_idle=3'd0; parameter s_start=3'd1; parameter s_end=3'd2; wire [7:0] second; reg [7:0] second_set=8'd7; //按键设计定时时间 always@(posedge clk or posedge rst_p) if(rst_p==1) second_set<=8'd7;//默认7秒 else if(set_key==1)//按键调时间1~60秒 if(second_set==8'd60) second_set<=8'd1; else second_set<=second_set+8'd1;//累计数 reg [7:0] second_cnt=8'd0; always@(posedge clk or posedge rst_p) if(rst_p==1) state<=s_idle;//复位 else case(state) s_idle://空闲状态 if(start_key==1)//启动按键 state<=s_start;//计时 else state<=s_idle; s_start://计时状态 if(second_cnt==second_set) state<=s_end;//结束 else state<=s_start;//倒计时 s_end://结束状态 state<=s_end;//结束 default:; endcase always@(posedge clk or posedge rst_p) if(rst_p==1) led<=0; else if(state==s_end)//结束状态 led<=1;//led到时警告 else led<=0; //分频到1Hz reg [31:0] count=32'd0; always@(posedge clk or posedge rst_p) if(rst_p==1) count<=32'd0; else if(state==s_start)//计时状态 if(count==32'd1000)//1KHz计数1000就是1秒 count<=32'd0; else count<=count+32'd1;//计数 else count<=count;//不计数 always@(posedge clk or posedge rst_p) if(rst_p==1) second_cnt<=8'd0;//复位,计数值回到0 else if(state==s_start)//计时状态 if(count==32'd1000)//1秒计时1次 second_cnt<=second_cnt+8'd1; else second_cnt<=second_cnt; else second_cnt<=second_cnt; assign second=second_cnt;//秒计时
源代码
扫描文章末尾的公众号二维码