verilog4路抢答器设计带30s倒计时_4路抢答器设计作业
verilog4路抢答器设计带30s倒计时由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“4路抢答器设计作业”。
四路抢答器
一、程序
module qiangda4(clr,clk,input1,input2,input3,input4,seg,clockin,scan,LED);
input clr,clk,input1,input2,input3,input4;output [7:0] seg;
//7段数码管数据
output [7:0] scan;
//数码管位选
output [3:0] LED;
//输出LED灯指示
output clockin;
//蜂鸣器
reg [7:0] seg;reg [7:0] scan;reg [3:0] LED;reg clockin;
reg [3:0] data;reg input_flag,count_flag;reg [14:0] count1;reg [8:0] count2;reg [3:0] LED_N;//reg clock_flag;reg div1khz,div1hz;reg [2:0] cnt;reg [3:0] dat;//reg [7:0] data_count;reg [3:0] count_one,count_ten;
initial count_one='d0;
//初始化
initial count_ten='d3;initial data=4'b0000;initial LED_N=4'b1111;
//-------------fenping分频1khz----always @(posedge clk)begin
if(count1=='d25000)
begin div1khz
begin count1
end //-------------fenping--1hz always @(posedge div1khz)begin if(count2=='d500)
begin div1hz
begin count2
begin
count_one
end else if((!input_flag)&(!count_flag))
begin if(count_one=='d0&&count_ten=='d0)
begin count_flag
end
else if(count_one=='d0)
begin count_one
count_ten
end
else
begin count_one
end
end
else
begin count_one
count_ten
end
end
//----------------------------always @(posedge clk)
//or input1 or input2 or input3 or input4 begin if(!clr)begin
LED_N
//clock_flag
input_flag
data
else if((!input_flag)&(!count_flag))
begin
if(input1==0)
begin
data
LED_N
input_flag
end
else if(input2==0)
begin
data
LED_N
input_flag
end
else if(input3==0)
begin
data
LED_N
input_flag
end
else if(input4==0)
begin
data
LED_N
input_flag
end
else
begin
data
LED_N
input_flag
end
end
end //-------------led灯及蜂鸣器--------------------always @(posedge clk)begin LED
//--------------shu ma guan sao miao数码管扫描--always @(posedge div1khz)begin if(cnt=='d3)
begin cnt
begin cnt
//----------------------always @(cnt,data,count_one,count_ten)begin
case(cnt)//3'b000 : begin scan
3'b010 : begin scan
//倒计时
3'b011 : begin scan
//-------------------------always @(dat)begin case(dat)4'b0000 : seg[7:0]
endmodule
二、框图
三、设计思路
四路抢答,有30s倒计时,当有人抢答时,数码管显示对应选手编号,同时对应LED灯亮,蜂鸣器响起,此时其他选手抢答无效。当倒计时到达0时,蜂鸣器响,此时不能够抢答,清零后重新计时。
程序有个小问题,数码管显示选手编号时,存在干扰,能够勉强辨认出选手编号,但不够清晰,找了好久都没查出。