LCD12864 coding problem

Discussion in 'Programmer's Corner' started by pruzr, May 9, 2008.

  1. pruzr

    Thread Starter New Member

    Mar 13, 2008
    3
    0
    I have found that I can't display a 8 bit on the lcd, I have tried it for a full day and I can't find any solution, can someone know what error in the code?
    thank you very much


    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 instantiating
    ---- any Xilinx primitives in this code.
    --library UNISIM;
    --use UNISIM.VComponents.all;

    entity LCD is

    port( clk:in std_logic;
    RST:in std_logic;
    Tick : in std_logic; -- Tick at 250 kHz (one clock cycle long)
    Din : in std_logic_vector (7 downto 0);
    Dav : in std_logic; -- Write Data command (1 clock cycle) if Dav=1 , then write data
    Busy : out std_logic;
    x : in std_logic_vector (7 downto 0);
    y : in std_logic_vector (7 downto 0);
    cs : in std_logic; -- choose segment to display
    ---Lcd signals---------------------------------------
    RS:eek:ut std_logic; ---LCD R R_sel
    RW:eek:ut std_logic; ---LCD Read/Write
    E:eek:ut std_logic; ---Enable
    CS1: out std_logic;---LCD chip select 1
    CS2: out std_logic;---LCD Chip select 2
    Dout: inout std_logic_vector(7 downto 0) --- LCD data
    -----------------------------------------------------

    );

    end LCD;

    architecture Behavioral of LCD is
    -----type defination----
    --TYPE State_type IS ( w_Z_SCROLL, w_X_PAGE, W_Y_COL, W_DATA, W_INS,
    -- DISPLAY_ON, DISPLaY_OFF, SEGMENT1, SEGMENT2,IDLE) ;
    type State_type is (Boot, W_Z_SCROLL,W_Y_COL,W_X_PAGE,Display,Segment_Select,Waiting,WriteData);
    -----constant defination----

    constant DON : std_logic_vector(7 downto 0) := "00111111"; -- Display on
    constant DOFF : std_logic_vector(7 downto 0) := "00111110"; -- Display off
    constant Y_ADD : std_logic_vector(7 downto 0) := "01000000"; -- Set Y address 01xxxxxx, xxxxxx is 0-127
    constant X_ADD : std_logic_vector(7 downto 0) := "10111000"; -- Set X col 10111xxx, xxx is 0-7
    constant Z_ADD : std_logic_vector(7 downto 0) := "11000000"; -- set z address 11xxxxxx, xxxxxx is 0-127
    constant write : std_logic_vector(7 downto 0) := "00000000"; -- xxxxxxxx is the data want to write



    constant Big_delay : integer := 25000; -- 25000/250 = 100 ms
    constant Clr_delay : integer := 5000; -- 500/250= 2 ms
    constant Small_delay : integer := 120; -- > 39 us after E down
    constant En_delay : integer := 20;
    --constant LastPosition : integer := 16;

    -----signal defination------
    SIGNAL State : State_type;
    --SIGNAL Next_State : State_type;
    --SIGNAL Count : integer range 0 to Big_delay;
    --SIGNAL Count2 : std_logic_vector(7 downto 0);
    SIGNAL Z_SCROLL : std_logic_vector(7 downto 0);
    SIGNAL X_PAGE : std_logic_vector(7 downto 0);
    SIGNAL Y_COL : std_logic_vector(7 downto 0);
    SIGNAL DAT : std_logic_vector(7 downto 0);
    SIGNAL temp,temp2,INS : std_logic_vector(7 downto 0);
    SIGNAL active : std_logic;

    signal DavM : std_logic;
    signal DataM : std_logic_vector (7 downto 0);
    signal Position : integer range 0 to 32;
    signal Count : integer range 0 to Big_delay;

    ----------------------------
    begin

    --RW <= '0';-------- write mode
    process(clk,RST)
    begin
    if Rst = '1' then
    State <= Boot;
    Position <= 0;
    Count <= 0;
    DavM <= '0';
    --Lcd_En <= '0';
    --Lcd_Sel <= '1';
    Busy <= '1';
    RS <= '1';
    RW <= '0';
    E <= '0';
    CS1 <= '0';
    CS2 <= '0';
    Dout <= (others=>'0');

    elsif rising_edge(Clk) then

    if Dav = '1' then
    DavM <= '1';
    DataM <= Din;
    Busy <= '1';
    end if;

    if Tick = '1' then

    case State is

    when Boot => -- Power up wait 30 ms
    RS <= '1';
    E <= '0';
    Busy <= '1';
    if Count = Big_delay then
    RS <= '0';
    Count <= 0;
    State <= W_Z_SCROLL;
    else
    Count <= Count + 1;
    end if;


    when W_Z_SCROLL => -- Set Function & Mode
    Dout <= Z_ADD;
    RS <= '0';
    if Count = 1 then
    E <= '1';
    elsif Count = En_delay then
    E <= '0';
    end if;
    if Count = Small_delay then
    State <= W_Y_COL;
    Count <= 0;
    else
    Count <= Count+1;
    end if;


    when W_Y_COL => -- set Entry Mode,
    temp <= Y_ADD or y;
    Dout <= temp;
    RS <= '0';
    if Count = 1 then
    E <= '1';
    elsif Count = En_delay then
    E <= '0';
    end if;
    if Count = Small_delay then
    State <= W_X_PAGE;
    Count <= 0;
    else
    Count <= Count+1;
    end if;

    when W_X_PAGE => -- set Entry Mode,
    temp2 <= X_ADD or x;
    Dout <= temp2;
    RS <= '0';
    if Count = 1 then
    E <= '1';
    elsif Count = En_delay then
    E <= '0';
    end if;
    if Count = Small_delay then
    State <= Display;
    Count <= 0;
    else
    Count <= Count+1;
    end if;


    when Display => -- set Display ON
    Dout <= DON;
    RS <= '0';
    if Count = 1 then
    E <= '1';
    elsif Count = En_delay then
    E <= '0';
    end if;
    if Count = Small_delay then
    State <= Segment_Select;
    Count <= 0;
    else
    Count <= Count+1;
    end if;




    when Segment_Select => -- set Display ON

    if cs ='0' then ---- cs1 enable
    RS <='0';
    RW <='1';
    CS1 <='1';
    CS2 <='0';
    Dout <= "00000000";

    if Count = 1 then
    E <= '1';
    elsif Count = En_delay then
    E <= '0';
    end if;
    if Count = Small_delay then
    State <= Waiting;
    Count <= 0;
    else
    Count <= Count+1;
    end if;

    elsif cs ='1' then -----cs2 enalbe
    RS <='0';
    RW <='1';
    CS1 <='0';
    CS2 <='1';
    Dout <= "00000000";

    if Count = 1 then
    E <= '1';
    elsif Count = En_delay then
    E <= '0';
    end if;
    if Count = Small_delay then
    State <= Waiting;
    Count <= 0;
    else
    Count <= Count+1;
    end if;

    end if;



    when Waiting => -- Waits for input
    if DavM = '1' then
    DavM <= '0';
    State <= WriteData;
    RS <= '1';
    else
    Busy <= '0';
    end if;



    when WriteData =>
    RS <= '1';
    RW <= '0';
    Dout <= Din;
    if Count = 1 then
    E <= '1';
    elsif Count = En_delay then
    E <= '0';
    end if;
    if Count = Small_delay then
    Count <= 0;
    State <= WriteData;
    else
    Count <= Count + 1;
    end if;


    end case;
    end if;
    end if;
    end process;




    end Behavioral;
     
  2. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Seems to me that you need to re-send the "wake-up" code a few times (with 10mS waits between) to ensure that the display is actually ready to receive commands - that is, if your LCD's controller is a Hitachi 44780 controller.

    You need to determine what the actual controller of your LCD is. The HD44780 is quite popular, but you may have a different controller.

    I re-formatted your program using [ CODE] [ /CODE] tags.

    Code ( (Unknown Language)):
    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. ---- Uncomment the following library declaration if instantiating
    7. ---- any Xilinx primitives in this code.
    8. --library UNISIM;
    9. --use UNISIM.VComponents.all;
    10.  
    11. entity LCD is
    12.  
    13. port(       clk:in std_logic;
    14.             RST:in std_logic;
    15.             Tick : in std_logic;                      -- Tick at 250 kHz (one clock cycle long)
    16.             Din : in std_logic_vector (7 downto 0);
    17.             Dav  : in std_logic;                      -- Write Data command (1 clock cycle)  if Dav=1 , then write data
    18.             Busy : out std_logic;
    19.             x : in std_logic_vector (7 downto 0);
    20.             y : in std_logic_vector (7 downto 0);
    21.             cs : in std_logic; -- choose segment to display  
    22. ---Lcd signals---------------------------------------
    23.             RS:out std_logic; ---LCD R         R_sel
    24.             RW:out std_logic; ---LCD Read/Write
    25.             E:out std_logic; ---Enable
    26.               CS1: out std_logic;---LCD chip select 1
    27.             CS2: out std_logic;---LCD Chip select 2
    28.             Dout: inout std_logic_vector(7 downto 0) --- LCD data
    29. -----------------------------------------------------
    30.  
    31.     );
    32.  
    33. end LCD;
    34.  
    35. architecture Behavioral of LCD is
    36. -----type defination----
    37. --TYPE  State_type IS (  w_Z_SCROLL, w_X_PAGE, W_Y_COL, W_DATA, W_INS,
    38. --                         DISPLAY_ON, DISPLaY_OFF, SEGMENT1, SEGMENT2,IDLE) ;
    39. type State_type is (Boot, W_Z_SCROLL,W_Y_COL,W_X_PAGE,Display,Segment_Select  ,Waiting,WriteData);      
    40. -----constant defination----
    41.  
    42. constant DON   : std_logic_vector(7 downto 0) := "00111111"; -- Display on
    43. constant DOFF  : std_logic_vector(7 downto 0) := "00111110"; -- Display off
    44. constant Y_ADD : std_logic_vector(7 downto 0) := "01000000"; -- Set Y address   01xxxxxx, xxxxxx is 0-127
    45. constant X_ADD : std_logic_vector(7 downto 0) := "10111000"; -- Set X col 10111xxx, xxx is 0-7
    46. constant Z_ADD : std_logic_vector(7 downto 0) := "11000000"; -- set z address 11xxxxxx, xxxxxx is 0-127
    47. constant write : std_logic_vector(7 downto 0) := "00000000"; -- xxxxxxxx is the data want to write
    48.  
    49.  
    50.  
    51. constant Big_delay    : integer := 25000;  -- 25000/250 = 100 ms
    52. constant Clr_delay    : integer := 5000;   -- 500/250= 2 ms
    53. constant Small_delay  : integer := 120;    -- > 39 us after E down
    54. constant En_delay     : integer := 20;
    55. --constant LastPosition : integer := 16;
    56.  
    57. -----signal defination------
    58. SIGNAL   State   : State_type;
    59. --SIGNAL   Next_State   : State_type;
    60. --SIGNAL    Count    : integer range 0 to Big_delay;
    61. --SIGNAL   Count2   : std_logic_vector(7 downto 0);
    62. SIGNAL   Z_SCROLL : std_logic_vector(7 downto 0);
    63. SIGNAL   X_PAGE : std_logic_vector(7 downto 0);
    64. SIGNAL   Y_COL : std_logic_vector(7 downto 0);
    65. SIGNAL   DAT : std_logic_vector(7 downto 0);
    66. SIGNAL   temp,temp2,INS : std_logic_vector(7 downto 0);
    67. SIGNAL   active : std_logic;
    68.  
    69. signal DavM  : std_logic;
    70. signal DataM : std_logic_vector (7 downto 0);
    71. signal Position : integer range 0 to 32;
    72. signal Count    : integer range 0 to Big_delay;
    73.  
    74. ----------------------------
    75. begin
    76.  
    77. --RW <= '0';-------- write mode
    78.    process(clk,RST)
    79.    begin
    80.       if Rst = '1' then
    81.       State    <= Boot;
    82.       Position <= 0;
    83.       Count    <= 0;
    84.       DavM     <= '0';
    85.       --Lcd_En   <= '0';
    86.       --Lcd_Sel  <= '1';
    87.       Busy     <= '1';
    88.       RS         <= '1';
    89.       RW         <= '0';
    90.       E         <= '0';
    91.       CS1      <= '0';
    92.       CS2      <= '0';
    93.       Dout     <= (others=>'0');
    94.      
    95.     elsif rising_edge(Clk) then
    96.  
    97.       if Dav = '1' then
    98.         DavM  <= '1';
    99.         DataM <= Din;
    100.         Busy  <= '1';
    101.       end if;
    102.  
    103.       if Tick = '1' then
    104.      
    105.         case State is
    106.  
    107.           when Boot =>                  -- Power up wait 30 ms
    108.             RS  <= '1';
    109.             E   <= '0';
    110.             Busy <= '1';
    111.             if Count = Big_delay then
    112.               RS <= '0';
    113.               Count <= 0;
    114.               State <= W_Z_SCROLL;
    115.             else
    116.               Count <= Count + 1;
    117.             end if;
    118.  
    119.  
    120.          when W_Z_SCROLL =>               -- Set Function & Mode
    121.             Dout    <= Z_ADD;
    122.             RS        <= '0';
    123.             if Count = 1 then
    124.               E <= '1';
    125.             elsif Count = En_delay then
    126.               E <= '0';
    127.             end if;
    128.             if Count = Small_delay then
    129.               State <= W_Y_COL;
    130.               Count <= 0;
    131.             else
    132.               Count <= Count+1;
    133.             end if;
    134.  
    135.  
    136.           when W_Y_COL =>             -- set Entry Mode,
    137.              temp    <= Y_ADD or y;
    138.             Dout    <= temp;
    139.             RS        <= '0';
    140.             if Count = 1 then
    141.               E <= '1';
    142.             elsif Count = En_delay then
    143.               E <= '0';
    144.             end if;
    145.             if Count = Small_delay then
    146.               State <= W_X_PAGE;
    147.               Count <= 0;
    148.             else
    149.               Count <= Count+1;
    150.             end if;
    151.  
    152.          when W_X_PAGE =>             -- set Entry Mode,
    153.              temp2    <= X_ADD or x;
    154.             Dout    <= temp2;
    155.             RS        <= '0';
    156.             if Count = 1 then
    157.               E <= '1';
    158.             elsif Count = En_delay then
    159.               E <= '0';
    160.             end if;
    161.             if Count = Small_delay then
    162.               State <= Display;
    163.               Count <= 0;
    164.             else
    165.               Count <= Count+1;
    166.             end if;
    167.  
    168.  
    169.           when Display =>               -- set Display ON
    170.             Dout    <= DON;
    171.             RS       <= '0';
    172.             if Count = 1 then
    173.               E <= '1';
    174.             elsif Count = En_delay then
    175.               E <= '0';
    176.             end if;
    177.             if Count = Small_delay then
    178.               State <= Segment_Select;
    179.               Count <= 0;
    180.             else
    181.               Count <= Count+1;
    182.             end if;
    183.  
    184.  
    185.  
    186.  
    187.             when Segment_Select =>               -- set Display ON
    188.  
    189.             if cs ='0' then ---- cs1 enable
    190.             RS       <='0';
    191.             RW       <='1';
    192.             CS1      <='1';
    193.             CS2      <='0';
    194.             Dout       <= "00000000";
    195.            
    196.             if Count = 1 then
    197.               E <= '1';
    198.             elsif Count = En_delay then
    199.               E <= '0';
    200.             end if;
    201.             if Count = Small_delay then
    202.               State <= Waiting;
    203.               Count <= 0;
    204.             else
    205.               Count <= Count+1;
    206.             end if;
    207.  
    208.             elsif cs ='1' then -----cs2 enalbe
    209.             RS       <='0';
    210.             RW       <='1';
    211.             CS1      <='0';
    212.             CS2      <='1';
    213.             Dout       <= "00000000";
    214.            
    215.             if Count = 1 then
    216.               E <= '1';
    217.             elsif Count = En_delay then
    218.               E <= '0';
    219.             end if;
    220.             if Count = Small_delay then
    221.               State <= Waiting;
    222.               Count <= 0;
    223.             else
    224.               Count <= Count+1;
    225.             end if;
    226.            
    227.             end if;
    228.  
    229.  
    230.  
    231.           when Waiting =>               -- Waits for input
    232.             if DavM = '1' then
    233.               DavM    <= '0';
    234.               State   <= WriteData;
    235.               RS <= '1';
    236.             else
    237.               Busy <= '0';
    238.             end if;
    239.  
    240.    
    241.  
    242.           when WriteData =>              
    243.              RS <= '1';
    244.              RW <= '0';
    245.              Dout <= Din;
    246.             if Count = 1 then
    247.               E <= '1';
    248.             elsif Count = En_delay then
    249.               E <= '0';
    250.             end if;
    251.             if Count = Small_delay then
    252.               Count    <= 0;
    253.               State    <= WriteData;
    254.             else
    255.               Count <= Count + 1;
    256.             end if;
    257.  
    258.  
    259.         end case;
    260.       end if;
    261.     end if;
    262.   end process;
    263.  
    264.    
    265.    
    266.  
    267. end Behavioral;
     
  3. pruzr

    Thread Starter New Member

    Mar 13, 2008
    3
    0
    Thank you for your reply SgtWookie
    Is that the Wake up code is the RST pin in my LCD controller?


    GDM12864A
    Features
    ?? Display format: 128*64 dots matrix graphic
    ?? STN yellow-green mode
    ?? Easy interface with 8-bit MPU
    ?? Low power consumption
    ?? LED back-light
    ?? Viewing angle: 6 O’clock
    ?? Driving method : 1/64 duty , 1/6.7 bias
    ?? LCD driver IC: KS0108B(2 ? )? KS0107B
    ?? Connector: Zebra

    KS0108 Driver IC


    4. Reset
    The system can be initialized by setting RSTB terminal at low level when turning power on, receiving
    instruction from MPU. When RSTB becomes low, following procedure is occurred.
    1. Display off
    2. Display start line register become set by 0.(Z-address 0)
    While RSTB is low, No instruction except status read can by accepted. Therefore, execute other
    instructions after making sure that DB4= (clear RSTB) and DB7=0 (ready) by status read instruction.
    The conditions of power supply at initial power up are shown in table 1.
    Table 1. Power Supply Initial Conditions
    Item Symbol Min Typ Max Unit
    Reset Time tRS 1.0 - - us
    Rise Time tR - - 200 ns
     
Loading...