📄 flashread.vhd
字号:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
ENTITY flashread IS
generic (databyteshu: integer :=4);----需要保存数据字节数
PORT (clkin : IN std_logic;
dataram: out std_logic_vector(7 downto 0);
tongzhi: out std_logic:='1';
clkout: out BIT ;
flashread:in bit;
datainout: inout std_logic;
ramwrite:out bit; ----------RAM写使能
addrram: out integer range 0 to 9 );
END flashread;
----------------------------------------------------------
ARCHITECTURE flashread OF flashread IS
SIGNAL temp_flashread :bit;
BEGIN
------------产生相位差四分之一周期的时钟----------
PROCESS(clkin)
VARIABLE read:bit:='0';
VARIABLE temp1: INTEGER RANGE 0 TO 3:=0;-----产生flash周期及
VARIABLE temp2: INTEGER :=0; -------整个计数
VARIABLE temp4: INTEGER :=0; -----标记写到了哪个字节
VARIABLE temp5: INTEGER ;-------
VARIABLE temp6: INTEGER :=0; ---------标志字节位
VARIABLE ramtemp: std_logic_vector(7 downto 0);----临时把要存入RAM的数据储存
BEGIN
---------------------------检验写信号-------------------------
-------------------------------------------------------------
if rising_edge(clkin) then
temp_flashread<=flashread;
end if;
if(clkin'EVENT AND clkin='1') THEN
temp1:=temp1+1;
temp2:=temp2+1;
if(flashread='1' and temp_flashread='0')then
tongzhi<='0';
read:='1';
temp2:=0;
temp1:=0;
temp4:=0;
temp6:=0;
ramwrite<='1';
-- temp2:=temp2+1;
--else temp2
end if;
IF (temp1=1) THEN
clkout<= '1' and read;
elsif (temp1=2)then
clkout<= '1' and read;
elsif (temp1=3)then
clkout<='0';
else
clkout<='0';
temp1:=0;
END IF;
if temp2<161 then
case temp2 is
when 5 => datainout<= '1';
when 14 => datainout<= '0';
-------------------------------------------------
when 16 => datainout<= '1';-----此时对应时钟低电平中点
when 20 => datainout<= '0';
when 24 => datainout<= '1';
when 28 => datainout<= '0';
----------------------------------------------------
when 32 => datainout<= '0';
when 36 => datainout<= '0';
when 40 => datainout<= '0';
-------------------------------------------------------------
when 44 => datainout<= '0'; ---写命令
--------------------------地址字节(高位)----------------------------
when 48 => datainout<= 'Z';
when 52 => datainout<= '0';
when 56 => datainout<= '0';
when 60 => datainout<= '0';
when 64 => datainout<= '0';
when 68 => datainout<= '0';
when 72 => datainout<= '0';
when 76 => datainout<= '0';
when 80 => datainout<= '0';
--------------------------地址字节(低位)----------------------------
when 84 => datainout<= 'Z';
when 88 => datainout<= '0';
when 92 => datainout<= '0';
when 96 => datainout<= '0';
when 100 => datainout<= '0';
when 104 => datainout<= '0';
when 108 => datainout<= '0';
when 112 => datainout<= '0';
when 116 => datainout<= '1';
----------------------------------------------------
when 120 => datainout<= 'Z';
when 124 => datainout<= '1';
when 126 => datainout<= '0';
-------------------------------------------------
when 128 => datainout<= '1';
when 132 => datainout<= '0';
when 136 => datainout<= '1';
when 140 => datainout<= '0';
----------------------------------------------------
when 144 => datainout<= '0';
when 148 => datainout<= '0';
when 152 => datainout<= '0';
-------------------------------------------------------------
when 156 => datainout<= '1'; ---读命令
when 160 => datainout<= 'Z';
temp5:=165;
when others => null;
end case;
end if;
-----------------------------读取数据字节------------------------
---------------------------------------------------------------------------
if(temp2=temp5)then
ramtemp(temp6):=datainout;
temp6:=temp6+1;
temp5:=temp5+4;
end if;
if temp6>7 then
temp6:=0;
temp5:=166+temp4*36+36;
temp4:=temp4+1;
end if;
if temp2>192 then
if(temp2=156+temp4*36+1+4)then
addrram<=temp4;-----------------第一次到此temp4=1;
end if;
if(temp2=156+temp4*36+2+4)then
dataram<=ramtemp;
end if;
------------------------------------------------------------------
if(temp2=156+temp4*36+4)then
if temp4=databyteshu+1 then
temp4:=0;
temp5:=166;
else
datainout<='0'; ----------ACK信号
end if;
end if;
------------------------------------------释放主线-------------------------------------------
if(temp2=156+temp4*36+8)then
datainout<='Z'; --- 释放主线
end if;
end if;
if temp2=156+databyteshu*36+4 then
datainout<='1'; ---------------------最后一字节不应答
end if;
------------------------停止信号产生--------------
if temp2=156+databyteshu*36+8 then
datainout<='0';
end if;
if temp2=156+databyteshu*36+10 then
datainout<='1';
ramwrite<='0';
tongzhi<='1';
end if;
----------------------------读结束后释放总线关闭时钟--------------
if temp2=156+databyteshu*36+12 then
datainout<='Z';
tongzhi<='0';
read:='0';-----------------此后时钟始终为零注意复用
end if;
----------------------------------------------------------------
END IF;
END PROCESS;
END flashread;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -