实例的内容及目标
1.实例的主要训练内容
本实例通过Verilog HDL语言设计一个简易的交通等控制器,实现一个具有两个方向、共8个灯并具有时间***功同步时钟。
下面是交通灯的Verilog HDL
end
default: //默认状态
LAMPA<=8; //红灯亮,输出1000
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; //返回方向A的状态0(绿灯状态)
tempa<=0; //进入状态变化判断
end
end
//控制B方向4种灯的模块,模块的语言描述与方向A的描述基本一致,这里不再重复注释
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]) 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;
tempb<=0;
countb<=0;
end
end
endmodule
通过上面这个Verilog HDL模块,基本实现了交通灯控制器的基本功能。读者可将此设计应用于实际的硬件系统中,通过晶振、FPGA、开关、LED灯及数码管等资源即可完成硬件实现。