Advertisement
Guest User

Untitled

a guest
Jan 14th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.29 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. use IEEE.STD_LOGIC_ARITH.ALL;
  4. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  5.  
  6. entity FSM_String is
  7.     Port ( Clk : in  STD_LOGIC;
  8.            Reset : in  STD_LOGIC;
  9.            LCD_Busy : in  STD_LOGIC;
  10.            LCD_WE : out  STD_LOGIC;
  11.            LCD_DnI : out  STD_LOGIC;
  12.            LCD_DI : out  STD_LOGIC_VECTOR (7 downto 0));
  13. end FSM_String;
  14.  
  15. architecture RTL of FSM_String is
  16.  
  17.   -- FSM
  18.   type state_type is (
  19.     sReset,
  20.     sBusyWait,
  21.     sWE,
  22.     sLoop
  23.     );
  24.   signal State, nextState : state_type;
  25.  
  26.   -- String to print
  27.   type t_data is array (natural range <>) of std_logic_vector(7 downto 0);
  28.  
  29.   type t_sel is array (natural range <>) of std_logic;
  30.  
  31.  
  32.   constant data_size : POSITIVE := 6;
  33.   constant data : t_data ( 0 to data_size - 1 ) := ( x"45", x"41",  x"42", x"C1",  x"43",  x"34");
  34.   constant sel  : t_sel ( 0 to data_size - 1 )  := (   '0',   '1',    '1',   '0',    '1',    '1');
  35.  
  36.   -- Character index
  37.   signal cntIdx : integer range 0 to data_size ;
  38.  
  39. begin
  40.    
  41.   -- Character index
  42.   process ( Clk )
  43.   begin
  44.     if rising_edge( Clk ) then
  45.       if State = sReset then
  46.         cntIdx <= 0;
  47.       elsif State = sWE then
  48.         cntIdx <= cntIdx + 1;
  49.       end if;
  50.     end if;
  51.   end process;
  52.  
  53.   -- FSM
  54.     process ( Clk )
  55.   begin
  56.     if rising_edge( Clk ) then
  57.       if Reset = '1' then
  58.         State <= sReset;
  59.       else
  60.         State <= nextState;
  61.       end if;
  62.     end if;
  63.   end process;
  64.     process( State, LCD_Busy, cntIdx)
  65.   begin
  66.     nextState <= State;   -- default is to stay in current State
  67.    
  68.     case State is
  69.  
  70.       when sReset =>
  71.         nextState <= sBusyWait;
  72.  
  73.       when sBusyWait =>
  74.         if LCD_Busy = '0' then
  75.           nextState <= sWE;
  76.         end if;
  77.  
  78.       when sWE =>   -- WE pulse
  79.         nextState <= sLoop;
  80.  
  81.       when sLoop =>
  82.         if cntIdx /= data_size then
  83.           nextState <= sBusyWait;
  84.         end if;   -- else null; => stay in sLoop till Reset
  85.      
  86.     end case;
  87.   end process;
  88.  
  89.  
  90.   LCD_WE  <= '1' when State = sWE else '0';
  91.   -- Outputs
  92.  
  93.   process (Clk)
  94.  
  95.    begin
  96.  
  97.       if sel(cntIdx) = '0' then
  98.  
  99.       LCD_DnI <= '0';
  100.  
  101.       else
  102.  
  103.       LCD_DnI <= '1';
  104.  
  105.       end if;
  106.  
  107.      
  108.  
  109.       LCD_DI <= data(cntIdx);
  110.    end process;
  111.  
  112.    
  113. end RTL;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement