亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? i2c_slave.vhd

?? IIC的IP.這是經過驗證的源代碼
?? VHD
?? 第 1 頁 / 共 2 頁
字號:
------------------------------------------------------------------------------
-- 
--  Name:  i2c_slave.vhd  
-- 
--  Description:  i2c slave emulation model for simulation
-- 
--  $Revision: 1.0 $          
--  
--  Copyright 2004 Lattice Semiconductor Corporation.  All rights reserved.
--
------------------------------------------------------------------------------
-- Permission:
--
--   Lattice Semiconductor grants permission to use this code for use
--   in synthesis for any Lattice programmable logic product.  Other
--   use of this code, including the selling or duplication of any
--   portion is strictly prohibited.
--
-- Disclaimer:
--
--   This VHDL or Verilog source code is intended as a design reference
--   which illustrates how these types of functions can be implemented.
--   It is the user's responsibility to verify their design for
--   consistency and functionality through the use of formal
--   verification methods.  Lattice Semiconductor provides no warranty
--   regarding the use or functionality of this code.
------------------------------------------------------------------------------
--
--    Lattice Semiconductor Corporation
--    5555 NE Moore Court
--    Hillsboro, OR 97124
--    U.S.A
--
--    TEL: 1-800-Lattice (USA and Canada)
--    408-826-6000 (other locations)
--
--    web: http://www.latticesemi.com/
--    email: techsupport@latticesemi.com
-- 
------------------------------------------------------------------------------


--This is a generic standard mode slave model for I2C.
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned."-";
use ieee.std_logic_unsigned."+";
use ieee.std_logic_textio.all;
use std.textio.all;
use ieee.numeric_std.all;


entity i2c_slave is port (     scl : in std_logic;
                         sda : inout std_logic);

end i2c_slave;

architecture behave of i2c_slave is

signal clk : std_logic := '0';
signal rst_l : std_logic;
type mem_256 is array (255 downto 0) of std_logic_vector(7 downto 0);
signal mem:mem_256;
signal word_address    : std_logic_vector(7 downto 0) := "00000000"; -- counts the active byte 
signal start_detect    : std_logic;
signal stop_detect     : std_logic;
signal sda_reg         : std_logic;
signal sda_reg_delayed : std_logic;
signal scl_reg         : std_logic;
signal scl_reg_delayed : std_logic;
signal start_pulse     : std_logic;
signal stop_pulse      : std_logic;
signal scl_pulse       : std_logic;
signal scl_neg_pulse   : std_logic;
signal address_reg_7   : std_logic_vector(6 downto 0);-- All 7 Bits of 7 bit addressing
signal temp10          : std_logic_vector(9 downto 0);
signal address_reg_10_upper      : std_logic_vector(6 downto 0);-- Upper 2 bits of address
signal address_reg_10_lower      : std_logic_vector(7 downto 0); -- lower 8 bits of address
signal current_state  : std_logic_vector(3 downto 0);
signal next_state     : std_logic_vector(3 downto 0);
signal in_reg         : std_logic_vector(7 downto 0) := "00000000"; 
signal out_reg        : std_logic_vector(7 downto 0):= "00000000"; -- registers used to hold the input
-- and output data to-from the sda line
signal bit_counter    : std_logic_vector(3 downto 0) := "0000"; -- Used to counter what bit is being selected
-- for the in_reg and out_reg
signal r_w_bit        : std_logic := '0'; -- used to hold the read write bit;
signal hit_7          : std_logic := '0'; 
signal hit_10_upper   : std_logic := '0'; 
signal hit_10_lower   : std_logic := '0'; -- flags for address hits
signal sda_out        : std_logic := '0'; 
signal sda_out2       : std_logic := '0'; 
signal ack_ctrl       : std_logic := '0'; 
signal in_reg_enable  : std_logic := '0'; -- the clock enable for the in_reg registers.
signal out_en         : std_logic := '0'; -- the output enable
signal word_add_flag  : std_logic := '0'; 
signal ack_flag       : std_logic := '0'; 
signal temp_add_upper : std_logic_vector(7 downto 1) := "0000000"; 
signal temp_add_lower : std_logic_vector(7 downto 0) := "00000000"; -- temp_add_upper & temp_add_lower are
-- used to hold the first & 
-- second address bytes of 10 bit
-- addressing so that during a 10 bit addressing
-- read the value of the current 10 bit address
-- can be compared with the last read.
signal read_10_flag : std_logic := '0'; -- This flag is set when the temp_add matches the current 
-- address_reg_10_upper and the r/w is a 1.  This tells
-- the ack to goto a data read state instead of getting
-- the second byte of address.


-----------------------------------------------------------------------
-- defines

-- used for address_mode parameter
constant seven_bit : integer := 0; 
-- used for address_mode parameter
constant ten_bit : integer := 1; 
-- used in upper 5 bits of address_reg_10_upper 
-- DON'T CHANGE
--`define ten_bit_add "11110"
constant ten_bit_add : std_logic_vector(4 downto 0) := "11110";
--  a 1 turns this on and a 0 off
--`define debug 0
constant debug : integer := 0;

-----------------------------------------------------------------------
-- constants
constant period      : time := 30 ns;-- using 33 MHz
constant reset_time  : time := 20 ns;-- hold reset low this long

-- DESIGNER SET the following parameter to use 7 or 10 bit addressing
constant address_mode : integer := 0; --`seven_bit;  Use `seven_bit or `ten_bit

-- depending on the value in address_mode either seven_bit_address or 
-- ten_bit_address will be used.

-- DESIGNER SET the next parameter with the 7 bit address the slave
-- should respond to. MSB->LSB
-- example: "1010_000"; 
constant seven_bit_address : std_logic_vector(6 downto 0) := "1010000";

-- DESIGNER SET the next parameter with the 10 bit address the slave
-- should respond to. MSB->LSB
-- example: "1011001010";
constant ten_bit_address : std_logic_vector(9 downto 0) := "1011001010";

-- state bits
constant idle     : std_logic_vector(3 downto 0) := "0000"; 
constant start    : std_logic_vector(3 downto 0) := "0001"; 
constant address  : std_logic_vector(3 downto 0) := "0010"; 
constant ack      : std_logic_vector(3 downto 0) := "0011"; 
constant data     : std_logic_vector(3 downto 0) := "0100"; 
constant data_ack : std_logic_vector(3 downto 0) := "0101"; 


signal test_std_vec : std_logic_vector(7 downto 0);
signal test_int :integer;

-- signals to convert sda and scl from 0 or H values to bit values
signal sda1 : bit;
signal scl1 : bit;

begin
test_std_vec <= "00000010";
-----------------------------------------------------------------------
-- internal clock for the model

clk <= not clk after(period / 2);


-----------------------------------------------------------------------

-----------------------------------------------------------------------------
-- sda_out is an internal reg that is assigned a 0 when the output should be
-- 0 and it assigns a Z otherwise.

sda <= '0' when (sda_out = '0' and out_en = '1' and sda_out2 = '0') else 'Z'; 

sda1 <= To_bit(sda);
scl1 <= To_bit(scl);
----------------------------------------------------------------------
-- print some status
status1:process(scl1)
variable L :line;
begin
 if(rising_edge(clk)) then
   if (debug = 1 and scl1 = '1') then
    write(L,now, justified => right, field=>10,unit=>ns);
    write(L,string'(" Received Clock Data "));
    write(L, sda1);
    writeline(output,L);   

   end if;
 end if;
end process;


-----------------------------------------------------------------------
-- initialize the address registers, mem array, clk and control the reset

initial : process 
variable L : line;
variable cnt:std_logic_vector(7 downto 0);
begin
      rst_l          <= '0'; -- turn on reset signal 
      wait for reset_time;                           
      rst_l          <= '1'; -- turn off reset signal    
      temp10 <= "0000000000";
      address_reg_10_upper <= "0000000";
      address_reg_10_lower <= "00000000";
    -- initialize the address registers
    if (address_mode = seven_bit) then
    write(L,now, justified => right, field=>10,unit=>ns);
    write(L,string'(" Using 7 bit Addressing "));
    writeline(output,L);   

      address_reg_7 <= seven_bit_address;
    elsif (address_mode = ten_bit) then
    write(L,now, justified => right, field=>10,unit=>ns);
    write(L,string'(" Using 10 Bit Addressing "));
    writeline(output,L);   

      temp10 <= ten_bit_address;
      address_reg_10_upper <= ten_bit_add & temp10(9 downto 9); --{`ten_bit_add, temp10[9:8]};  2 MSB
      address_reg_10_lower <= temp10(7 downto 0);
    else 
    write(L,now, justified => right, field=>10,unit=>ns);
    write(L,string'(" ERROR address_mode parameter is INVALID "));
    writeline(output,L);   
    end if;
    
    wait; -- execute this process only once
    
end process;


------------------------------------------------------------------------
-- start and stop detect logic
ss : process (clk,rst_l,sda1)
begin 
  if (rst_l = '0') then
      sda_reg <= '1'; -- bus is active low
      sda_reg_delayed <= '1';
  elsif(rising_edge(clk)) then 
      if(sda1 = '1') then
       sda_reg <= '1';
      else
       sda_reg <= '0';
      end if;
      sda_reg_delayed <= sda_reg;
  end if;  
end process;

-- detect a high to low while scl is high 
-- start_pulse
srtpulse : process(clk,rst_l)
begin 
  if (rst_l = '0') then 
      start_pulse <= '0';
  elsif(rising_edge(clk)) then
    if(sda_reg = '0' and sda_reg_delayed = '1' and scl1 = '1') then
      start_pulse <= '1';
    else 
      start_pulse <= '0';
    end if;
  end if;
end process;

-- start flag
srtflg : process(clk,rst_l)
begin 
  if (rst_l = '0') then 
      start_detect <= '0';
  elsif(rising_edge(clk)) then
    if(start_pulse = '1') then
      start_detect <= '1';  
    elsif (scl1 = '0') then 
      start_detect <= '0'; -- clear start bit 
    else
      start_detect <= start_detect;
    end if;
    
  end if;
end process;

-- detect a low to high while scl is high 
-- stop_pulse
stppulse : process(clk,rst_l)
begin 
  if (rst_l = '0') then 
      stop_pulse <= '0';
  elsif(rising_edge(clk)) then
    if (sda_reg = '1' and sda_reg_delayed = '0' and scl1 = '1') then 
      stop_pulse <= '1';
    else 
      stop_pulse <= '0';
    end if;
  end if;
end process;

--stop flag
stpflg : process(clk,rst_l)
begin 
  if (rst_l = '0') then 
      stop_detect <= '0';
  elsif(rising_edge(clk)) then
    if (stop_pulse = '1') then
      stop_detect <= '1';  
    elsif (current_state = idle) then
      stop_detect <= '0'; -- clear start bit 
    end if;
  end if;
end process;  
------------------------------------------
 

------------------------------------------
-- SCL posedge & nededge detector regs
scldet : process(clk,rst_l,scl)
begin 
  if (rst_l = '0') then 
      scl_reg <= '1';
      scl_reg_delayed <= '1';
  elsif(rising_edge(clk)) then
      if(scl1 = '1') then
        scl_reg <= '1';
      else
       scl_reg <= '0';
      end if;
      scl_reg_delayed <= scl_reg;
  end if;
    
end process;

-- SCL posedge detector
sclpos : process(clk,rst_l)
begin 
  if (rst_l = '0') then 
      scl_pulse <= '0';    
  elsif(rising_edge(clk)) then
    if (scl_reg = '1' and scl_reg_delayed = '0') then
      scl_pulse <= '1';
    else 
      scl_pulse <= '0'; 
    end if;
  end if;  
end process;

-- SCL negedge detector
sclneg : process(clk,rst_l)
begin 
  if (rst_l = '0') then 
      scl_neg_pulse <= '0';
  elsif(rising_edge(clk)) then
    if (scl_reg = '0' and scl_reg_delayed = '1') then 
      scl_neg_pulse <= '1';
    else 
      scl_neg_pulse <= '0';
    end if;
  end if;
    
end process;

--------------------------------------------


--------------------------------------------
-- Output Mux
outmux:process(out_reg, bit_counter,ack_ctrl,sda_out2)
begin
  if(ack_ctrl = '0') then
    case bit_counter is
      when "0000" =>
            sda_out <= out_reg(7); 
      when "0001" =>
            sda_out <= out_reg(6);
      when "0010" =>
            sda_out <= out_reg(5);
      when "0011" =>
            sda_out <= out_reg(4);
      when "0100" =>
            sda_out <= out_reg(3);
      when "0101" =>
            sda_out <= out_reg(2);
      when "0110" =>
            sda_out <= out_reg(1);
      when "0111" =>
            sda_out <= out_reg(0);
      when others =>
            sda_out <= out_reg(0);
      end case;
  else
    sda_out <= sda_out2;
  end if;

end process;

--------------------------------------------



?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
精品对白一区国产伦| 中文字幕va一区二区三区| 婷婷国产在线综合| 欧美日韩激情在线| 天堂午夜影视日韩欧美一区二区| 日韩免费视频一区| 亚洲综合色网站| 欧美日韩一区二区三区四区五区| 亚洲在线一区二区三区| 欧美主播一区二区三区| 日韩av电影天堂| 精品99999| 色婷婷国产精品久久包臀| 亚洲成av人**亚洲成av**| 欧美一区在线视频| 成人激情午夜影院| 一区二区三区四区视频精品免费| 欧美日本高清视频在线观看| 久久精品国产77777蜜臀| 中文字幕不卡三区| 日韩一区二区三区电影在线观看 | 精品视频在线免费看| 久久精品国产秦先生| 一区二区三区四区av| 久久综合色8888| 色综合中文字幕国产| 亚洲福中文字幕伊人影院| 久久天堂av综合合色蜜桃网| 色婷婷av一区二区| 国模冰冰炮一区二区| 一区二区三区精品在线| 国产欧美综合色| 精品国产露脸精彩对白| 欧美日韩国产经典色站一区二区三区| 97aⅴ精品视频一二三区| 天天射综合影视| 亚洲午夜私人影院| 亚洲欧美另类久久久精品2019| 久久久久久夜精品精品免费| 欧美一区中文字幕| 91精品久久久久久久91蜜桃 | 日本一不卡视频| 亚洲一级片在线观看| 亚洲综合小说图片| 亚洲伦在线观看| 亚洲美女免费视频| 一区二区三区四区在线| 亚洲综合视频在线| 日韩电影在线看| 日本午夜一区二区| 国产美女久久久久| 成人综合婷婷国产精品久久蜜臀| 国产做a爰片久久毛片| 国产不卡一区视频| 91蝌蚪porny| 欧美日韩高清一区二区三区| 欧美日韩免费视频| 日韩精品一区二区三区在线观看| 91精品国产一区二区三区| 精品美女在线播放| 国产精品系列在线| 亚洲精品欧美在线| 日韩精品一二区| 成人毛片老司机大片| 欧美日韩免费高清一区色橹橹| 7777精品伊人久久久大香线蕉 | 欧美视频一区二区三区四区| 日韩欧美一级在线播放| 日本一区二区电影| 三级欧美韩日大片在线看| 国产99久久久国产精品免费看| 在线观看三级视频欧美| 精品第一国产综合精品aⅴ| 亚洲美女偷拍久久| 国产综合色精品一区二区三区| 色婷婷久久久亚洲一区二区三区| 国产精品视频麻豆| 亚洲一区二区三区国产| 国产成人自拍在线| 精品美女在线播放| 日本大胆欧美人术艺术动态| 成人美女在线视频| 久久精品一区四区| 免费三级欧美电影| 欧美日本乱大交xxxxx| 国产精品成人免费在线| 激情成人午夜视频| 日韩亚洲欧美成人一区| 婷婷综合在线观看| 777a∨成人精品桃花网| 有坂深雪av一区二区精品| av不卡免费电影| 国产精品美女久久福利网站| 加勒比av一区二区| 欧美变态凌虐bdsm| 久久不见久久见中文字幕免费| 欧美日韩夫妻久久| 爽好久久久欧美精品| 欧美性一二三区| 亚洲v精品v日韩v欧美v专区| 欧美日韩精品一区二区天天拍小说| 亚洲免费观看高清完整版在线| 99久久久久久| 亚洲精品中文在线影院| 91丨porny丨中文| 亚洲图片欧美视频| 26uuu精品一区二区三区四区在线 26uuu精品一区二区在线观看 | 美国毛片一区二区| 日本一区二区三区久久久久久久久不| 国产乱码一区二区三区| 亚洲女爱视频在线| 91麻豆精品国产91久久久久| 免费在线观看成人| 国产精品久久久久久久久免费樱桃| 91网页版在线| 麻豆91免费观看| 亚洲精品国产一区二区三区四区在线| 欧美日韩国产大片| 成人午夜免费电影| 麻豆国产欧美日韩综合精品二区 | 国产片一区二区三区| 欧美日韩www| 成年人国产精品| 韩国毛片一区二区三区| 亚洲美女在线国产| 久久久精品国产免费观看同学| 欧美性色aⅴ视频一区日韩精品| 久久99久国产精品黄毛片色诱| 亚洲欧美在线视频观看| 精品国产污网站| 日韩精品一区二区三区视频| 欧美日韩亚洲综合一区二区三区| 国产91清纯白嫩初高中在线观看 | 成人免费电影视频| 国产一区美女在线| 日本美女一区二区三区| 亚洲综合一二区| 亚洲午夜影视影院在线观看| 亚洲一区精品在线| 亚洲一区二区三区四区不卡| 国产精品福利一区二区| 国产午夜精品久久久久久免费视 | 久久精品国产亚洲aⅴ| 国产精品免费免费| 一区二区三区不卡视频在线观看| 午夜电影网一区| 成人v精品蜜桃久久一区| 99re成人在线| 成人高清视频在线| 色综合天天综合色综合av| 99久久99久久精品免费看蜜桃| 成人妖精视频yjsp地址| 丁香婷婷深情五月亚洲| 成人精品视频一区二区三区尤物| 国产一区二区三区久久久| 成人av午夜影院| 99精品视频一区二区三区| 欧美色大人视频| 欧美成人乱码一区二区三区| 久久新电视剧免费观看| 国产精品网站在线播放| 亚洲宅男天堂在线观看无病毒| 韩国视频一区二区| 欧美视频第二页| 亚洲视频图片小说| 国产精品原创巨作av| 日韩一区二区三区电影在线观看 | 日韩视频一区二区三区在线播放| 日韩欧美不卡一区| 亚洲视频 欧洲视频| 免费的国产精品| 欧美精品亚洲二区| 中文字幕一区二区三区在线播放 | 欧美一卡二卡三卡四卡| 亚洲欧洲在线观看av| 国产清纯白嫩初高生在线观看91 | 综合中文字幕亚洲| 99久久免费精品| 精品sm捆绑视频| 国产精品影视在线| 久久久国际精品| 99久精品国产| 亚洲日本免费电影| 91影院在线观看| 综合激情网...| 国产不卡免费视频| 久久你懂得1024| 国产乱码精品一区二区三区av | 国产日产精品一区| 成人一区二区三区中文字幕| 国产精品久久久久婷婷二区次| 97精品久久久午夜一区二区三区 | 国产一区三区三区| 国产精品久久久久一区| 欧美日韩一区久久| 精品在线视频一区| 国产精品久久久久久亚洲伦| 日本韩国一区二区三区视频| 亚洲国产欧美在线人成| 7777精品伊人久久久大香线蕉的|