虫虫首页|资源下载|资源专辑|精品软件
登录|注册

您现在的位置是:虫虫下载站 > 资源下载 > 技术资料 > IIC接口E2PROM(AT24C64) 读写VERILOG 驱动源码+仿真激励文件: module

IIC接口E2PROM(AT24C64) 读写VERILOG 驱动源码+仿真激励文件: module

资 源 简 介

IIC接口E2PROM(AT24C64) 读写VERILOG 驱动源码+仿真激励文件:

module i2c_dri

    #(

      parameter   SLAVE_ADDR = 7'b1010000   ,  //EEPROM从机地址

      parameter   CLK_FREQ   = 26'd50_000_000, //模块输入的时钟频率

      parameter   I2C_FREQ   = 18'd250_000     //IIC_SCL的时钟频率

    )

   (                                                            

    input                clk        ,    

    input                rst_n      ,   

                                         

    //i2c interface                      

    input                i2c_exec   ,  //I2C触发执行信号

    input                bit_ctrl   ,  //字地址位控制(16b/8b)

    input                i2c_rh_wl  ,  //I2C读写控制信号

    input        [15:0]  i2c_addr   ,  //I2C器件内地址

    input        [ 7:0]  i2c_data_w ,  //I2C要写的数据

    output  reg  [ 7:0]  i2c_data_r ,  //I2C读出的数据

    output  reg          i2c_done   ,  //I2C一次操作完成

    output  reg          i2c_ack    ,  //I2C应答标志 0:应答 1:未应答

    output  reg          scl        ,  //I2C的SCL时钟信号

    inout                sda        ,  //I2C的SDA信号

                                       

    //user interface                   

    output  reg          dri_clk       //驱动I2C操作的驱动时钟

     );


//localparam define

localparam  st_idle     = 8'b0000_0001; //空闲状态

localparam  st_sladdr   = 8'b0000_0010; //发送器件地址(slave address)

localparam  st_addr16   = 8'b0000_0100; //发送16位字地址

localparam  st_addr8    = 8'b0000_1000; //发送8位字地址

localparam  st_data_wr  = 8'b0001_0000; //写数据(8 bit)

localparam  st_addr_rd  = 8'b0010_0000; //发送器件地址读

localparam  st_data_rd  = 8'b0100_0000; //读数据(8 bit)

localparam  st_stop     = 8'b1000_0000; //结束I2C操作


//reg define

reg            sda_dir   ; //I2C数据(SDA)方向控制

reg            sda_out   ; //SDA输出信号

reg            st_done   ; //状态结束

reg            wr_flag   ; //写标志

reg    [ 6:0]  cnt       ; //计数

reg    [ 7:0]  cur_state ; //状态机当前状态

reg    [ 7:0]  next_state; //状态机下一状态

reg    [15:0]  addr_t    ; //地址

reg    [ 7:0]  data_r    ; //读取的数据

reg    [ 7:0]  data_wr_t ; //I2C需写的数据的临时寄存

reg    [ 9:0]  clk_cnt   ; //分频时


相 关 资 源