我正在尝试实现 Spartan 3AN 的 LCD 的初始化。我对此很陌生,所以非常欢迎每一个建议。
我的代码如下:
----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 17:31:49 11/04/2011
-- Design Name:
-- Module Name: LCD - Behavioral
-- Project Name:
-- Target Devices:
-- Tool versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
--use IEEE.STD_LOGIC_ARITH.ALL;
--use IEEE.STD_LOGIC_UNSIGNED.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity LCD is
Port ( clk : in STD_LOGIC;
LCD_DB : out STD_LOGIC_VECTOR (7 downto 0);
LCD_E : out STD_LOGIC;
LCD_RS : out STD_LOGIC;
LCD_RW : out STD_LOGIC);
end LCD;
architecture Behavioral of LCD is
-- CAUTION!!! When using 4-bit mode, FPGA must drive the LCD_DB<3:0> signals HIGH ( = '1' )
-- MAQUINA DE ESTADOS INICIALIZACION
type initialization_state is (A, B, C, D, E, F, G, H, I, done);
signal iCurrentState: initialization_state := A;
signal iNextState: initialization_state := A;
signal cycleCounter: integer := 0;
-- MAQUINA DE ESTADOS
begin
initializationLCD:
process (clk) begin
if (clk'event and clk = '1') then
case iCurrentState is
when A =>
if (cycleCounter = 750000) then
iCurrentState <= B;
cycleCounter <= 0;
else
cycleCounter <= cycleCounter + 1;
end if;
when B =>
LCD_RS <= '1';
LCD_RW <= '0';
LCD_DB <= "00000001";
if (cycleCounter = 50000) then
iCurrentState <= C;
cycleCounter <= 0;
else
cycleCounter <= cycleCounter + 1;
end if;
when C =>
if (cycleCounter = 50000) then
iCurrentState <= D;
cycleCounter <= 0;
else
cycleCounter <= cycleCounter + 1;
end if;
when D =>
LCD_RS <= '1';
LCD_RW <= '0';
LCD_DB <= "00000010";
if (cycleCounter = 50000) then
iCurrentState <= E;
cycleCounter <= 0;
else
cycleCounter <= cycleCounter + 1;
end if;
when E =>
if (cycleCounter = 50000) then
iCurrentState <= F;
cycleCounter <= 0;
else
cycleCounter <= cycleCounter + 1;
end if;
when F =>
LCD_RS <= '1';
LCD_RW <= '0';
LCD_DB <= "00000100";
if (cycleCounter = 12) then
iCurrentState <= G;
cycleCounter <= 0;
else
cycleCounter <= cycleCounter + 1;
end if;
when G =>
if (cycleCounter = 50000) then
iCurrentState <= H;
cycleCounter <= 0;
else
cycleCounter <= cycleCounter + 1;
end if;
when H =>
LCD_RS <= '1';
LCD_RW <= '0';
LCD_DB <= "00001000";
if (cycleCounter = 12) then
iCurrentState <= I;
cycleCounter <= 0;
else
cycleCounter <= cycleCounter + 1;
end if;
when I =>
if (cycleCounter = 50000) then
iCurrentState <= done;
cycleCounter <= 0;
else
cycleCounter <= cycleCounter + 1;
end if;
when others =>
iCurrentState <= done;
end case;
end if;
end process;
end Behavioral;
所以有2个问题:
这段代码好吗?我知道我还有很多代码要做,但我只是想看看我是否做得很好,是什么让我提出问题 2
我用 ISim 进行了模拟(顺便说一句,我在 Xilinx 12.3 上)并且状态永远不会改变总是 A,我的代码是否遗漏了什么?或者我模拟的方式不对,你能告诉我如何模拟吗?
非常感谢 !