http://blog.sina.com.cn/s/blog_9bd80b7601012o9y.html

library ieee ;

use ieee.std_logic_1164.all ;

use ieee.std_logic_arith.all ;

use ieee.std_logic_unsigned.all ;

entity I2C_Control is

port (

CLKI      :IN     Std_logic ;

RST    :IN     Std_logic ;

Slave_add  :in  std_logic_vector(3 downto 0);

addr   :in  std_logic_vector(7 downto 0);

wr_rd   :IN     Std_logic ;

DAT1   :in  std_logic_vector(7 downto 0);

Delay_Time  :in  integer range 0 to 255;

A    :buffer std_logic_vector(2 downto 0);

WP    :buffer std_logic;

SCL    :buffer std_logic;

SDA    :buffer std_logic

) ;

end I2C_Control ;

architecture Arch of I2C_Control is

type state1 is (Idle,Idle1, I1,I2,I3,I4,I5,I6,I7,I8,I9,I10,Iok);

signal current_state,next_state : state1;

signal I2C_Sent  :std_logic_vector(26 downto 0);

begin

I2C_Sent <= Slave_add & A & wr_rd &'0'& addr &'0'& DAT1&'0' ;

process(clki,RST)

begin

if RST = '1' then

current_state <= Idle;

elsif clki'event and clki = '0' then

current_state <= next_state;

end if;

end process;

process(clki)

variable i            :integer range 0 to 63;

variable cnt          :integer range 0 to 1023;

begin

if clki'event and clki = '1' then

A<="111";

case current_state is

when Idle =>

SCL <= '1'; SDA <= '1';

WP <= '1';

next_state <= Idle1;

when Idle1 =>

SCL <= '1'; SDA <= '1';

WP <= '0';

next_state <= I1;

when I1   =>

SDA <= '0';

next_state <= I2;

when I2   =>

SCL <= '0';

i :=26;

next_state <= I3;

when I3   =>

SCL <= '0';

SDA <= I2C_Sent(i);

next_state <= I4;

when I4   =>

SCL <= '1';

next_state <= I5;

when I5   =>

if i= 0 then

next_state <= I6;

else

i := i-1;

next_state <= I3;

end if;

when I6   =>

SCL <= '0';

next_state <= I7;

when I7   =>

SCL<= '1';

next_state <= I8;

when I8   =>

SDA <= '1';

next_state <= I9;

when I9   =>

WP<= '1';  --1

next_state <= I10;

WHEN I10 =>

if cnt = Delay_Time then

cnt := 0;

next_state <= Idle;

else

cnt := cnt +1;

end if;

when Iok  =>

SCL <='1';

SDA <= '1';

next_state <= Iok;

when others =>

next_state <= Iok;

end case;

end if;

end process;

end Arch;

I2C VHDL程序的更多相关文章

  1. VHDL程序的库

    VHDL库存储和放置了可被其他VHDL程序调用的数据定义.器件说明.程序包等资源.VHDL库的种类有很多,但最常见的库有IEEE标准库.WORK库.IEEE标准库主要包括STD_LOGIC_1164. ...

  2. 毕业设计预习:VHDL入门知识学习(一) VHDL程序基本结构

    VHDL入门知识学习(一) VHDL程序基本结构 简介 VHDL程序基本结构 简介 概念: HDL-Hardware Description Language-硬件描述语言-描述硬件电路的功能.信号连 ...

  3. 基于BASYS2的VHDL程序——交通灯

    请尊重作者版权,转载请注明原地址: http://www.cnblogs.com/connorzx/p/3676746.html 数电实验交通灯VHDL版,程序写的扩展性很差,待以后有时间进行优化. ...

  4. 基于BASYS2的VHDL程序与仿真——50%占空比8分频器

    转帖请注明转自http://www.cnblogs.com/connorzx/p/3547673.html 一.新建工程 1.点击File->New Project, 2.点击Next 注:此处 ...

  5. Linux i2c 读写程序

    /* This software uses a BSD license. Copyright (c) 2010, Sean Cross / chumby industriesAll rights re ...

  6. 基于BASYS2的VHDL程序——分频和数码管静态显示程序

    转载请注明出处:http://www.cnblogs.com/connorzx/p/3633860.html 分频是基于计数器程序.由于FPGA的并行处理能力,根本不需要单片机式的中断指令,用起来很方 ...

  7. 基于BASYS2的VHDL程序与烧写——按键消抖程序

    请尊重作者版权,转载请注明源地址http://www.cnblogs.com/connorzx/p/3548364.html 按键在按下的过程中通常会产生一段时间的抖动,为了消除这种抖动,一般采取两种 ...

  8. 基于BASYS2的VHDL程序——交通灯(状态机版)

    请尊重作者版权,转载注明源地址:http://www.cnblogs.com/connorzx/p/3694618.html 使用了状态机,增加了可读性和用户体验. library IEEE; use ...

  9. 基于BASYS2的VHDL程序——数字钟(最终版)

    转载请注明原地址:http://www.cnblogs.com/connorzx/p/3674178.html 调时电路正常工作.一切正常.发现做FPGA还是得从数电的思路思考,设置一个预置使能端,预 ...

随机推荐

  1. Button模板,样式

    一.button控件上的模板 <Button Content="Button" Height="25" HorizontalAlignment=" ...

  2. shell 统计某个文件的行数命令

    语法:wc [选项] 文件- 说明:该命令统计给定文件中的字节数.字数.行数.如果没有给出文件名,则从标准输入读取.wc同时也给出所有指定文件的总统计数.字是由空格字符区分开的最大字符串. 该命令各选 ...

  3. java io流之BufferReader&BufferedWriter

    BufferedReader 由Reader类扩展而来,提供通用的缓冲方式文本读取,而且提供了很实用的readLine,读取一个文本行,从字符输入流中读取文本,缓冲各个字符,从而提供字符.数组和行的高 ...

  4. python 识别图片验证码报IOError

    说一下困扰了我一周的问题:识别图片验证码 本来我按照安装步骤(http://www.cnblogs.com/yeayee/p/4955506.html?utm_source=tuicool&u ...

  5. 微信企业号-JS-SDK图像接口

    使用JS-SDK需要进行四步  主要是步骤二和步骤三,步骤二需要配置,步骤三具体使用相关接口,这里以使用图像接口为例 php页面代码主要用来完成步骤二,也就是配置接口 public function ...

  6. JavaWeb 学习0010-今日问题 2016-12-3

    2016-12-3 1. 今天要做的第一个问题就是,怎么把网页变得好看点: addStudent/listStudent页面都有改动 其中 list页面还有了<c:if 的语句这是还没练习过得知 ...

  7. 05-Java中的String类

    程序设计思路: 首先目标是使输入的字符串加上某个数变成另一个字符串,从而相当于对字符串进行加密. 第一步输入一个字符串String类型: 第二步把这个字符串转变成字符数组: 第三步让这个数组的每一个字 ...

  8. 简单的通用TreeView(WPF)

    工作中要为很多类创建TreeView, 很多时候仅仅是因为要显示字段不同, 就得Ctrl+C.Ctrl+V复制一份几乎相同的代码, 这难免让人生厌, 于是希望像泛型集合的扩展方法那样, 可以在使用的时 ...

  9. Merge Intervals 运行比较快

    class Solution { public: static bool cmp(Interval &a,Interval &b) { return a.start<b.star ...

  10. mysql中的where和having子句的区别

    mysql中的where和having子句的区别 having的用法 having字句可以让我们筛选成组后的各种数据,where字句在聚合前先筛选记录,也就是说作用在group by和having字句 ...