|
我们老板要我烧个程序,我左烧右烧就是烧不出。题目要求为道路较窄而车辆通行较多,支线、干线的车辆通行时间不等,并设有左右弯道通行时间,允许人工监控或修改各线通行时间,同时设有道路应急控制。具体的情况是:在正常的情况下,干道通行时间为40秒,其中左右弯道占时5秒,直道通行时间为25秒,其中左右弯道占时5秒,直道占时20秒。并且能够在人工监控状态下,干道、支道通行时间通过键盘修改或通过开关人为控制。
最后一个要求“并且能够在人工监控状态下,干道、支道通行时间通过键盘修改或通过开关人为控制。”这个我用那个状态机,不懂做,希望老鸟帮我改一下程序。我把已经能实现功能的基础部分拷贝如下:
注:A方向即为主干道方向 B方向为支干道方向
/*信号定义与说明:
CLK :同步时钟;
EN:使能信号,为1的话,则控制器工作;
LAMPA:控制A方向四盏灯的亮灭;其中LAMPA0~LAMPA3,分别控制A方向的左拐灯、绿灯、黄灯和红灯。
LAMPB:控制B方向四盏灯的亮灭;其中LAMPB0~LAMPB3,分别控制B方向的左拐灯、绿灯、黄灯和红灯。
acount:用于A方向灯的时间显示,8位,可驱动两个数码管;
bcount:用于B方向灯的时间显示,8位,可驱动两个数码管。*/
module traffic(CLK,EN,LAMPA,LAMPB,acount,bcount);
input CLK,EN;
output[3:0] LAMPA,LAMPB;
output[7:0] acount,bcount;
reg tempa,tempb;
reg[2:0] counta,countb;
reg[3:0] LAMPA,LAMPB;
reg[7:0] ared,ayellow,agreen,aleft,bred,byellow,bgreen,bleft;
reg[7:0] numa,numb;
always @(EN)
if(!EN)
begin
ared <=8'd35;
ayellow<=8'd5;
agreen <=8'd35;
aleft <=8'd5;
bred <=8'd50;
byellow <=8'd5;
bgreen <=8'd20;
bleft <=8'd5;
end
assign acount=numa;
assign bcount=numb;
always @(posedge CLK)
begin
if(EN)
begin
if(!tempa)
begin
tempa<=1;
case(counta)
0:begin numa<=agreen;LAMPA<=2;counta<=1;end
1:begin numa<=ayellow;LAMPA<=4;counta<=2;end
2:begin numa<=aleft;LAMPA<=1;counta<=3;end
3:begin numa<=ayellow;LAMPA<=4;counta<=4;end
4:begin numa<=ared;LAMPA<=8;counta<=0;end
default: LAMPA<=8;
endcase
end
else begin
if(numa>1)
if(numa[3:0]==0)
begin numa[3:0]<=4'b1001;numa[7:4]<=numa[7:4]-1;end
else numa[3:0]<=numa[3:0]-1;
if(numa==2) tempa<=0;
end
end
else begin LAMPA<=4'b1000;counta<=0;tempa<=0;end
end
always @(posedge CLK)
begin
if(EN)
begin
if(!tempb)
begin
tempb<=1;
case(countb)
0:begin numb<=bred;LAMPB<=8;countb<=1;end
1:begin numb<=bgreen;LAMPB<=2;countb<=2;end
2:begin numb<=byellow;LAMPB<=4;countb<=3;end
3:begin numb<=bleft;LAMPB<=1;countb<=4;end
4:begin numb<=byellow;LAMPB<=4;countb<=0;end
default: LAMPB<=8;
endcase
end
else begin
if(numb>1)
if(numb[3:0]==0)
begin numb[3:0]<=9;numb[7:4]<=numb[7:4]-1;end
else numb[3:0]<=numb[3:0]-1;
if(numb==2) tempb<=0;
end
end
else begin LAMPB<=4'b1000;countb<=0;tempb<=0;end
end
endmodule |
阿莫论坛20周年了!感谢大家的支持与爱护!!
知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)
|