I2C VHDL程序
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程序的更多相关文章
- VHDL程序的库
VHDL库存储和放置了可被其他VHDL程序调用的数据定义.器件说明.程序包等资源.VHDL库的种类有很多,但最常见的库有IEEE标准库.WORK库.IEEE标准库主要包括STD_LOGIC_1164. ...
- 毕业设计预习:VHDL入门知识学习(一) VHDL程序基本结构
VHDL入门知识学习(一) VHDL程序基本结构 简介 VHDL程序基本结构 简介 概念: HDL-Hardware Description Language-硬件描述语言-描述硬件电路的功能.信号连 ...
- 基于BASYS2的VHDL程序——交通灯
请尊重作者版权,转载请注明原地址: http://www.cnblogs.com/connorzx/p/3676746.html 数电实验交通灯VHDL版,程序写的扩展性很差,待以后有时间进行优化. ...
- 基于BASYS2的VHDL程序与仿真——50%占空比8分频器
转帖请注明转自http://www.cnblogs.com/connorzx/p/3547673.html 一.新建工程 1.点击File->New Project, 2.点击Next 注:此处 ...
- Linux i2c 读写程序
/* This software uses a BSD license. Copyright (c) 2010, Sean Cross / chumby industriesAll rights re ...
- 基于BASYS2的VHDL程序——分频和数码管静态显示程序
转载请注明出处:http://www.cnblogs.com/connorzx/p/3633860.html 分频是基于计数器程序.由于FPGA的并行处理能力,根本不需要单片机式的中断指令,用起来很方 ...
- 基于BASYS2的VHDL程序与烧写——按键消抖程序
请尊重作者版权,转载请注明源地址http://www.cnblogs.com/connorzx/p/3548364.html 按键在按下的过程中通常会产生一段时间的抖动,为了消除这种抖动,一般采取两种 ...
- 基于BASYS2的VHDL程序——交通灯(状态机版)
请尊重作者版权,转载注明源地址:http://www.cnblogs.com/connorzx/p/3694618.html 使用了状态机,增加了可读性和用户体验. library IEEE; use ...
- 基于BASYS2的VHDL程序——数字钟(最终版)
转载请注明原地址:http://www.cnblogs.com/connorzx/p/3674178.html 调时电路正常工作.一切正常.发现做FPGA还是得从数电的思路思考,设置一个预置使能端,预 ...
随机推荐
- robot framework 安装配置
robot framework 是一款专门用作自动化测试的框架,提供了丰富的内置库,与第三方库,也支持用户自己编写的库,robot framework +library 可以 用来做ui的自动化测试, ...
- Sql 触发器禁用和启用
--启用or禁用指定表所有外键约束 alter table tbname NOCHECK constraint all alter table tbname CHECK constraint all ...
- svn命令
1.检出.更新.提交 svn chectout http://svn_server/xxx_repository/trunk svn update svn commit -m "XXX&qu ...
- Function类型
1.每个函数都是Function类型的,和其他引用类型一样都具有属性和方法.函数也是对象,因此函数实际上是一个指向函数对象的指针. 函数声明语法定义: 方法1: function sum(num1,n ...
- 处理sevenzipsharp 检查密码函数的Bug
using (SevenZipExtractor extr = new SevenZipExtractor(tbPackagePath.Text, "www.pc6.com")) ...
- Newtonsoft.Json解析Json字符串案例:
/// <summary> /// 上行jsom格式日志记录 /// </summary> /// <param name="responseJson" ...
- Retrofit源码分析(一)
1.基本用法 创建接口 public interface GitHubService { @GET("users/{user}/repos") Observable<List ...
- mysql-5.7.14 源码安装笔记
安装编译 下载源码 mysql-5.7.14.tar.gz 解压定义安装变量 cd /usr/local/src mysql_version="mysql-5.7.14" tar ...
- Java 验证码、二维码
Java 验证码.二维码 资源 需要: jelly-core-1.7.0.GA.jar网站: http://lychie.github.io/products.html将下载下来的 jelly ...
- Git远程操作
Git远程操作 // */ // ]]> Git远程操作 Table of Contents 1 Git远程命令概览 2 Git远程仓库与本地仓库的关系图 3 git clone 4 git ...