高分求一用Verilog HDL语言编写的简单交通灯程序
有数码管显示的倒计时,交通灯只需要一组即可,要求交通灯循环亮,没有其他要求了…谁能帮着做一个呀,谢谢了~很急,所以给高分!...
有数码管显示的倒计时,交通灯只需要一组即可,要求交通灯循环亮, 没有其他要求了…谁能帮着做一个呀,谢谢了~很急,所以给高分!
展开
1个回答
展开全部
//绿灯亮40秒,转黄灯;
//黄灯亮5秒,转左转灯;
//左转灯亮15秒,转黄灯;
//黄灯亮5秒,转红灯;
//红灯亮55秒,转绿灯;
//lamp从高到低 分别接红灯 黄灯 绿灯 左转灯
//account接2个数码管
module traffic(clk,en,lamp,acount);
output[7:0] acount;
output[3:0] lamp;
input clk,en;
reg[7:0] num;
reg temp;
reg[2:0] count;
reg[7:0] red,yellow,green,left;
reg[3:0] lamp;
always @(en)
if(!en)
begin
red<=8'd55; //55 second
yellow<=8'd5;
green<=8'd40;
left<=8'd15;
end
assign acount=num;
always @(posedge clk)
begin
if(en)
begin
if(!temp)
begin
temp<=1;
case(count)
0:begin num<=green;lamp<=2;count<=1; end //green
1:begin num<=yellow;lamp<=4;count<=2;end //yellow
2:begin num<=left;lamp<=1;count<=3;end //left
3:begin num<=yellow;lamp<=4;count<=4;end //yellow
4:begin num<=red; lamp<=8;count<=0;end //red
default:lamp<=8;
endcase
end
else
begin
if(num>1)
if(num[3:0]==0)
begin
num[3:0]<=4'b1001;
num[7:4]<=num[7:4]-1;
end
else
num[3:0]<=num[3:0]-1;
if(num==2) temp<=0;
end
end
else
begin
lamp<=4'b1000;
count<=0;
temp<=0;
end
end
endmodule
//黄灯亮5秒,转左转灯;
//左转灯亮15秒,转黄灯;
//黄灯亮5秒,转红灯;
//红灯亮55秒,转绿灯;
//lamp从高到低 分别接红灯 黄灯 绿灯 左转灯
//account接2个数码管
module traffic(clk,en,lamp,acount);
output[7:0] acount;
output[3:0] lamp;
input clk,en;
reg[7:0] num;
reg temp;
reg[2:0] count;
reg[7:0] red,yellow,green,left;
reg[3:0] lamp;
always @(en)
if(!en)
begin
red<=8'd55; //55 second
yellow<=8'd5;
green<=8'd40;
left<=8'd15;
end
assign acount=num;
always @(posedge clk)
begin
if(en)
begin
if(!temp)
begin
temp<=1;
case(count)
0:begin num<=green;lamp<=2;count<=1; end //green
1:begin num<=yellow;lamp<=4;count<=2;end //yellow
2:begin num<=left;lamp<=1;count<=3;end //left
3:begin num<=yellow;lamp<=4;count<=4;end //yellow
4:begin num<=red; lamp<=8;count<=0;end //red
default:lamp<=8;
endcase
end
else
begin
if(num>1)
if(num[3:0]==0)
begin
num[3:0]<=4'b1001;
num[7:4]<=num[7:4]-1;
end
else
num[3:0]<=num[3:0]-1;
if(num==2) temp<=0;
end
end
else
begin
lamp<=4'b1000;
count<=0;
temp<=0;
end
end
endmodule
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询