title: VHDL-controling LCD screen ALTERA DE 2
body: <p>heloo I am currently working on ALTERA DE2 board . I want to use the LCD screen . I manged to turn it on . In this code the lcd_bus is the output of the lcd  for exmaple if the code for number one is : "0100110001"
   so if I write in the code :
  WHEN 1 => lcd_bus &lt;= "0100110001" then I will see output lcd_bus = 0100110001 . here is the code for this exmaple : </p>
  
  <pre><code>LIBRARY ieee;
   USE ieee.std_logic_1164.ALL;
   USE IEEE.STD_LOGIC_ARITH.ALL;
   USE IEEE.STD_LOGIC_UNSIGNED.ALL;
  
   ENTITY lcd_user_logic IS
  
  
                          GENERIC (display_resolution : INTEGER :=23;   -- counter to get to the lowest ferquncy 
                                      display_counter: INTEGER :=8);      -- counter to get to 97KHz ferquincy 
  
   PORT(
  
  
  
          lcd_bus_ones : IN STD_LOGIC_VECTOR(9 DOWNTO 0);
  
  
  
  
   --COUNTER_VECTOR :IN  STD_LOGIC_VECTOR(display_counter downto 0);
   lcd_busy : IN STD_LOGIC; --lcd controller busy/idle feedback
   clk : IN STD_LOGIC; --system clock
   lcd_clk : OUT STD_LOGIC;
   reset_n : OUT STD_LOGIC;
   lcd_enable : buffer STD_LOGIC; --lcd enable received from lcd controller
   lcd_bus : BUFFER STD_LOGIC_VECTOR(9 DOWNTO 0)); --data andcontrol signals
   --The MSB is the rs signal, followed by the rw signal.
   -- The other 8 bits are the data bits.
   END lcd_user_logic;
  
   ARCHITECTURE behavior OF lcd_user_logic IS
  
  
  signal lcd_bus_ones_signal :  STD_LOGIC_VECTOR(display_counter+1 downto 0);
  
  
  
   BEGIN
  
   lcd_bus_ones_signal&lt;=lcd_bus_ones;
  
  
  
  
  
   PROCESS(clk,lcd_bus_ones,lcd_bus_ones_signal)
   VARIABLE char : INTEGER RANGE 0 TO 12 := 0;
          BEGIN
  
                  IF(clk'EVENT AND clk = '1') THEN
  
                      IF(lcd_busy = '0' AND lcd_enable = '0') THEN
                      --  lcd_bus &lt;=  lcd_bus_ones;   
                              lcd_enable &lt;= '1';
                                  IF(char &lt; 12) THEN
                                          char := char + 1;
                  END IF;
   CASE char IS
  
  
  
                      ---------------------------------------------------------------------------this is the test 
  
                    WHEN 1 =&gt; lcd_bus &lt;="1000110001";
  
  
  
  
  
   WHEN OTHERS =&gt; lcd_enable &lt;= '0';
   END CASE;
   ELSE
   lcd_enable &lt;= '0';
   END IF;
   END IF;
   END PROCESS;
  
  
  
  
  
   reset_n &lt;= '1';
   lcd_clk &lt;= clk;
  
  
  
   END behavior;
  </code></pre>
  
  <p>and the output will be indeed  lcd_bus &lt;="1000110001" </p>
  
  <p><a href="https://i.stack.imgur.com/xfV0J.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xfV0J.png" alt="enter image description here"></a></p>
  
  <p>how ever if for exmaple I want to enter a value to lcd_bus like this , lcd_bus &lt;=lcd_bus_ones then I get lcd_bus = "0000000000" 
  and the code looks like this :</p>
  
  <pre><code>LIBRARY ieee;
   USE ieee.std_logic_1164.ALL;
   USE IEEE.STD_LOGIC_ARITH.ALL;
   USE IEEE.STD_LOGIC_UNSIGNED.ALL;
  
   ENTITY lcd_user_logic IS
  
  
                          GENERIC (display_resolution : INTEGER :=23;   -- counter to get to the lowest ferquncy 
                                      display_counter: INTEGER :=8);      -- counter to get to 97KHz ferquincy 
  
   PORT(
  
  
  
          lcd_bus_ones : IN STD_LOGIC_VECTOR(9 DOWNTO 0);
  
  
  
  
   --COUNTER_VECTOR :IN  STD_LOGIC_VECTOR(display_counter downto 0);
   lcd_busy : IN STD_LOGIC; --lcd controller busy/idle feedback
   clk : IN STD_LOGIC; --system clock
   lcd_clk : OUT STD_LOGIC;
   reset_n : OUT STD_LOGIC;
   lcd_enable : buffer STD_LOGIC; --lcd enable received from lcd controller
   lcd_bus : BUFFER STD_LOGIC_VECTOR(9 DOWNTO 0)); --data andcontrol signals
   --The MSB is the rs signal, followed by the rw signal.
   -- The other 8 bits are the data bits.
   END lcd_user_logic;
  
   ARCHITECTURE behavior OF lcd_user_logic IS
  
  
  signal lcd_bus_ones_signal :  STD_LOGIC_VECTOR(display_counter+1 downto 0);
  
  
  
   BEGIN
  
   lcd_bus_ones_signal&lt;=lcd_bus_ones;
  
  
  
  
  
  
  
  
  
  
  
  
   PROCESS(clk,lcd_bus_ones,lcd_bus_ones_signal)
   VARIABLE char : INTEGER RANGE 0 TO 12 := 0;
          BEGIN
  
                  IF(clk'EVENT AND clk = '1') THEN
  
                      IF(lcd_busy = '0' AND lcd_enable = '0') THEN
                      --  lcd_bus &lt;=  lcd_bus_ones;   
                              lcd_enable &lt;= '1';
                                  IF(char &lt; 12) THEN
                                          char := char + 1;
                  END IF;
   CASE char IS
  
  
  
                      ---------------------------------------------------------------------------this is the test 
  
                    WHEN 1 =&gt; lcd_bus &lt;=lcd_bus_ones;
  
  
  
  
  
  
   WHEN OTHERS =&gt; lcd_enable &lt;= '0';
   END CASE;
   ELSE
   lcd_enable &lt;= '0';
   END IF;
   END IF;
   END PROCESS;
  
  
  
  
  
  
  
   reset_n &lt;= '1';
   lcd_clk &lt;= clk;
  
  
  
   END behavior;
  </code></pre>
  
  <p>so the out put will look like this </p>
  
  <p><a href="https://i.stack.imgur.com/2ZNWP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2ZNWP.png" alt="enter image description here"></a></p>
  
  <p>the problem is with this statment :<br>
  IF(lcd_busy = '0' AND lcd_enable = '0') THEN</p>
  
  <p>any one have idea how to fix this problem |? </p>