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

📄 all.vhd

📁 本程序是用VHDL语言实现异步通信控制器
💻 VHD
字号:
LIBRARY ieee; 
USE ieee.std_logic_1164.all;
USE ieee.std_logic_unsigned.all;
entity asynchronous is
	port(reset,TXC,RXC,RXD:IN STD_LOGIC;
			CS,A0,RD,WR:IN STD_LOGIC;
			TXD:OUT STD_LOGIC;
			D:INOUT STD_LOGIC_VECTOR(7 DOWNTO 0));
END;
ARCHITECTURE behavior of asynchronous is
signal FE,PE,OVERFLOW,RBF,TBE:STD_LOGIC;
signal	ERXE,ETBE,ERBF:STD_LOGIC;
signal LDRB,RXEN,W_r:STD_LOGIC;

signal clk:std_logic;
signal count1:integer range 0 to 9;
signal count2:integer range 0 to 22;
signal temp:std_logic_vector(9 downto 0);

signal data:STD_LOGIC_VECTOR(7 DOWNTO 0);
signal RX_buf:STD_LOGIC_VECTOR(7 DOWNTO 0) :="00000000";
begin
p1:process(reset,CS,A0,RD,WR)	--chip select
  begin	
	if(reset='0')then
		FE<='0';OVERFLOW<='0';PE<='0';RBF<='0';TBE<='1';
		W_r<='0';D<="ZZZZZZZZ";--RX_buf<=D;
	else
		if(CS='1')THEN	D<="ZZZZZZZZ";W_r<='0';
		elsif(cs='0'and A0='0'and RD='0'and WR='1')then
			W_r<='0';D<=RX_buf;
			FE<='0';OVERFLOW<='0';PE<='0';
		elsif(cs='0'and A0='0'and RD='1'and WR='0')then
			W_r<='1';
			if(LDRB='1')THEN	RX_buf<=D;D<="ZZZZZZZZ";
			end if;
		elsif(cs='0'and A0='1'and RD='0'and WR='1')then
			W_r<='0';
			D<="000"&FE&OVERFLOW&PE&TBE&RBF;
			FE<='0';OVERFLOW<='0';PE<='0';
		elsif(cs='0'and A0='1'and RD='1'and WR='0')then
			w_r<='1';
			if(LDRB='1')THEN	ERXE<=D(2);ETBE<=D(1);ERBF<=D(0);D<="ZZZZZZZZ";end if;
		--else w_r<='0';D<="ZZZZZZZZ";
		end if;
	end if;
end process p1;
p2:process(TXC,reset)	--send data
  begin
	if(txc'event and txc='1')then
		if(reset='1' and w_r='0')then
			if(count2=22)then
				count2<=0;clk<=not clk;
			else
				count2<=count2+1;
	end if;end if;end if;
end process p1;
p3:process(clk)
  begin
	if(reset='0' or w_r='1')then	count1<=9;
	else
		if(clk'event and clk='1')then
			if(count1=9)then	count1<=0;
			else	count1<=count1+1;
	end if;end if;end if;
end process p2;
p4:process(clk)
  begin
	if(reset='0' or w_r='1')then	temp(9)<='1';TBE<='1';
	else
		if(clk'event and clk='1')then
			if(count1=0)then
				temp(9 downto 0)<=('0'&d_in(3 downto 0)&d_in(7 downto 4)&'1');
				TBE<='0';
			else	
				if(count1=9)then	TBE<='1';temp(9)<='1'; --downto 1)<=temp(8 downto 0);
				else	temp(9 downto 1)<=temp(8 downto 0);
			end if;end if;
		end if;
	end if;
END PROCESS;
TXD<=temp(9);


	
end;

⌨️ 快捷键说明

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