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

📄 ads7846.vhd

📁 四线电阻式触摸屏
💻 VHD
字号:
--dclk,cs,din测试正确(其中写控制字需要一个时钟周期)
--未考虑触摸抖动和连击问题
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_ARITH.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY ADS7846 IS
PORT(
     penirq,dout,busy,clk2mhz:IN STD_LOGIC;--busy引脚未用到(busy:忙低,不工作高阻态,写完控制字后一个时钟周期为高)
     din,dclk:OUT STD_LOGIC;
     cs:buffer STD_LOGIC;
     xdout,ydout:OUT STD_LOGIC_VECTOR(11 DOWNTO 0));
END ADS7846;

architecture behavioral of ads7846 is
type states is(reset,control,write_bit,read_bit);--注:写控制字占一个时钟周期(control)
signal state:states:=reset;
signal flag:std_logic:='0';
signal write_cnt:integer range 0 to 7:=0;
signal read_cnt:integer range 0 to 15:=0;
signal dataoutx,dataouty:std_logic_vector(11 downto 0):=(others=>'0');
signal write_control:std_logic_vector(7 downto 0):=(others=>'0');
begin

process(cs)
begin
if cs='0'then dclk<=clk2mhz;
else dclk<='0';
end if;
end process;

process(clk2mhz,state,penirq)
begin 
  if rising_edge(clk2mhz)then 
    case state is
      when reset=>if penirq/='0'then cs<='1';state<=reset;
                   else state<=control;
                   end if;                  
      when control=>if flag='0'then write_control<="10010000";--ox90
                   else write_control<="11010000";--oxd0
                   end if;
                   cs<='0';state<=write_bit;
      when write_bit=>case write_cnt is
                       when 0 to 3=>if write_control(7-write_cnt)='1'then din<='1';
                                    else din<='0';
                                    end if;
                                    write_cnt<=write_cnt+1;
                       when 4 to 6=>din<='0';write_cnt<=write_cnt+1;
					   when 7=>din<='0';write_cnt<=0;state<=read_bit;
					   end case;
	  when read_bit=>case read_cnt is
                       when 0 =>read_cnt<=read_cnt+1;
                       when 1 to 12=>if flag='0'then dataoutx(12-read_cnt)<=dout;read_cnt<=read_cnt+1;
                                     else dataouty(12-read_cnt)<=dout;read_cnt<=read_cnt+1;
                                     end if;
                       when 13 to 14=>read_cnt<=read_cnt+1;
                       when 15=>if flag='0'then state<=control;flag<='1';
                                else state<=reset;flag<='0';
                                end if;
                                read_cnt<=0;                    
                     end case;
end case;
end if;
xdout<=dataoutx;
ydout<=dataouty;
end process;
end;

 

⌨️ 快捷键说明

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