⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 receive.txt

📁 有用的单片机程序,包括8279和E2ROM的读写
💻 TXT
字号:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
--5位数字信号的接收和发送模块,异步串行通信
--校验码为偶校验

--接收端处理程序
entity receive is
    Port ( clk : in std_logic;  --通讯同步时钟
           re : in std_logic;	  --串行接收
           output : out std_logic_vector(4 downto 0);	--检验到接收正确数据后并行输出
           alm : out std_logic);   --检验到接收错误数据后报警
end receive;

architecture Behavioral of receive is
begin
process(clk) is
variable idle:std_logic:='0';	 --空闲位:‘0’为空闲字符;‘1’为正在处理接受数据标志
variable cnt: integer range 0 to 6;  --计数时钟:
variable shift:std_logic_vector(5 downto 0);	--串、并转换:除启示位还剩5位数据位和一位校验位
 begin
 if rising_edge(clk) then
   if idle='0' then	 --系统处于空闲状态时允许接收
     if re='0' then	 --启示开始接收位收到
	  idle:='1'; --接收到后置系统为忙状态
	  alm<='0';  
	end if;
   else 
     if cnt<6 then
	  shift:=shift(4 downto 0) & re;
	  cnt:=cnt+1;
	else cnt:=0; idle:='0';
	  if(shift(0) xor shift(1) xor shift(2) xor shift(3) xor shift(4) xor shift(5))='0' then
	    output<=shift(5  downto 1);
	  else
	    alm<='1';
	  end if;
	end if;
   end if;
 end if;  	            
end process;
end Behavioral;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -