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

📄 cc_port.v

📁 用Verilog实现8255芯片功能
💻 V
字号:
//////////////////////////////////////////////////
//                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,
                select
                );
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;
output[7:0] select;
reg[7:0] select;
//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_set_rst)
    begin
      if(!rst_n)
         begin
           select=8'b0;
         end
      else if(c_set_rst[4])
             begin
                case(c_set_rst[3:1])   
                     3'b000: select=8'b00000001;
                     3'b001: select=8'b00000010;
                     3'b010: select=8'b00000100;
                     3'b011: select=8'b00001000;
                     3'b100: select=8'b00010000;
                     3'b101: select=8'b00100000;
                     3'b110: select=8'b01000000;
                     3'b111: select=8'b10000000;  
                    
                endcase
                
            end
       else  select=8'h00;
    end

always @(rst_n or select or c_port or r_w)
   begin
       if(!rst_n)
           begin
              c_out=8'h00;
            end
       else 
           begin
             case(1)
               select[0]: c_out={c_out[7:1],c_set_rst[0]};
               select[1]: c_out={c_out[7:2],c_set_rst[0],c_out[0]};
               select[2]: c_out={c_out[7:3],c_set_rst[0],c_out[1:0]};
               select[3]: c_out={c_out[7:4],c_set_rst[0],c_out[2:0]};
               select[4]: c_out={c_out[7:5],c_set_rst[0],c_out[3:0]};
               select[5]: c_out={c_out[7:6],c_set_rst[0],c_out[4:0]};
               select[6]: c_out={c_out[7],c_set_rst[0],c_out[5:0]};
               select[7]: c_out={c_set_rst[0],c_out[6:0]};
               default:   
                        begin
                             if(c_port&&r_w)  c_out=c_outbuf;
                        end
              endcase
           end
   end
endmodule

⌨️ 快捷键说明

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