📄 r_w_con.v
字号:
//////////////////////////////////////////////////
// 8255的读写控制逻辑单元 //
//model name: r_w_con //
//time: 2006.10.28 //
//author: cheng fangmin //
//function: 控制8255 //
//////////////////////////////////////////////////
module r_w_con(//input
rst_n, //reset signal
cs_n, //chip select
a0,
a1,
wr_n, //write signal
rd_n, //read signal
// data input
d_inbuf,
//output
//control data bus buffer
lk_bus,
//control internal bus
bus_con,
//control C port
r_w,
c_port,
c_upper_io,
c_lower_io,
c_set_rst,
//control B port
b_mode_io,
b_port,
//control A port
a_mode_io,//A口在模式0下是输入还是输出
a_port, //为1,选中对A口操作。
con //附加信号,便于观察
);
output con;
// input from CPU
input rst_n,cs_n,a0,a1,wr_n,rd_n;
//input from data bus buffer
input[7:0] d_inbuf;
//control data bus buffer
output lk_bus;
wire lk_bus;
//control internal bus
output[3:0] bus_con;
reg[3:0] bus_con;
//control A port
output a_mode_io,a_port;
reg a_mode_io,a_port;
//control B port
output b_mode_io,b_port;
reg b_mode_io,b_port;
//control C port
output c_upper_io,c_lower_io,c_port,r_w;
output[4:0] c_set_rst;
reg c_upper_io,c_lower_io,c_port,r_w;
wire[4:0] c_set_rst;
//internal signal
wire[1:0] port_select;
reg con;
reg[7:0] con_word;
//A1. A0. cs组成片选信号和寄存器选择信号
assign port_select={a1,a0};
always @(cs_n or port_select)
begin
if(!cs_n)
begin
case(port_select)
2'b00:
begin
a_port=1'b1;
b_port=1'b0;
c_port=1'b0;
con=1'b0;
end
2'b01:
begin
a_port=1'b0;
b_port=1'b1;
c_port=1'b0;
con=1'b0;
end
2'b10:
begin
a_port=1'b0;
b_port=1'b0;
c_port=1'b1;
con=1'b0;
end
2'b11:
begin
a_port=1'b0;
b_port=1'b0;
c_port=1'b0;
con=1'b1;
end
endcase
end
else
begin
a_port=1'b0;
b_port=1'b0;
c_port=1'b0;
con=1'b0;
end
end
//wr_n rd_n 组成的控制信号,
always @(wr_n or rd_n)
begin
if((wr_n==1)&&(rd_n==0)) r_w=1'b0;
else r_w=1'b1;
end
//对数据总线缓冲器的控制信号
assign lk_bus=~r_w;
//对控制逻辑内部寄存器con_word[7:0]的操作。
always @(rst_n or con or d_inbuf)
begin
if(!rst_n) con_word=8'b0;
else if(con) con_word=d_inbuf;
end
//对A口的控制信号的产生。
always @(rst_n or con_word)
begin
if(!rst_n)
begin
a_mode_io<=1'b1;
b_mode_io<=1'b1;
c_upper_io<=1'b1;
c_lower_io<=1'b1;
end
else if(con_word)
begin
a_mode_io<=con_word[4];
b_mode_io<=con_word[1];
c_upper_io<=con_word[3];
c_lower_io<=con_word[0];
end
end
assign c_set_rst[4:0]={con&(~con_word[7]),con_word[3:0]};//控制是否对C口的某一位进行置位复位。
//对内部总线的控制信号的产生。
always @(r_w or c_port or a_port or b_port)
begin
if(r_w) bus_con=4'b1000;
else bus_con={r_w,c_port,b_port,a_port};
end
endmodule
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -