library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity LCD3 is
port(
clk: in std_logic;
en,rs,rw:out std_logic;
data:out std_logic_vector(7 downto 0)
);
end LCD3;
architecture a of LCD3 is
signal clk1,clk2,clk3:std_logic;
signal cnt:integer range 0 to 500000;
signal cnt1:integer range 0 to 250000;
signal cnt2:integer range 0 to 3000;
signal sec0,sec1,min0,min1,hou0,hou1:std_logic_vector(3 downto 0);
signal s1,s2,m1,m2,h1,h2,ddram:std_logic_vector(7 downto 0);
type state is
(set_dlnf,set_cursor,set_dcb,set_ddram,write_data);
signal pr_state:state;
begin
process(clk)
begin
if(clk'event and clk='1')then
if(cnt1=249999)then
cnt1<=0;
clk1<=not clk1;
else
cnt1<=cnt1+1;
end if;
end if;
end process;
process(clk)
begin
if(clk'event and clk='1')then
if(cnt2=2999)then
cnt2<=0;
clk2<=not clk2;
else
cnt2<=cnt2+1;
end if;
end if;
end process;
process(clk2)
begin
if(rising_edge(clk2))then
if(cnt=499999)then
cnt<=0;
else
cnt<=cnt+1;
end if;
if(cnt<250000)then
clk3<='0';
else
clk3<='1';
end if;
end if;
end process;
process(clk2)
begin
if(clk2'event and clk2='1') then
if(sec0="1001")then
sec0<="0000";
if(sec1="0101")then
sec1<="0000";
min0<=min0+1;
if (min0="1001")then
min0<="0000";
if(min1="0101")then
min1<="0000";
hou0<=hou0+1;
if(hou0="1001")then
hou0<="0000";
if(hou0="0100"and hou1="0010")then
hou1<="0000";sec0<="0001";
else hou1<=hou1+1;
end if;
else hou0<=hou0+1;
end if;
else min1<=min1+1;
end if;
else min0<=min0+1;
end if;
else sec1<=sec1+1;
end if;
else
sec0<=sec0+1;
end if;
end if;
end process;
process(sec0)
begin
case sec0 is
when "0000"=>s1<="00110000";
when "0001"=>s1<="00110001";
when "0010"=>s1<="00110010";
when "0011"=>s1<="00110011";
when "0100"=>s1<="00110100";
when "0101"=>s1<="00110101";
when "0110"=>s1<="00110110";
when "0111"=>s1<="00110111";
when "1000"=>s1<="00111000";
when "1001"=>s1<="00111001";
when others=>s1<=null;
end case;
end process;
process(sec1)
begin
case sec1 is
when "0000"=>s2<="00110000";
when "0001"=>s2<="00110001";
when "0010"=>s2<="00110010";
when "0011"=>s2<="00110011";
when "0100"=>s2<="00110100";
when "0101"=>s2<="00110101";
when others=>s2<=null;
end case;
end process;
process(min0)
begin
case min0 is
when "0000"=>m1<="00110000";
when "0001"=>m1<="00110001";
when "0010"=>m1<="00110010";
when "0011"=>m1<="00110011";
when "0100"=>m1<="00110100";
when "0101"=>m1<="00110101";
when "0110"=>m1<="00110110";
when "0111"=>m1<="00110111";
when "1000"=>m1<="00111000";
when "1001"=>m1<="00111001";
when others=>m1<=null;
end case;
end process;
process(min1)
begin
case min1 is
when "0000"=>m2<="00110000";
when "0001"=>m2<="00110001";
when "0010"=>m2<="00110010";
when "0011"=>m2<="00110011";
when "0100"=>m2<="00110100";
when "0101"=>m2<="00110101";
when others=>m2<=null;
end case;
end process;
process(hou0)
begin
case hou0 is
when "0000"=>h1<="00110000";
when "0001"=>h1<="00110001";
when "0010"=>h1<="00110010";
when "0011"=>h1<="00110011";
when "0100"=>h1<="00110100";
when "0101"=>h1<="00110101";
when "0110"=>h1<="00110110";
when "0111"=>h1<="00110111";
when "1000"=>h1<="00111000";
when "1001"=>h1<="00111001";
when others=>h1<=null;
end case;
end process;
process(hou1)
begin
case hou1 is
when "0000"=>h2<="00110000";
when "0001"=>h2<="00110001";
when "0010"=>h2<="00110010";
when others=>h2<=null;
end case;
end process;
en<=clk3;
rw<='0';
process(clk3,pr_state)
begin
if clk3'event and clk3='1'then
rs<='0';
pr_state<=set_dlnf;
case pr_state is
when set_dlnf=>data<="00110000";
pr_state<=set_cursor;
when set_cursor=>data<="00000110";
pr_state<=set_dcb;
when set_dcb=>data<="00001111";
pr_state<=set_ddram;
when set_ddram=>--data<="10000000";
if ddram="10000111"then
ddram<="10000000";
elsif ddram<"10000111"then
ddram<=ddram+1;
case ddram is
when"10000111"=>data<=s1;
when"10000110"=>data<=s2;
when"10000101"=>data<="10111010";
when"10000100"=>data<=m1;
when"10000011"=>data<=m2;
when"10000010"=>data<="10111010";
when"10000001"=>data<=h1;
when"10000000"=>data<=h2;
when others=>data<=null;
end case;
end if;
pr_state<=write_data;
when write_data=>rs<='1';
data<="00000000";
when others=>null;
end case;
end if;
end process;
end a;