/*
blue 00_11_11
yellow 11_00_11
blue 11_11_00
0 bu liang
1 liang
*/
module traffic(led_l,led_r,clk,seg_reg1,seg_reg2);
input clk;
output [6:0] seg_reg1,seg_reg2;
output [5:0] led_l,led_r;
reg [6:0] dispdat1,dispdat2,seg_reg1,seg_reg2;
reg [25:0] count;
reg [1:0] led_yellow_l;
reg [1:0] led_blue_l;
reg [1:0] led_red_l;
reg [5:0] led_reg_l;
reg [1:0] led_yellow_r;
reg [1:0] led_blue_r;
reg [1:0] led_red_r;
reg [5:0] led_reg_r;
reg sec;
reg [1:0] rgy_status;
reg [7:0] rgy_time;
initial
begin
rgy_status=2'd0;
rgy_time=8'h30; //status 0 time
//led_reg=12'b000000001111;
led_reg_l=6'b000000;
led_reg_r=6'b000000;
end
////////////////////////fen ping chan sheng 2HZ shi zhong/////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
always @(posedge clk)
begin
count=count+1;
if(count==26'd1000_0000) //should be 2500_0000
begin
count=0;
sec=~sec; //2 HZ
end
end
///////////////////////////////status 0/////////////////////////////////////////////////
always @(posedge sec)
begin
if(rgy_status==2'd0)
begin
if(rgy_time==8'h0)
begin
rgy_status=2'd1;
rgy_time=8'h21; //status 1 time short time
//led_red=led_reg[3:0];
end
else
begin
led_reg_l=6'b110000; //blue
led_reg_r=6'b000011; //red
rgy_time=rgy_time-1'b1;
if(rgy_time[3:0]>9)
rgy_time[3:0]=9;
end
end
////////////////////////////////////status 1/////////////////////////////////////////////
if(rgy_status==2'd1)
begin
if(rgy_time==8'h0)
begin
rgy_status=2'd2;
rgy_time=8'h31; //status 2 time
end
else
begin
led_reg_l=6'b001100; //yellow
led_reg_r=6'b000011; //red
rgy_time=rgy_time-1;
if(rgy_time[3:0]>9)
rgy_time[3:0]=9;
end
end
////////////////////////////////////status 2//////////////////////////////////////
if(rgy_status==2'd2)
begin
if(rgy_time==8'h0)
begin
rgy_status=2'd3;
rgy_time=8'h21; // short time
end
else
begin
led_reg_l=6'b000011; //red
led_reg_r=6'b110000; //blue
rgy_time=rgy_time-1;
if(rgy_time[3:0]>9)
rgy_time[3:0]=9;
end
end
//////////////////////////////////zhuang tai 3///////////////////////////////////////////
if(rgy_status==2'd3)
begin
if(rgy_time==8'h0)
begin
rgy_status=2'd0; //return to status 0
rgy_time=8'h30;
end
else
begin
led_reg_l=6'b000011; //red
led_reg_r=6'b001100; //yellow
rgy_time=rgy_time-1;
if(rgy_time[3:0]>9)
rgy_time[3:0]=9;
end
end
end
////////////////////////////xian shi ji shi///////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
always
begin
dispdat1=rgy_time[3:0];
dispdat2=rgy_time[7:4];
end
always @(dispdat1)
begin
case(dispdat1)
4'h0:seg_reg1=7'b1000000;//0
4'h1:seg_reg1=7'b1111001;//1
4'h2:seg_reg1=7'b0100100;//2
4'h3:seg_reg1=7'b0110000;//3
4'h4:seg_reg1=7'b0011001;//4
4'h5:seg_reg1=7'b0010010;//5
4'h6:seg_reg1=7'b0000010;//6
4'h7:seg_reg1=7'b1111000;//7
4'h8:seg_reg1=7'b0000000;//8
4'h9:seg_reg1=7'b0010000;//9
endcase
end
//////////////////////////////////////////////////////////////////////////////////////////
always @(dispdat2)
begin
case(dispdat2)
4'h0:seg_reg2=7'b1000000;//0
4'h1:seg_reg2=7'b1111001;//1
4'h2:seg_reg2=7'b0100100;//2
4'h3:seg_reg2=7'b0110000;//3
4'h4:seg_reg2=7'b0011001;//4
4'h5:seg_reg2=7'b0010010;//5
4'h6:seg_reg2=7'b0000010;//6
4'h7:seg_reg2=7'b1111000;//7
4'h8:seg_reg2=7'b0000000;//8
4'h9:seg_reg2=7'b0010000;//9
endcase
end
assign led_l=led_reg_l;
assign led_r=led_reg_r;
endmodule
|
文件: |
学校试验_交通灯控制系统测试版(一)(未带按键).rar |
大小: |
526KB |
下载: |
下载 | |
阅读(698) | 评论(0) | 转发(0) |