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还是得从数电的思路思考,设置一个预置使能端,预 ...
随机推荐
- [delphi]运行cmd命令,并取得输出字符
http://blog.csdn.net/nerdy/article/details/8969189 [delphi]运行cmd命令,并取得输出字符 标签: delphiCMD命令 2013-05- ...
- python之路-Day8
抽象接口 class Alert(object): '''报警基类''' def send(self): raise NotImplementedError class MailAlert(Alert ...
- (转)UIWebView全部API学习
网上找的收藏一下 http://www.myexception.cn/web/1888974.html 最生僻的API做了下划线以及粗体的标注.百度上查了全是拷贝的同一份代码,而且只有代码没有解释,很 ...
- asp.net Ajax和web services
新建一个web服务 using System; using System.Collections.Generic; using System.Linq; using System.Web; using ...
- 史航416第九次作业&总结
一.知识点总结: 1.二维数组定义的形式:类型名 数组名[行长度] [列长度] 例如:int a[3][2]:定义一个二维数组a,3行2列,6个元素: 2.二维数组引用的形式:类型名 数组名[行下标] ...
- javascript 伪协议
[javascript 伪协议] 将javascript代码添加到客户端的方法是把它放置在伪协议说明符javascript:后的URL中.这个特殊的协议类型声明了URL的主体是任意的javascrip ...
- What is “:-!!” in C code?
stackoverflow上看到的这个问题,觉得挺有趣,顺手记下来. 楼主提问: I bumped into this strange macro code in /usr/include/linux ...
- debug命令简介
debug命令不区分大小,debug的命令都是一个字母,后跟或不跟参数 1.debug [路径\文件] [参数] [参数]--[参数] debug相应程序 2. D(Dump) [地址] [范围] 显 ...
- 统计黑ip的脚本
#!/bin/bash > ] do cd /var/openresty/nginx/logs#统计nginx日志,将结果重定向到文件blackip.txt中 cat access.log|gr ...
- NGUI 屏幕自适应大屏与小屏(初始设定宽高为1280x720,能适应比其小或者更大的屏)
具体细节可以参考另外一篇随笔! 以下提供的算法完成的事: 1.自适应1280x720分辨率以下的屏幕 2.自适应1280x720分辨率以上的屏幕 在我设定的要求内包括的分辨率大部分都测过了,背景图.全 ...