📄 cu_two.v
字号:
`timescale 1ns / 1ps
////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer: Angela
//
// Create Date: 12:57:17 01/11/07
// Design Name:
// Module Name: cu_two
// Project Name:
// Target Device:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
////////////////////////////////////////////////////////////////////////////////
module cu_two(stat_1, stat_2, mov_1, mov_2, ch_stat_1, ch_stat_2, req_clr_1,req_clr_2,des_1,des_2,
req_1, req_2, up_1, up_2,down_1, down_2,now_1, now_2,stop_1,stop_2,sel_1, sel_2,floor_1, floor_2);//,pv_in, pv_out);
input [1:0] stat_1;
input [1:0] stat_2;
input [1:0] req_1;//本层外部请求
input [1:0] req_2;
input up_1; //本层之上有请求或目的
input up_2;
input down_1; //本层之下有请求或目的
input down_2;
input now_1; //本层是目的
input now_2;
input [2:0] floor_1;
input [2:0] floor_2;
input sel_1; /////////////////////////// 请求调度信号
input sel_2; //////////////////////////////////////
// input pv_in;
output des_1; reg des_1; // des_ clear...
output des_2; reg des_2;
output [1:0]req_clr_1;
reg [1:0] req_clr_1;
output [1:0]req_clr_2;
reg [1:0] req_clr_2;
output [1:0] mov_1; reg [1:0] mov_1;
output [1:0] mov_2; reg [1:0] mov_2;
output stop_1; reg stop_1;
output stop_2; reg stop_2;
output [1:0] ch_stat_1; reg [1:0] ch_stat_1;
output [1:0] ch_stat_2; reg [1:0] ch_stat_2;
// output pv;
// reg pv;
always @( posedge sel_2)//or stat_2 or req_2 or up_2 or down_2 or now_2) //////////////////////////////电梯二
begin
mov_2 = 0;
stop_2 = 0;
ch_stat_2 = 0;
des_2 = 0;
req_clr_2 = 0;
//避免形成Latch...
case (stat_2)
2'b00: begin //电梯处于等待状态的调度
case(req_2)
2'b00 : begin
if(up_2) begin
ch_stat_2 = 2'b01;
mov_2 = 2'b01;
stop_2 = 1'b0;
end
else begin
if(down_2)
begin
ch_stat_2 = 2'b10;
mov_2 = 2'b10;
stop_2 = 1'b0;
end
else //上下均无请求
begin
ch_stat_2 = 2'b00;
mov_2 = 2'b00;
stop_2 = 1'b0; //停 但是不开门
end
end
end
2'b11 ,
2'b01 : begin
ch_stat_2 = 2'b01;
stop_2 = 1'b1;
mov_2 = 2'b01; //只是规定了响应之后的运动方向 还应有一个开门的信号 需协调
req_clr_2 = 2'b01; //撤销所有相关请求的信号 01为撤销向上的请求
des_2 = 1;
end
2'b10 : begin
ch_stat_2 = 2'b10;
mov_2 = 2'b10; //同上
stop_2 = 1'b1;
req_clr_2 = 2'b10; //10表示撤销向下的请求
des_2 = 1;
end
default: begin
ch_stat_2 = stat_2;
mov_2 = 2'b00;
stop_2 = 1'b0; //同上
end
endcase
end
2'b01: begin //电梯处于向上状态的调度
case(req_2)
2'b00: begin //外部无请求的情况
if(now_2)//本层是目的地
begin
if(floor_2 == 7)
begin
if(down_2)
begin
mov_2 = 2'b10;
ch_stat_2 = 2'b10;
stop_2 = 'b1;
des_2 = 'b1;
end
else
begin
mov_2 = 'b00;
ch_stat_2 = 'b00;
stop_2 = 'b0;
des_2 = 'b1;
end
end
else
begin
mov_2 = 2'b01;
ch_stat_2 = 2'b01;
stop_2 = 1'b1;
des_2 = 1;
end
end
else begin
if(up_2) begin
ch_stat_2 = 2'b01;
mov_2 = 2'b01;
stop_2 = 1'b0;
end
else begin
if(down_2) begin
ch_stat_2 = 2'b10;
mov_2 = 2'b10;
stop_2 = 1'b0;
end
else begin
ch_stat_2 = 2'b00;
mov_2 = 2'b00;
stop_2 = 1'b0;//都无请求 停在此层
end
end
end
end
2'b11,
2'b01: begin //外部有向上请求的情况
ch_stat_2 = 2'b01;
mov_2 = 2'b01;
stop_2 = 1'b1;// 停下响应本层
des_2 = 1;
req_clr_2 = 2'b01;
end
2'b10: begin
if(now_2)//本层是目的地
begin
if(floor_2 == 7)
begin
mov_2 = 2'b10;
ch_stat_2 = 2'b10;
stop_2 = 'b1;
des_2 = 'b1;
end
else
begin
if(up_2)
begin
mov_2 = 2'b01;
ch_stat_2 = 2'b01;
stop_2 = 1'b1;
des_2 = 1;
end
else
begin
mov_2 ='b10;
ch_stat_2 = 'b10;
stop_2 = 'b1;
des_2 = 'b1;
end
end
end
else begin
if(up_2)
begin
ch_stat_2 = 2'b01;
mov_2 = 2'b01;
stop_2 = 1'b0;
end
else begin
ch_stat_2 = 2'b10;
mov_2 = 2'b10;
stop_2 = 1'b1;
des_2 = 1;
req_clr_2 = 2'b10;
end
end
end
default:begin
ch_stat_2 = stat_2;
mov_2 = 0;
stop_2 = 1'b0;
end
endcase
end
2'b10: begin //电梯处于向下的状态
case(req_2)
2'b00: begin
if(now_2) begin
if(floor_2 == 0)
if(up_2)
begin
ch_stat_2 = 2'b01;
mov_2 = 2'b01;//相应本层目的
stop_2 = 1'b1;
des_2 = 1;
end
else
begin
ch_stat_2 = 2'b00;
mov_2 = 2'b00;
stop_2 = 'b0;
des_2 = 'b1;
end
else
begin
ch_stat_2 = 2'b10;
mov_2 = 2'b10;//相应本层目的
stop_2 = 1'b1;
des_2 = 1;
end
end
else begin
if(down_2)
begin
ch_stat_2 = 2'b10;
mov_2 = 2'b10;
stop_2 = 1'b0;
end
else begin
if(up_2)
begin
ch_stat_2 = 2'b01;
mov_2 = 2'b01;
stop_2 = 1'b0;
end
else begin
ch_stat_2 = 2'b00;
mov_2 = 2'b00;
stop_2 = 1'b0;
end
end
end
end
2'b01: begin
if(now_2)
begin
if(floor_2 == 0)
begin
ch_stat_2 = 2'b01;
mov_2= 2'b01; //响应本层目的
stop_2 = 1'b1;
des_2 = 1;
end
else
begin
if(down_2)
begin
ch_stat_2 ='b10;
mov_2 = 'b10;
stop_2 = 'b1;
des_2 = 'b1;
end
else
begin
ch_stat_2 = 'b01;
mov_2 = 'b01;
stop_2 = 'b1;
des_2 = 'b1;
end
end
end
else begin
if(down_2)
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -