⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 top_8255.v

📁 用Verilog实现8255芯片功能
💻 V
📖 第 1 页 / 共 2 页
字号:
//internal signal 
wire[1:0] port_select;
reg con;
reg[7:0] con_word;


//A1. A0. cs组成片选信号和寄存器选择信号
assign port_select={a1,a0};
always
   begin
     if(!cs_n) 
         begin
           case(port_select)
               2'b00: 
                     begin 
                       a_port=1;
                       b_port=0;
                       c_port=0;
                       con=0;
                     end
               2'b01:  
                     begin 
                       a_port=0;
                       b_port=1;
                       c_port=0;
                       con=0;
                     end

               2'b10:
                     begin 
                       a_port=0;
                       b_port=0;
                       c_port=1;
                       con=0;
                     end
               2'b11: 
                     begin 
                       a_port=0;
                       b_port=0;
                       c_port=0;
                       con=1;
                     end 
           endcase                           
         end
    else 
         begin
             a_port=0;
             b_port=0;
             c_port=0;
             con=0;
         end
   end
  

//wr_n   rd_n 组成的控制信号,
always
  begin
      if((wr_n==1)&&(rd_n==0))   r_w=0;
      else  r_w=1;
  end

//对数据总线缓冲器的控制信号
assign  lk_bus=~r_w;

//对控制逻辑内部寄存器con_word[7:0]的操作。
always 
   begin
         if(!rst_n)   con_word=8'b0;
         else if(con)  con_word=d_inbuf;
   end

//对A口的控制信号的产生。
always
   begin
         if(!rst_n)  a_mode_io=1;
         else if(con_word[7])   a_mode_io=con_word[4];
   end

//对B口的控制信号的产生。
always
   begin
         if(!rst_n)  b_mode_io=1;
         else if(con_word[7])   b_mode_io=con_word[1];
   end

//对C口的控制信号的产生。
always
   begin
         if(!rst_n)  
             begin
                 c_upper_io=1;
                 c_lower_io=1;
             end
         else if(con_word[7])
                   begin
                       c_upper_io=con_word[3];
                       c_lower_io=con_word[0];
                   end
//              else c_set_rst[3:0]=con_word[3:0]; 
   end
assign  c_set_rst[4:0]={con&(~con_word[7]),con_word[3:0]};//控制是否对C口的某一位进行置位复位。

//对内部总线的控制信号的产生。
always
   begin
          if(r_w)   bus_con=4'b1000;
          else  bus_con={r_w,c_port,b_port,a_port};
   end

endmodule

  
//////////////////////////////////////////////////
//               A口单元                        //
//model name:     aa_port                       //
//time:           2006.10.28                    //
//author:       cheng fangmin                   //
//function:      实现A口的输入输出              //
//////////////////////////////////////////////////
module aa_port(//input
               a_port,
               a_mode_io,
               a_outbuf,
               //output
               a_inbuf,
               //inout
               a_bus
               );
//control signal;
input a_port,a_mode_io;

//数据通道连接内部总线。
input[7:0]  a_outbuf;
output[7:0] a_inbuf;
reg[7:0] a_inbuf;

//与外设的连接口
inout[7:0] a_bus;


reg[7:0] a_out;

//
assign  a_bus=(!a_mode_io)? a_out:8'hzz ;

always
    begin
        if(a_mode_io)
             begin
                    a_inbuf=a_bus;  
             end
         else if(a_port) a_out=a_outbuf;
        
    end
endmodule

//////////////////////////////////////////////////
//               B口单元                        //
//model name:     bb_port                       //
//time:           2006.10.31                    //
//author:       cheng fangmin                   //
//function:      实现B口的输入输出 与A口相同    //
//////////////////////////////////////////////////
module bb_port(//input
               b_port,
               b_mode_io,
               b_outbuf,
               //output
               b_inbuf,
               //inout
               b_bus
               );
//control signal;
input b_port,b_mode_io;

//数据通道连接内部总线。
input[7:0]  b_outbuf;
output[7:0] b_inbuf;
reg[7:0] b_inbuf;

//与外设的连接口
inout[7:0] b_bus;

reg[7:0] b_out;


assign  b_bus=(!b_mode_io)? b_out:8'hzz ;

always
    begin
        if(b_mode_io)
             begin
                    b_inbuf=b_bus;  
             end
         else if(b_port) b_out=b_outbuf;
        
    end
endmodule

//////////////////////////////////////////////////
//                c口单元                       //
//model name:     cc_port                       //
//time:           2006.10.31                    //
//author:       cheng fangmin                   //
//function:      实现c口的输入输出              //
//////////////////////////////////////////////////
module  cc_port(//input
                rst_n,
                c_port,
                r_w,
                c_upper_io,
                c_lower_io,
                c_set_rst,
                c_outbuf,
                //output
                c_inbuf,
                //inout
                c_bus
                );
input c_port,r_w,c_upper_io,c_lower_io,rst_n;
input[4:0]  c_set_rst;
input[7:0] c_outbuf;

output[7:0] c_inbuf;
reg[7:0] c_inbuf;
 
inout[7:0] c_bus;
wire[7:0] c_bus;

//internal register
reg[7:0] c_out;
//C口下半部
assign c_bus[3:0]=(!c_lower_io)?c_out[3:0]:4'hz;
always @(rst_n or c_lower_io or c_bus)
      begin
       if(!rst_n)
         begin
           c_inbuf[3:0]=4'b0;
         end
        else if(c_lower_io) c_inbuf[3:0]=c_bus[3:0];
      end
//C口上半部
assign c_bus[7:4]=(!c_upper_io)?c_out[7:4]:4'hz;
always @(rst_n or c_upper_io or c_bus)
      begin
         if(!rst_n)
           begin
           c_inbuf[7:4]=4'b0;
           end 
       else  if(c_upper_io) c_inbuf[7:4]=c_bus[7:4];
      end
//C口输出时
always @ (rst_n or c_port or r_w or c_outbuf or c_set_rst)
    begin
      if(!rst_n)
         begin
           c_out=8'b0;
         end
      else if(c_set_rst[4])
             begin
                case(c_set_rst[3:1])   //对C口的置位复位操作
                    3'b000:  c_out={c_out[7:1],c_set_rst[0]};
                    
                    3'b001: c_out={c_out[7:2],c_set_rst[0],c_out[0]};
                             
                    3'b010: c_out[2]=c_set_rst[0];
                            
                    3'b011: c_out[3]=c_set_rst[0];
                           
                    3'b100: c_out[4]=c_set_rst[0];
                            
                    3'b101: c_out[5]=c_set_rst[0];
                           
                    3'b110: c_out[6]=c_set_rst[0];
                           
                    3'b111: c_out[7]=c_set_rst[0];
                                        
                endcase
                
            end
       else  if(c_port)    //数据输入输出操作
               begin
                if(r_w) c_out=c_outbuf;
               end
    end
endmodule                             

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -