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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? i2c_slave.vhd

?? IIC的IP.這是經(jīng)過驗(yàn)證的源代碼
?? 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;

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



?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美日韩激情在线| 久久精工是国产品牌吗| 欧美三级日韩在线| 精品国产露脸精彩对白| 亚洲国产一区视频| 成人一级视频在线观看| 欧美精品一区二区三区很污很色的| 一区二区高清视频在线观看| 激情偷乱视频一区二区三区| 欧美男生操女生| 日韩精品国产精品| 欧美影院一区二区| 亚洲一区二区精品视频| 欧美日韩亚洲综合在线| 偷拍一区二区三区| 欧美一级一区二区| 丁香六月综合激情| 一区二区三区不卡在线观看| 日韩一级欧美一级| 成人激情电影免费在线观看| 一区二区三区.www| 欧美一级片在线| 成人免费毛片a| 亚洲综合一二三区| 日韩欧美成人激情| 99在线视频精品| 日韩激情av在线| 中文字幕乱码亚洲精品一区| 欧美视频精品在线观看| 国产精品一级片| 亚洲国产成人porn| 日本一二三四高清不卡| 欧美酷刑日本凌虐凌虐| 国产a视频精品免费观看| 亚洲丶国产丶欧美一区二区三区| 日韩一区二区电影网| 不卡一区二区三区四区| 老司机精品视频一区二区三区| 日韩一区在线看| 日韩欧美精品在线视频| 91在线无精精品入口| 精品午夜一区二区三区在线观看| 亚洲欧美乱综合| 久久久久久久性| 3d成人h动漫网站入口| 99在线精品一区二区三区| 乱中年女人伦av一区二区| 亚洲一区精品在线| 国产精品美女一区二区| 日韩精品一区二区在线| 欧美自拍丝袜亚洲| 不卡视频一二三| 国产精品一区二区三区四区| 午夜精品一区二区三区免费视频 | 美女任你摸久久| 亚洲九九爱视频| 国产精品素人视频| 久久综合色天天久久综合图片| 欧美肥妇free| 欧美天天综合网| 色综合久久久久综合| 国产白丝精品91爽爽久久| 久久丁香综合五月国产三级网站| 亚洲高清在线精品| 亚洲激情五月婷婷| 亚洲欧美另类久久久精品2019| 国产精品亲子乱子伦xxxx裸| 久久午夜老司机| 精品播放一区二区| 精品理论电影在线观看| 91精品国产入口在线| 欧美日韩mp4| 欧美美女直播网站| 欧美福利电影网| 欧美夫妻性生活| 欧美少妇一区二区| 欧美日韩一区在线| 7777精品伊人久久久大香线蕉完整版 | 国产精品乡下勾搭老头1| 日韩avvvv在线播放| 午夜视频在线观看一区二区三区| 亚洲小说春色综合另类电影| 夜夜嗨av一区二区三区四季av| 日韩毛片视频在线看| 亚洲欧洲无码一区二区三区| 亚洲欧美在线另类| 一区二区不卡在线视频 午夜欧美不卡在 | 国产在线一区二区综合免费视频| 国产又黄又大久久| 99久久久精品免费观看国产蜜| 国产风韵犹存在线视精品| 岛国av在线一区| 91丨porny丨在线| 在线观看日韩一区| 91精品欧美久久久久久动漫| 精品久久久久久久久久久久久久久| 欧美一级欧美三级在线观看| 久久综合999| 国产精品成人一区二区三区夜夜夜| 最新高清无码专区| 天天色 色综合| 国产一区二区三区黄视频| 成人亚洲精品久久久久软件| 91黄视频在线观看| 99re亚洲国产精品| 中文字幕一区二区三区不卡在线| 中文字幕一区二区三区不卡| 亚洲另类春色校园小说| 五月婷婷激情综合| 国产一区在线看| 在线观看亚洲精品| 日韩欧美色综合| 最近日韩中文字幕| 美女视频黄 久久| proumb性欧美在线观看| 这里只有精品电影| 国产精品国产三级国产| 日韩成人一区二区| 白白色 亚洲乱淫| 9191成人精品久久| 国产精品毛片a∨一区二区三区| 香蕉久久夜色精品国产使用方法| 国产又粗又猛又爽又黄91精品| 色爱区综合激月婷婷| 久久综合五月天婷婷伊人| 一区二区三区成人| 国产精品夜夜嗨| 欧美精品在线一区二区三区| 国产精品国产三级国产aⅴ入口| 日韩成人精品在线| 91网页版在线| 精品国产髙清在线看国产毛片| 夜色激情一区二区| 成人性生交大片免费看中文网站| 欧美二区三区的天堂| 亚洲视频每日更新| 国产成人av电影在线观看| 欧美日韩国产综合视频在线观看 | 性感美女久久精品| 94色蜜桃网一区二区三区| www.亚洲在线| 欧美xingq一区二区| 性欧美疯狂xxxxbbbb| 99久久精品久久久久久清纯| 久久婷婷成人综合色| 免费成人美女在线观看.| 91久久一区二区| 亚洲免费成人av| 成人精品在线视频观看| 久久五月婷婷丁香社区| 美女mm1313爽爽久久久蜜臀| 欧美剧情片在线观看| 亚洲国产精品久久人人爱蜜臀 | 国产一区二区三区精品欧美日韩一区二区三区 | 韩国三级电影一区二区| 日韩午夜在线影院| 性做久久久久久免费观看欧美| 91啪在线观看| 亚洲欧美另类图片小说| 91麻豆高清视频| 亚洲免费色视频| 91日韩一区二区三区| 日韩一区中文字幕| 99国产精品久| 最好看的中文字幕久久| av激情综合网| 亚洲美女免费视频| 色哟哟一区二区三区| 亚洲精品美国一| 欧美日韩精品福利| 日日摸夜夜添夜夜添亚洲女人| 欧美天堂一区二区三区| 五月天激情小说综合| 欧美日韩国产欧美日美国产精品| 午夜精品久久久久久久99樱桃| 欧美日韩一区 二区 三区 久久精品| 亚洲综合一二区| 91精品国产丝袜白色高跟鞋| 日本亚洲视频在线| 精品少妇一区二区三区免费观看 | 天涯成人国产亚洲精品一区av| 欧美视频在线播放| 免费看欧美美女黄的网站| 精品福利一区二区三区免费视频| 国产美女av一区二区三区| 国产清纯白嫩初高生在线观看91 | 亚洲欧美一区二区不卡| 欧美亚洲一区二区在线| 青草av.久久免费一区| 久久嫩草精品久久久精品| 欧美特级限制片免费在线观看| 亚洲国产乱码最新视频| 日韩欧美在线观看一区二区三区| 精一区二区三区| 亚洲免费在线视频一区 二区| 欧美二区三区的天堂| 国产白丝网站精品污在线入口| 一区二区高清免费观看影视大全 | 日日欢夜夜爽一区| 国产三级精品在线|