1 | LIBRARY IEEE;
|
2 | USE IEEE.STD_LOGIC_1164.ALL;
|
3 | USE IEEE.STD_LOGIC_UNSIGNED.ALL;
|
4 |
|
5 | ENTITY LCD_Main IS
|
6 | PORT ( clk : IN std_logic;
|
7 | iRST_N : IN std_logic;
|
8 | SW : IN std_logic_vector(17 downto 0);
|
9 | reset : IN std_logic;
|
10 | switch : IN std_logic;
|
11 | switch2 : IN std_logic;
|
12 |
|
13 | LCD_DATA : OUT std_logic_vector(7 downto 0);
|
14 | LCD_RW : OUT std_logic;
|
15 | LCD_ON : OUT std_logic;
|
16 | LCD_BLON : OUT std_logic;
|
17 | LCD_RS : OUT std_logic;
|
18 | LCD_EN : OUT std_logic:='0'
|
19 | );
|
20 | END LCD_Main;
|
21 |
|
22 | ARCHITECTURE LCDBody of LCD_Main is
|
23 |
|
24 | CONSTANT LCD_INITIAL:std_logic_vector(7 downto 0):="00000000";
|
25 | CONSTANT LCD_LINE1:std_logic_vector(7 downto 0):= "00000100";
|
26 | CONSTANT LCD_CH_LINE:std_logic_vector(7 downto 0):=LCD_LINE1+16;
|
27 | CONSTANT LCD_LINE2:std_logic_vector(7 downto 0):=LCD_LINE1+16+1;
|
28 | CONSTANT LUT_SIZE:std_logic_vector(7 downto 0):=(LCD_LINE2+50)+1;
|
29 |
|
30 | SIGNAL LUT_DATA:std_logic_vector (11 downto 0):=x"000";--In hex
|
31 | -- SIGNAL count2 : integer range 0 to 65535 := 0;
|
32 | SIGNAL LUT_INDEX:std_logic_vector(7 downto 0):="00000000";
|
33 | SIGNAL mLCD_DONE:std_logic:='0';
|
34 | -- SIGNAL mLCD_ST:std_logic_vector(5 downto 0):="000000";
|
35 | SIGNAL mLCD_ST:std_logic_vector(1 downto 0):="00";
|
36 | SIGNAL mDLY:std_logic_vector(27 downto 0):=x"0000000";--In hex
|
37 | SIGNAL mLCD_Start:std_logic:='0';
|
38 | SIGNAL mLCD_DATA:std_logic_vector(7 downto 0):="00000000";
|
39 | SIGNAL mLCD_RS:std_logic:='0';
|
40 | SIGNAL sclk:std_logic:='0';
|
41 | SIGNAL startcount : integer range 0 to 1:=0;
|
42 | SIGNAL D1,D2,D3,D4,D5,D6 : std_logic_vector (11 downto 0):=x"130";
|
43 | -- SIGNAL D1,D2,D3,D4,D5,D6 : std_logic_vector (11 downto 0);
|
44 |
|
45 | COMPONENT LCD_controller IS
|
46 | PORT( iCLK,iRS,iRST_N,istart : IN std_logic;
|
47 | iDATA : IN std_logic_vector(7 downto 0);
|
48 | oDone : OUT std_logic;
|
49 | LCD_DATA : OUT std_logic_vector(7 downto 0);
|
50 | LCD_RW : OUT std_logic;
|
51 | LCD_RS : OUT std_logic;
|
52 | LCD_EN : OUT std_logic
|
53 | );
|
54 | END COMPONENT LCD_controller;
|
55 |
|
56 | COMPONENT clk_div IS
|
57 | PORT ( iCLK: IN std_logic;
|
58 | sclk: OUT std_logic
|
59 | );
|
60 | END COMPONENT clk_div;
|
61 |
|
62 | BEGIN
|
63 | U0:LCD_controller
|
64 | PORT MAP(
|
65 | iCLK => clk,
|
66 | iRS => mLCD_RS,
|
67 | iRST_N => iRST_N,
|
68 | istart => mLCD_START,
|
69 | iDATA => mLCD_DATA,
|
70 | oDone => mLCD_DONE,
|
71 | LCD_DATA => LCD_DATA,
|
72 | LCD_RW => LCD_RW,
|
73 | LCD_RS => LCD_RS,
|
74 | LCD_EN => LCD_EN
|
75 | );
|
76 |
|
77 | U1:clk_div
|
78 | PORT MAP( iCLK => clk,
|
79 | sclk => sclk
|
80 | );
|
81 |
|
82 | LCD_ON <= '1';
|
83 | LCD_BLON <= '1';
|
84 |
|
85 | always : process(clk,reset,sclk)
|
86 | Begin
|
87 | IF(SW(0)='1')THEN
|
88 | D1 <= x"132";
|
89 | ELSIF(SW(1)='1')THEN
|
90 | D2 <= x"133";
|
91 | END IF;
|
92 |
|
93 | IF(reset = '1')THEN
|
94 | LUT_INDEX <= "00000000";
|
95 | --mLCD_ST <= "000000";
|
96 | mLCD_ST <= "00";
|
97 | --mDLY <= x"0000000";
|
98 | mLCD_DATA <= "00000000";
|
99 | mLCD_START <= '0';
|
100 | mLCD_RS <= '0';
|
101 |
|
102 | startcount <= 0;
|
103 | D1 <= x"130";
|
104 | D2 <= x"130";
|
105 | D3 <= x"130";
|
106 | D4 <= x"130";
|
107 | D5 <= x"130";
|
108 | D6 <= x"130";
|
109 |
|
110 | ----------LCD Line 1--------------
|
111 |
|
112 |
|
113 | ELSIF(rising_edge(clk))THEN
|
114 | startcount <= startcount + 1;
|
115 | IF (startcount = 1)THEN
|
116 |
|
117 | IF(LUT_INDEX < LUT_SIZE)THEN
|
118 | case mLCD_ST is
|
119 | when "00" => mLCD_DATA <= LUT_DATA(7 downto 0);
|
120 | mLCD_RS <= LUT_DATA(8);
|
121 | mLCD_START<= '1';
|
122 | mLCD_ST <= "01";
|
123 |
|
124 | when "01" => IF(mLCD_DONE = '1') THEN
|
125 | mLCD_START <= '0';
|
126 | mLCD_ST <= "10";
|
127 | END IF;
|
128 |
|
129 | when "10" => IF(switch = '1')THEN
|
130 | IF(LUT_DATA = x"080")THEN
|
131 | mLCD_ST <= "11";
|
132 | END IF;
|
133 | END IF;
|
134 |
|
135 | when "11" => LUT_INDEX <= LUT_INDEX + 1;
|
136 | mLCD_ST <= "00";
|
137 | end case;
|
138 | ELSE
|
139 | IF(sclk = '1')THEN
|
140 | LUT_INDEX <= LCD_INITIAL;
|
141 | END IF;
|
142 | END IF;
|
143 |
|
144 | END IF;
|
145 | END IF;
|
146 | END PROCESS always;
|
147 |
|
148 |
|
149 |
|
150 | ----READING OF LCD COMMAND----
|
151 | check:process(LUT_INDEX)
|
152 | begin
|
153 |
|
154 | case LUT_INDEX is
|
155 | when LCD_INITIAL+0=>LUT_DATA<=(x"030");
|
156 | when LCD_INITIAL+1=>LUT_DATA<=(x"00C");
|
157 | when LCD_INITIAL+2=>LUT_DATA<=(x"001");
|
158 | when LCD_INITIAL+3=>LUT_DATA<=(x"006");
|
159 | when LCD_INITIAL+4=>LUT_DATA<=(x"080");
|
160 |
|
161 |
|
162 |
|
163 |
|
164 | when LCD_LINE1 + 1 => LUT_DATA<=(x"130");
|
165 | when LCD_LINE1 + 2 => LUT_DATA<=(x"130");
|
166 | when LCD_LINE1 + 3 => LUT_DATA<=(x"130");
|
167 | when LCD_LINE1 + 4 => LUT_DATA<=(D6);
|
168 | when LCD_LINE1 + 5 => LUT_DATA<=(D5);
|
169 | when LCD_LINE1 + 6 => LUT_DATA<=(x"13a");
|
170 | when LCD_LINE1 + 7 => LUT_DATA<=(D4);
|
171 | when LCD_LINE1 + 8 => LUT_DATA<=(D3);
|
172 | when LCD_LINE1 + 9 => LUT_DATA<=(x"13a");
|
173 | when LCD_LINE1 + 10=> LUT_DATA<=(D2);
|
174 | when LCD_LINE1 + 11=> LUT_DATA<=(D1);
|
175 | -- when LCD_LINE1 + 12=> LUT_DATA<=(x"130");
|
176 | -- when LCD_LINE1 + 13=> LUT_DATA<=(x"130");
|
177 | -- when LCD_LINE1 + 14=> LUT_DATA<=(x"130");
|
178 | -- when LCD_LINE1 + 15=> LUT_DATA<=(x"130");
|
179 | -- when LCD_LINE1 + 16=> LUT_DATA<=(x"130");
|
180 | when others => LUT_DATA <= (x"000");
|
181 |
|
182 | end case;
|
183 |
|
184 | end process check;
|
185 | end LCDBody;
|