//===================================================================
// project name: strive_answer
// author: heal119
// date: 24.07.2006
// code description: host control the state .Initial ,the host give an
// order then three persons start to strive answer,
// after the first man successfully have this done,
// the host give the second order ,then the man start
// answer the question demanded while a counter start
// to work, which count from 60s down to 0s,
// when counter =0; the process is over .
// note: I just write it for practice.I will be glad if it can give
// you some help.
//===================================================================
module strive_answer (clk,
rst,
man_a,
man_b,
man_c,
host,
led1,
led2,
led3);
input rst;
input clk;
input man_a;
input man_b;
input man_c;
input host;
outputreg [3:0] led1;
outputreg [3:0] led2;
outputreg [3:0] led3;
reg [1:0] state;
reg [5:0] cnt;
reg en_cnt;
reg en_ans;
reg en_man_a;
reg en_man_b;
reg en_man_c;
parameter prepare=0;
parameter strive=1;
parameter answer=3;
always @(posedge clk or posedge rst)
begin
if (rst)
begin
en_ans<=0;
state<=prepare;
end
else
begin
case(state)
prepare:
begin
en_ans<=0;
en_man_a<=0;
en_man_b<=0;
en_man_c<=0;
if(host)
begin
en_cnt<=0;
state<=strive;
end
else
en_cnt<=0;
end
strive:
begin
en_ans<=1;
en_man_a<=1;
en_man_b<=1;
en_man_c<=1;
if(host)
begin
en_cnt<=1;
state<=answer;
end
else
en_cnt<=0;
end
answer:
begin
en_ans<=0;
en_man_a<=0;
en_man_b<=0;
en_man_c<=0;
en_cnt<=0;
if (cnt==0)
state<=prepare;
end
endcase
end
end
always@(posedge clk or posedge rst)
if(rst)
cnt<=0;
else if (en_cnt)
cnt<=60;
else
cnt<=cnt-1;
always @(posedge clk or posedge rst)
if (rst)
begin
led1<=0;
en_man_a<=0;
en_man_b<=0;
en_man_c<=0;
end
else if (en_ans)
begin
if (man_a&&en_man_a)
begin
led1<=1;
en_man_b<=0;
en_man_c<=0;
end
else if (man_b&&en_man_b)
begin
led1<=2;
en_man_a<=0;
en_man_c<=0;
end
else if (man_c&&en_man_c)
begin
led1<=3;
en_man_a<=0;
en_man_b<=0;
end
end
endmodule |