begin
count<=count+1'b1;
end
else
begin
count<=1'b0;
clk_odd<=~clk_odd;
end
endmodule
控制及计时模块:
module
control(led,car,rst,clk,count_H_1,count_L_1,count_H_2,count_L_2);
output[3:
0]count_H_1,count_L_1,count_H_2,count_L_2;
output[5:
0]led;
inputclk,rst,car;
reg[5:
0]led;
reg[3:
0]count_H_1,count_L_1,count_H_2,count_L_2;
reg[1:
0]state;
parameterS0=2'b00,
S1=2'b01,
S2=2'b10,
S3=2'b11;
always@(posedgeclkornegedgerst)
if(!
rst)
begin
led=6'b010100;
state=S0;
count_H_1=4'b0000;count_L_1=4'b0000;
count_H_2=4'b0000;count_L_2=4'b0000;
end
else
begin
case(state)
S0:
begin
Begin
if(!
car)
begin
led=6'b010100;//count_H_1=4'b0100;count_L_1=4'b0101;//?
?
?
count_H_1=4'b0111;count_L_1=4'b0111;
end
else
begin
if(count_H_1==4'b0111)
begin
count_H_1=4'b0100;count_L_1=4'b0101;count_H_2=4'b0101;count_L_2=4'b0000;
end
else
if(count_L_1=0)
if(count_H_1==0)
begin
led=6'b001100;count_H_1=4'b0000;count_L_1=4'b0100;state<=S1;
if(count_L_2==0)
begin
count_H_2<=count_H_2-1'b1;count_L_2<=4'b1001;
end
elsebegincount_L_2<=count_L_2-1'b1;
end
endelse
begin
count_H_1<=count_H_1-1'b1;count_L_1<=4'b1001;
if(count_L_2==0)
begin
count_H_2<=count_H_2-1'b1;count_L_2<=4'b1001;
end
elsebegin
count_L_2<=count_L_2-1'b1;
end
end
else
begin
count_L_1<=count_L_1-1'b1;
if(count_L_2==0)
begin
count_H_2<=count_H_2-1'b1;count_L_2<=4'b1001;
end
elsebegin
count_L_2<=count_L_2-1'b1;
end
end
end
end
/*begin
if(!
car)
begin
count_H_2=4'b0101;count_L_2=4'b0000;end
else
if(count_L_2==0)
begin
count_H_2<=count_H_2-1'b1;
count_L_2<=4'b1001;
end
elsebegin
count_L_2<=count_L_2-1'b1;
end
end*/
end
/*if(count_L_1==0)
begin
if(count_H_1==0)
begin
led=6'b001100;count_H_1=4'b0000;count_L_1=4'b0100;state<=S1;
end
else
begin
count_H_1<=count_H_1-1'b1;
count_L_1<=4'b1001;
end
end
elsebegin
count_L_1<=count_L_1-1'b1;
end
if(!
car)
begincount_H_2=4'b0101;
count_L_2=4'b0000;
end
elseif(count_L_2==0)
begin
count_H_2<=count_H_2-1'b1;
count_L_2<=4'b1001;
end
else
begin
count_L_2<=count_L_2-1'b1;
end
S1:
begin
if(count_L_1==0)
begin
if(count_H_1==0)
begin
led=6'b100010;
count_H_1=4'b0010;count_L_1=4'b1001;count_H_2=4'b0010;count_L_2=4'b0100;
state<=S2;
end
else
begin
count_H_1<=count_H_1-1'b1;
count_H_2<=count_H_2-1'b1;
end
end
elsebegin
count_L_1<=count_L_1-1'b1;
count_L_2<=count_L_2-1'b1;
end
end
S2:
begin
if(count_L_2==0)
begin
if(count_H_2==0)
begin
led=6'b100001;count_H_2=4'b0000;count_L_2=4'b0100;
state<=S3;
else
begin
count_H_2<=count_H_2-1'b1;count_L_2=4'b1001;
end
end
elsebegin
count_L_2<=count_L_2-1'b1;
end
if(count_L_1==0)
begin
begin
count_H_1<=count_H_1-1'b1;
count_L_1=4'b1001;
end
end
else
begin
count_L_1<=count_L_1-1'b1;
end
end
S3:
begin
if(count_L_2==0)
begin
if(count_H_2==0)
begin
led=6'b010100;
count_H_1=4'b0100;count_L_1=4'b1001;count_H_2=4'b0100;count_L_2=4'b0100;state<=S0;
end
elsebegin
count_H_1<=count_H_1-1'b1;
count_H_2<=count_H_2-1'b1;
end
end
else
begin
count_L_1<=count_L_1-1'b1;
count_L_2<=count_L_2-1'b1;
end
endcase
end
endmodule
扫描译码显示模块:
module
saomiao(rst,clk,count_H_1,count_L_1,count_H_2,count_L_2,sel,seg);
inputrst,clk;
input[3:
0]count_H_1,count_L_1,count_H_2,count_L_2;
output[6:
0]sel;
output[3:
0]seg;
reg[6:
0]sel;
reg[3:
0]seg;
reg[15:
0]count;
reg[1:
0]cnt;
reg[3:
0]data;
regclk_odd;
always@(posedgeclkornegedgerst)
begin
if(!
rst)
begin
count<=0;
clk_odd<=0;
end
elseif(count==16'd2)
begin
clk_odd<=~clk_odd;
count<=0;
end
else
count<=count+1'b1;
end
always@(negedgerstorposedgeclk_odd)//?
?
?
?
1ms
if(!
rst)begin
cnt<=2'b00;
end
elsecnt<=cnt+1'b1;
always@(negedgerstorposedgeclk)
if(!
rst)begin
//sel=7'b0000000;
seg=4'b1111;
end
elsebegin
case(cnt)
2'b00:
begin
seg=4'b1110;
data=count_H_1;
end
2'b01:
begi
seg=4'b1101;//?
?
?
?
?
data=count_L_1;
end
2'b10:
begin//?
?
?
?
?
seg=4'b1011;
data=count_H_2;
end
2'b11:
begin//?
?
?
?
?
seg=4'b0111;
data=count_L_2;
end
default:
begin
//sel=8'b0000000;
seg=4'b0000;
end
endcase
end
always@(dataorseg)begin
case(data)
4'b0000:
sel=7'b1111110;
4'b0001:
sel=7'b0110000;
4'b0010:
sel=7'b1101101;
4'b0011:
sel=7'b1111001;
4'b0100:
sel=7'b0110011;
4'b0101:
sel=7'b1011011;
4'b0110:
sel=7'b1011111;
4'b0111:
sel=7'b1110000;
4'b1000:
sel=7'b1111111;
4'b1001:
sel=7'b1111011;
default:
sel=7'b1111110;
endcase
end
endmodule
顶层模块:
modulejiaotongdeng(clk,rst,car,led,sel,seg,count_H_1,count_L_1,count_H_2,count_L_2,clk_odd);
inputclk,rst,car;
output[3:
0]seg;
output[6:
0]sel;
output[5:
0]led;
output[3:
0]count_H_1,count_L_1,count_H_2,count_L_2;
outputclk_odd;
wire[3:
0]count_H_1,count_L_1,count_H_2,count_L_2;
wireclk_odd;
saomiaoee(rst,clk_odd,count_H_1,count_L_1,count_H_2,count_L_2,sel,seg);
controlrr(led,car,rst,clk_odd,count_H_1,count_L_1,count_H_2,count_L_2);
fenpinqitt(clk,rst,clk_odd);
endmodule
激励模块:
`defineTRUE1'b1
`defineFALSE1'b0
modulestimulus;
wire[3:
0]SEG;
wire[6:
0]SEL;
wire[5:
0]LED;
wire[3:
0]count_H_1,count_L_1,count_H_2,count_L_2;
wireclk_odd;
regCAR_ON_CNTRY_RD;
regCLOCK,RST;
jiaotongdengjiaotongdeng1(CLOCK,RST,CAR_ON_CNTRY_RD,LED,SEL,SEG,count_H_1,count_L_1,count_H_2,count_L_2,clk_odd);
initial
$monitor($time,"led=%b,sel=%b,seg=%b",LED,SEL,SEG);
initial
begin
CLOCK=`FALSE;
forever#5CLOCK=~CLOCK;
end
initial
begin
RST=`FALSE;
repeat
(2)@(negedgeCLOCK);
RST=`TRUE;
end
initial
begin
CAR_ON_CNTRY_RD=1'b0;
repeat(20)@(negedgeCLOCK);CAR_ON_CNTRY_RD=1'b1;
repeat(500)@(negedgeCLOCK);CAR_ON_CNTRY_RD=1'b0;
repeat(500)@(negedgeCLOCK);CAR_ON_CNTRY_RD=1'b1;
repeat(2400)@(negedgeCLOCK);$stop;
end
endmodule