library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_ARITH.all;
USE IEEE.STD_LOGIC_UNSIGNED.all;
entity oled_module_controllerv1 is
Port ( clk : in STD_LOGIC;
rst : in STD_LOGIC;
preset : in std_logic ;
key_in: in std_logic_vector (0 to 15) ;
adt_sec10 : in std_logic_vector(3 downto 0) ;
status_reg : in std_logic_vector( 1 downto 0) ;
led : out std_logic_vector(1 downto 0) ;
cdt_hour10 , cdt_hour1, cdt_min10 ,cdt_min1, cdt_sec10 ,cdt_sec1 : in std_logic_vector (3 downto 0) ;
adt_day100,adt_day10 ,adt_day1 : in std_logic_Vector ( 3 downto 0) ;
adt_sec1 : in std_logic_vector( 3 downto 0) ;
adt_min10, adt_min1 : in std_logic_vector( 3 downto 0) ;
adt_hour10,adt_hour1:in std_logic_vector( 3 downto 0) ;
data_out : inout STD_LOGIC_vector( 7 downto 0) ;
rs : out STD_LOGIC;
rw : out STD_LOGIC;
e : out STD_LOGIC;
sec0_En ,sec1_en , min0_en, min1_en , hour1_en, hour0_en : out std_logic ;
dac_a0 , dac_scl, dac_sda : out std_logic );
end oled_module_controllerv1;
architecture Behavioral of oled_module_controllerv1 is
signal clock_count : unsigned ( 23 downto 0) :=(others=>'0') ;
signal clk_enable400 : std_logic :='0' ;
type state_type is (power_up,reset1, reset2,
reset3, func_set, display_on, mode_set,
line2, return_home, drop_lcd_e, display_off, display_clear ,line2_data,char_mode, cursor_shift,
adt_state,sec10,sec1 ,min10,min1,coln1,coln2, hour10 , hour1,day100,day10 ,day1 ,dcoln,
cdth10 ,cdth1, cdtm10,cdtm1 ,cdts10,cdts1, status ,coln3,coln4,coln5,coln6,coln7 ,cdt_ih10,cdt_ih1, cdt_im10,cdt_im1,cdt_is10,cdt_is1
, dram_address,rst1,rst2,rst3,rst4,disp_off, func, clear_screen ,disp_on, MODE ,ADDR, message_enter ,
second_line,CURSOR_ON,l2 , second_linedata,zero , one , two , three , four, five , six , seven, eight , nine , forward , backward , data_delay , delay ,
input_data , delay_state,time_save);
----------st1,st2,st3,st4,st5,cdt_space2,read_addr
signal state, next_command : state_type;
signal data_bus : std_logic_vector ( 7 downto 0) ;
signal lcd_e, lcd_rs, lcd_rw_int : std_Logic ;
type character_string is array ( 0 to 15 ) of STD_LOGIC_VECTOR( 7 downto 0 );
signal lcd_display_string : character_string;
signal lcd_display_string_01 : character_string;
signal lcd_display_string_02 : character_string;
signal lcd_display_string_03 : character_string;
signal next_char : STD_LOGIC_VECTOR(7 downto 0);
signal char_count : STD_LOGIC_VECTOR(4 downto 0);
signal counter : unsigned ( 26 downto 0) :=( others=>'0') ;
signal sec_bcd: unsigned( 3 downto 0) :=( others=>'0') ;
signal sec_en: std_logic ;
signal sec_out : std_logic_vector( 7 downto 0) ;
------------------adt ------------
type str1 is array ( 0 to 5) of std_logic_Vector ( 7 downto 0) ;
signal adt_string,cdt_string : str1;
signal adt :std_logic_vector ( 7 downto 0) ;
signal cdt: std_logic_vector( 7 downto 0) ;
signal str_count : std_logic_vector( 3 downto 0) :="0000" ;
signal message_count : std_Logic_vector( 3 downto 0) ;
signal wait_count : std_logic_vector( 19 downto 0) := (others=>'0') ;
signal wait_time : integer range 0 to 119 :=0 ;
signal enable_key : std_logic:='0' ;
signal adt_d1s: std_logic_vector ( 7 downto 0) ;
signal adt_d10s : std_logic_vector ( 7 downto 0) ;
signal adt_d100s: std_logic_vector ( 7 downto 0) ;
signal adt_sec1s: std_logic_vector ( 7 downto 0) ;
signal adt_sec10s : std_logic_vector ( 7 downto 0) ;
signal adt_min1s: std_logic_vector ( 7 downto 0) ;
signal adt_min10s : std_logic_vector ( 7 downto 0) ;
signal adt_hour1s: std_logic_vector ( 7 downto 0) ;
signal adt_hour10s : std_logic_vector ( 7 downto 0) ;
--------------------------cdt--------------------------------
signal cdt_sec1s: std_logic_vector ( 7 downto 0) ;
signal cdt_sec10s : std_logic_vector ( 7 downto 0) ;
signal cdt_min1s: std_logic_vector ( 7 downto 0) ;
signal cdt_min10s : std_logic_vector ( 7 downto 0) ;
signal cdt_hour1s: std_logic_vector ( 7 downto 0) ;
signal cdt_hour10s : std_logic_vector ( 7 downto 0) ;
---------------------xxxxxxxxxxxxxxxx----------
signal key_stored, fkey_stored: std_logic_vector( 7 downto 0) ;
signal key_q : std_logic_vector( 0 to 15 ) ;
signal hour2_reg , hour1_reg : std_logic_Vector ( 3 downto 0) ;
signal sec2_reg , sec1_reg , min2_reg , min1_reg : std_logic_vector( 3 downto 0) ;
-------status -register ---------
signal sts_reg : std_logic_vector ( 1 downto 0) ;
signal wait_1sec : integer range 0 to 239999 := 0 ;
signal space_count : integer range 0 to 19 := 0 ;
signal one_mscounter : natural range 0 to 835 :=0 ; -------counter for 10 mhz clock enable for 10 mhz checking
signal f1khz : std_logic ;
attribute mark_debug : string ;
attribute mark_debug of key_q : signal is "true" ;
attribute mark_debug of lcd_e : signal is "true" ;
attribute mark_debug of lcd_rs : signal is "true" ;
attribute mark_debug of lcd_rw_int : signal is "true" ;
attribute mark_debug of data_bus : signal is "true" ;
attribute mark_debug of preset : signal is "true" ;
begin
dac_a0<=lcd_rs ;
dac_scl<= lcd_rw_int;
dac_sda<=lcd_e ;
---------------=============================
lcd_display_string <=( X"45" , X"6E" , X"74" ,X"65" , X"72" , X"20" ,X"63" , X"64" , X"74" , X"20" , X"54" , X"69" , X"6D" , X"65" , X"20", X"20") ;
next_char<= lcd_display_string( conv_integer( message_count)) ;
---------===============================
process(f1khz )
begin
if rising_edge ( f1khz ) then
key_q <= key_in ;
end if ;
end process ;
-----------------xxxxxxxxx----------------------------
-----------adt day---------------------------------
--------------------------------------------
process ( adt_day1) begin
case adt_day1 is
when "0000" =>
adt_d1s<=x"30" ;
when "0001"=>
adt_d1s<=x"31" ;
when "0010"=>
adt_d1s <=x"32" ;
when "0011"=>
adt_d1s<=x"33" ;
when "0100"=>
adt_d1s <=x"34" ;
when "0101"=>
adt_d1s <=x"35" ;
when others=>
adt_d1s <=x"30" ;
end case ;
end process ;
process ( adt_day10) begin
case adt_day10 is
when "0000" =>
adt_d10s<=x"30" ;
when "0001"=>
adt_d10s<=x"31" ;
when "0010"=>
adt_d10s <=x"32" ;
when "0011"=>
adt_d10s<=x"33" ;
when "0100"=>
adt_d10s <=x"34" ;
when "0101"=>
adt_d10s <=x"35" ;
when "0110"=>
adt_d10s<=x"36" ;
when others=>
adt_d10s <=x"30" ;
end case ;
end process ;
process ( adt_day100) begin
case adt_day100 is
when "0000" =>
adt_d100s<=x"30" ;
when "0001"=>
adt_d100s<=x"31" ;
when "0010"=>
adt_d100s <=x"32" ;
when "0011"=>
adt_d100s<=x"33" ;
when others=>
adt_d100s <=x"30" ;
end case ;
end process ;
----------------------------XXXXXXXXXXXXXXXXXX---------------------------------
------------------ADT HOUR ---------------------------------------------------
----------=============================================
process ( adt_hour10)
begin
case adt_hour10 is
when "0000" =>
adt_hour10s<=x"30" ;
when "0001"=>
adt_hour10s<=x"31" ;
when "0010"=>
adt_hour10s <=x"32" ;
when "0011"=>
adt_hour10s<=x"33" ;
when "0100"=>
adt_hour10s <=x"34" ;
when "0101"=>
adt_hour10s <=x"35" ;
when "0110"=>
adt_hour10s<=x"36" ;
when "0111"=>
adt_hour10s <=x"37" ;
when "1000"=>
adt_hour10s <=x"38" ;
when "1001"=>
adt_hour10s <=x"39" ;
when others =>
adt_hour10s <= x"30" ;
end case ;
end process ;
process ( adt_hour1)
begin
case adt_hour1 is
when "0000" =>
adt_hour1s<=x"30" ;
when "0001"=>
adt_hour1s <=x"31" ;
when "0010"=>
adt_hour1s<=x"32" ;
when "0011"=>
adt_hour1s <=x"33" ;
when "0100"=>
adt_hour1s <=x"34" ;
when "0101"=>
adt_hour1s <=x"35" ;
when "0110"=>
adt_hour1s <=x"36" ;
when "0111"=>
adt_hour1s <=x"37" ;
when "1000"=>
adt_hour1s <=x"38" ;
when "1001"=>
adt_hour1s <=x"39" ;
when others =>
adt_hour1s <= x"30" ;
end case ;
end process ;
----------------------XXXXXXXXXXXXXXXXX-------------------------------
--------------------ADT MIN-------------------------------------------------
------------------======================================
process ( adt_min10)
begin
case adt_min10 is
when "0000" =>
adt_min10s<=x"30" ;
when "0001"=>
adt_min10s <=x"31" ;
when "0010"=>
adt_min10s <=x"32" ;
when "0011"=>
adt_min10s <=x"33" ;
when "0100"=>
adt_min10s <=x"34" ;
when "0101"=>
adt_min10s <=x"35" ;
when "0110"=>
adt_min10s <=x"36" ;
when "0111"=>
adt_min10s <=x"37" ;
when "1000"=>
adt_min10s <=x"38" ;
when "1001"=>
adt_min10s <=x"39" ;
when others =>
adt_min10s <= x"30" ;
end case ;
end process ;
process ( adt_min1)
begin
case adt_min1 is
when "0000" =>
adt_min1s<=x"30" ;
when "0001"=>
adt_min1s <=x"31" ;
when "0010"=>
adt_min1s <=x"32" ;
when "0011"=>
adt_min1s <=x"33" ;
when "0100"=>
adt_min1s <=x"34" ;
when "0101"=>
adt_min1s <=x"35" ;
when "0110"=>
adt_min1s <=x"36" ;
when "0111"=>
adt_min1s <=x"37" ;
when "1000"=>
adt_min1s <=x"38" ;
when "1001"=>
adt_min1s <=x"39" ;
when others =>
adt_min1s <= x"30" ;
end case ;
end process ;
----------------------xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-----------------------------
---------------ADT SEC-------------------------------------------------
-------===============================================
process ( adt_sec1)
begin
case (adt_sec1 ) is
when "0000" =>
adt_sec1s <=x"30" ;
when "0001"=>
adt_sec1s <=x"31" ;
when "0010"=>
adt_sec1s <=x"32" ;
when "0011"=>
adt_sec1s <=x"33" ;
when "0100"=>
adt_sec1s <=x"34" ;
when "0101"=>
adt_sec1s <=x"35" ;
when "0110"=>
adt_sec1s <=x"36" ;
when "0111"=>
adt_sec1s <=x"37" ;
when "1000"=>
adt_sec1s <=x"38" ;
when "1001"=>
adt_sec1s <=x"39" ;
when others =>
adt_sec1s <= x"30" ;
end case ;
end process ;
process ( adt_sec10)
begin
case adt_sec10 is
when "0000" =>
adt_sec10s <=x"30" ;
when "0001"=>
adt_sec10s <=x"31" ;
when "0010"=>
adt_sec10s <=x"32" ;
when "0011"=>
adt_sec10s <=x"33" ;
when "0100"=>
adt_sec10s <=x"34" ;
when "0101"=>
adt_sec10s <=x"35" ;
when "0110"=>
adt_sec10s <=x"36" ;
when "0111"=>
adt_sec10s <=x"37" ;
when "1000"=>
adt_sec10s <=x"38" ;
when "1001"=>
adt_sec10s <=x"39" ;
when others =>
adt_sec10s <= x"30" ;
end case ;
end process ;
--------------=============================cdt=======================
----============================================================
----------------------------XXXXXXXXXXXXXXXXXX---------------------------------
------------------CDT HOUR ---------------------------------------------------
----------=============================================
process ( cdt_hour10)
begin
case cdt_hour10 is
when "0000" =>
cdt_hour10s<=x"30" ;
when "0001"=>
cdt_hour10s<=x"31" ;
when "0010"=>
cdt_hour10s <=x"32" ;
when "0011"=>
cdt_hour10s<=x"33" ;
when "0100"=>
cdt_hour10s <=x"34" ;
when "0101"=>
cdt_hour10s <=x"35" ;
when "0110"=>
cdt_hour10s<=x"36" ;
when "0111"=>
cdt_hour10s <=x"37" ;
when "1000"=>
cdt_hour10s <=x"38" ;
when "1001"=>
cdt_hour10s <=x"39" ;
when others =>
cdt_hour10s <= x"30" ;
end case ;
--end if;
--end if ;
end process ;
process ( cdt_hour1)
begin
case cdt_hour1 is
when "0000" =>
cdt_hour1s<=x"30" ;
when "0001"=>
cdt_hour1s <=x"31" ;
when "0010"=>
cdt_hour1s<=x"32" ;
when "0011"=>
cdt_hour1s <=x"33" ;
when "0100"=>
cdt_hour1s <=x"34" ;
when "0101"=>
cdt_hour1s <=x"35" ;
when "0110"=>
cdt_hour1s <=x"36" ;
when "0111"=>
cdt_hour1s <=x"37" ;
when "1000"=>
cdt_hour1s <=x"38" ;
when "1001"=>
cdt_hour1s <=x"39" ;
when others =>
cdt_hour1s <= x"30" ;
end case ;
end process ;
----------------------XXXXXXXXXXXXXXXXX-------------------------------
--------------------ADT MIN-------------------------------------------------
------------------======================================
process ( cdt_min10)
begin
case cdt_min10 is
when "0000" =>
cdt_min10s<=x"30" ;
when "0001"=>
cdt_min10s <=x"31" ;
when "0010"=>
cdt_min10s <=x"32" ;
when "0011"=>
cdt_min10s <=x"33" ;
when "0100"=>
cdt_min10s <=x"34" ;
when "0101"=>
cdt_min10s <=x"35" ;
when "0110"=>
cdt_min10s <=x"36" ;
when "0111"=>
cdt_min10s <=x"37" ;
when "1000"=>
cdt_min10s <=x"38" ;
when "1001"=>
cdt_min10s <=x"39" ;
when others =>
cdt_min10s <= x"30" ;
end case ;
end process ;
process ( cdt_min1)
begin
case cdt_min1 is
when "0000" =>
cdt_min1s<=x"30" ;
when "0001"=>
cdt_min1s <=x"31" ;
when "0010"=>
cdt_min1s <=x"32" ;
when "0011"=>
cdt_min1s <=x"33" ;
when "0100"=>
cdt_min1s <=x"34" ;
when "0101"=>
cdt_min1s <=x"35" ;
when "0110"=>
cdt_min1s <=x"36" ;
when "0111"=>
cdt_min1s <=x"37" ;
when "1000"=>
cdt_min1s <=x"38" ;
when "1001"=>
cdt_min1s <=x"39" ;
when others =>
cdt_min1s <= x"30" ;
end case ;
end process ;
----------------------xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-----------------------------
---------------ADT SEC-------------------------------------------------
-------===============================================
process ( cdt_sec1)
begin
case (cdt_sec1 ) is
when "0000" =>
cdt_sec1s <=x"30" ;
when "0001"=>
cdt_sec1s <=x"31" ;
when "0010"=>
cdt_sec1s <=x"32" ;
when "0011"=>
cdt_sec1s <=x"33" ;
when "0100"=>
cdt_sec1s <=x"34" ;
when "0101"=>
cdt_sec1s <=x"35" ;
when "0110"=>
cdt_sec1s <=x"36" ;
when "0111"=>
cdt_sec1s <=x"37" ;
when "1000"=>
cdt_sec1s <=x"38" ;
when "1001"=>
cdt_sec1s <=x"39" ;
when others =>
cdt_sec1s <= x"30" ;
end case ;
end process ;
process ( cdt_sec10)
begin
case cdt_sec10 is
when "0000" =>
cdt_sec10s <=x"30" ;
when "0001"=>
cdt_sec10s <=x"31" ;
when "0010"=>
cdt_sec10s <=x"32" ;
when "0011"=>
cdt_sec10s <=x"33" ;
when "0100"=>
cdt_sec10s <=x"34" ;
when "0101"=>
cdt_sec10s <=x"35" ;
when "0110"=>
cdt_sec10s <=x"36" ;
when "0111"=>
cdt_sec10s <=x"37" ;
when "1000"=>
cdt_sec10s <=x"38" ;
when "1001"=>
cdt_sec10s <=x"39" ;
when others =>
cdt_sec10s <= x"30" ;
end case ;
end process ;
------------------------xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-----------------------
adt_string <=( x"41" ,x"44" ,x"54" , x"3a",x"20" ,x"20" ) ;
adt <= adt_string (conv_integer ( str_count ) ) ;
cdt_string <=(x"43" , x"44" , x"54" ,x"3a",x"20" ,x"20" );
cdt <= cdt_string ( conv_integer ( str_count)) ;
-- BIDIRECTIONAL TRI STATE LCD DATA BUS
data_out <= data_bus when lcd_rw_int = '0' else "ZZZZZZZZ";
-- LCD_RW PORT is assigned to it matching SIGNAL
rw <= lcd_rw_int;
e<=lcd_e ;
rs <=lcd_rs ;
process ( clk )
begin
if rising_edge ( clk) then
if ( rst='1') then
clock_count <=(others=>'0') ;
clk_enable400<='0' ;
else
if ( clock_count <= 416) then -----------240 khz enable signal for zedboard working 100 mhz
-- if ( clock_count <= 99999) then -----------240 khz enable signal for zedboard working 100 mhz
-- if ( clock_count <= 99999) then -----------240 khz enable signal for zedboard working 100 mhz
-- if ( clock_count <= 24999) then ----------- working 4khz final
clock_count <= clock_count +1 ;
clk_enable400 <='0' ;
else
clock_count<=(others=>'0') ;
clk_enable400 <='1';
end if ;
end if ;
end if ;
end process ;
------------xx-------------------------
process ( clk, rst )
begin
if (rst='1') then
one_mscounter <=0;
f1khz <='0';
elsif rising_edge( clk) then
-- if ( one_mscounter =835) then ---- for zedboard default 120 khz
-- if ( one_mscounter =417) then ---- for zedboard default 120 khz 120 khz enable freequency
if ( one_mscounter =417) then ---- for zedboard default 120 khz
-- if ( one_mscounter =4999) then -------for 10 mhz clock
-- if ( one_mscounter =62499) then -------for 1khz clock for zybo ----working
one_mscounter <=0;
f1khz <= not (f1khz) ; ----240 khz frequeny
else
one_mscounter <= one_mscounter +1 ;
end if ;
end if ;
end process;
------------------------------------------------------------------
---------------statemachine cotnrol-----------------------------
--------------------------------------------------------------------
process ( f1khz,rst)
begin
if (rst='1') then
state <= power_up;
data_bus <= x"38"; -- RESET ---default
next_command <= reset1;
lcd_e <= '1'; ------------enableing data in 120 khz half of the clk_enable
lcd_rs <= '0';
lcd_rw_int <= '0';
str_count <= "0000" ;
wait_count <=(others=>'0') ;
space_count <=0;
message_count<=(others=>'0') ;
sec1_en <='0';
sec0_en <='0' ;
min1_en <='0' ;
min0_en <='0' ;
hour1_en <='0' ;
hour0_en <='0' ;
elsif rising_edge(f1khz) then
-- if clk_enable400 = '1' then
case (state ) is
when power_up =>
lcd_e <= '1';
lcd_rs <= '0';
lcd_rw_int <= '0';
data_bus <= x"38"; -- EXTERNAL RESET
state <= drop_lcd_e;
if ( wait_count =120) then ------ testing
wait_count <=(others=>'0') ;
next_command <= reset1; ----500 ms reached
else
wait_count <= wait_count +1 ;
end if ;
char_count <= "00000";
if ( preset='1') then
next_command <= rst1 ;
end if ;
--======================= INITIALIZATION START ============================--
when reset1 =>
lcd_e <= '1';
lcd_rs <= '0';
lcd_rw_int <= '0';
data_bus <= x"38"; -- EXTERNAL RESET
state <= drop_lcd_e;
-- next_command <= reset2;
-- if ( wait_count =250) then ------ working
if ( wait_count =120) then ------ testing
wait_count <=(others=>'0') ;
next_command <= reset2; ----500 ms reached
else
wait_count <= wait_count +1 ;
end if ;
char_count <= "00000";
if ( preset='1') then
next_command <= rst1 ;
end if ;
when reset2 =>
lcd_e <= '1';
lcd_rs <= '0';
lcd_rw_int <= '0';
data_bus <= x"38"; -- EXTERNAL RESET
state <= drop_lcd_e;
next_command <= reset3;
if ( preset='1') then
next_command <= rst1 ;
end if ;
when reset3 =>
lcd_e <= '1';
lcd_rs <= '0';
lcd_rw_int <= '0';
data_bus <= x"38"; -- EXTERNAL RESET
state <= drop_lcd_e;
next_command <= func_set;
if ( preset='1') then
next_command <= rst1 ;
end if ;
-- Function Set
--==============--
when func_set =>
lcd_e <= '1';
lcd_rs <= '0';
lcd_rw_int <= '0';
data_bus <= x"38"; -- Set Function to 8-bit transfer, 2 line display and a 5x8 Font size
state <= drop_lcd_e;
next_command <= display_off; ---default working
-- next_command <= display_clear;
if ( preset='1') then
next_command <= rst1 ;
end if ;
-- Turn off Display
--==============--
when display_off =>
lcd_e <= '1';
lcd_rs <= '0';
lcd_rw_int <= '0';
data_bus <= x"08"; -- Turns OFF the Display, Cursor OFF and Blinking Cursor Position OFF.......
-- data_bus <= x"0D"; -- (0F = Display ON and Cursor ON, Blinking cursor position ON)
state <= drop_lcd_e;
next_command <= display_clear;
if ( preset='1') then
next_command <= rst1 ;
end if ;
-- Clear Display
--==============--
when display_clear =>
lcd_e <= '1';
lcd_rs <= '0';
lcd_rw_int <= '0';
data_bus <= x"01"; -- Clears the Display
state <= drop_lcd_e;
next_command <= display_on;
if ( preset='1') then
next_command <= rst1 ;
end if ;
-- Turn on Display and Turn off cursor
--===================================--
when display_on =>
lcd_e <= '1';
lcd_rs <= '0';
lcd_rw_int <= '0';
data_bus <= x"0C"; -- Turns on the Display (0E = Display ON, Cursor ON and Blinking cursor OFF)
-- data_bus <= x"0D";
state <= drop_lcd_e;
-- next_command <= mode_set;
-- next_command <= char_mode;
next_command <= dram_address;
if ( preset='1') then
next_command <= rst1 ;
end if ;
-----------------enable while inputing from keypad
when cursor_shift =>
lcd_e <= '1';
lcd_rs <= '0';
lcd_rw_int <= '0';
data_bus <= x"14";
state <= drop_lcd_e;
next_command <= mode_set;
if ( preset='1') then
next_command <= rst1 ;
end if ;
when char_mode =>
lcd_e <= '1';
lcd_rs <= '0';
lcd_rw_int <= '0';
data_bus <= x"17";
state <= drop_lcd_e;
next_command <= mode_set;
if ( preset='1') then
next_command <= rst1 ;
end if ;
when dram_address =>
lcd_e <= '1';
lcd_rs <= '0';
lcd_rw_int <= '0';
data_bus <= "10000000";
state <= drop_lcd_e;
next_command <= mode_set;
if ( preset='1') then
next_command <= rst1 ;
end if ;
-- Set write mode to auto increment address and move cursor to the right
--====================================================================--
when mode_set =>
lcd_e <= '1';
lcd_rs <= '0';
lcd_rw_int <= '0';
data_bus <= x"06"; -- Auto increment address and move cursor to the right
state <= drop_lcd_e;
next_command <=adt_state ;
if ( preset='1') then
next_command <= rst1 ;
end if ;
when adt_state =>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
----------------------------added
data_bus <=adt ;
next_command <=adt_state; ----added
if ( str_count ="0101") then
str_count <="0000" ;
next_command<=day100;
else
str_count <= str_count +1 ;
end if ;
if ( preset='1') then
next_command <= rst1 ;
end if ;
------------------------added code ------------------
when day100=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
----------------------------added
data_bus <=adt_d100s;
next_command<=day10;
if ( preset='1') then
next_command <= rst1 ;
end if ;
when day10=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
----------------------------added
data_bus <=adt_d10s;
next_command<=day1;
if ( preset='1') then
next_command <= rst1 ;
end if ;
when day1=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
----------------------------added
data_bus <=adt_d1s;
next_command<=dcoln;
if ( preset='1') then
next_command <= rst1 ;
end if ;
when dcoln=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
----------------------------added
data_bus <=x"3a";
next_command<=hour10;
if ( preset='1') then
next_command <= rst1 ;
end if ;
when hour10=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
----------------------------added
data_bus <=adt_hour10s;
next_command<=hour1;
if ( preset='1') then
next_command <= rst1 ;
end if ;
when hour1=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
----------------------------added
data_bus <=adt_hour1s;
next_command<=coln2;
if ( preset='1') then
next_command <= rst1 ;
end if ;
when coln2=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
----------------------------added
data_bus <=x"3a";
next_command<=min10;
if ( preset='1') then
next_command <= rst1 ;
end if ;
when min10=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
----------------------------added
data_bus <=adt_min10s;
next_command<=min1;
if ( preset='1') then
next_command <= rst1 ;
end if ;
when min1=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
----------------------------added
data_bus <=adt_min1s;
next_command<=coln1;
if ( preset='1') then
next_command <= rst1 ;
end if ;
-----------------------------------------------------
when coln1=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
----------------------------added
data_bus <=x"3a";
next_command<=sec10;
if ( preset='1') then
next_command <= rst1 ;
end if ;
when sec10=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
----------------------------added
data_bus <=adt_sec10s;
next_command<=sec1;
if ( preset='1') then
next_command <= rst1 ;
end if ;
when sec1=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
----------------------------added
data_bus <=adt_sec1s;
next_command<=line2;
if ( preset='1') then
next_command <= rst1 ;
end if ;
when line2 =>
lcd_e <= '1';
lcd_rs <= '0';
lcd_rw_int <= '0';
data_bus <= x"c0"; ---c0 default ---working
-- data_bus <= x"40";
state <= drop_lcd_e;
-- next_command<=cdt_c;
next_command<=line2_data;
if ( preset='1') then
next_command <= rst1 ;
end if ;
when line2_data=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
data_bus <= cdt ;
next_command <=line2_data; ----added
if ( str_count ="0101") then
str_count <="0000" ;
next_command<=cdth10;
-- next_command<=line3;
else
str_count <= str_count +1 ;
end if ;
if ( preset='1') then
next_command <= rst1 ;
end if ;
----------------==========================cdt -timing
when cdth10=>
----------------------------
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
data_bus <=cdt_hour10s;
next_command<=cdth1;
if ( preset='1') then
next_command <= rst1 ;
end if ;
--------------------------------
when cdth1=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
data_bus <=cdt_hour1s;
next_command<=coln3;
if ( preset='1') then
next_command <= rst1 ;
end if ;
when coln3=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
data_bus <=x"3a";
next_command<=cdtm10;
if ( preset='1') then
next_command <= rst1 ;
end if ;
when cdtm10=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
----------------------------added
data_bus <=cdt_min10s;
next_command<=cdtm1;
if ( preset='1') then
next_command <= rst1 ;
end if ;
when cdtm1=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
----------------------------added
data_bus <=cdt_min1s;
next_command<=coln4;
if ( preset='1') then
next_command <= rst1 ;
end if ;
when coln4=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
----------------------------added
data_bus <=x"3a";
next_command<=cdts10;
if ( preset='1') then
next_command <= rst1 ;
end if ;
when cdts10=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
----------------------------added
data_bus <=cdt_sec10s;
next_command<=cdts1;
if ( preset='1') then
next_command <= rst1 ;
end if ;
when cdts1=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
----------------------------added
data_bus <=cdt_sec1s;
next_command<=coln5 ;
if ( preset='1') then
next_command <= rst1 ;
end if ;
when coln5=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
----------------------------added
data_bus <=x"3a";
next_command<=status;
if ( preset='1') then
next_command <= rst1 ;
end if ;
when status =>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
----------------------------added
if ( status_reg ="00" ) then
data_bus <=x"30";
elsif ( status_reg="10" ) then
data_bus<=x"55" ;
elsif (status_reg="01" ) then
data_bus <=x"44" ;
elsif (status_reg="11" ) then
data_bus <=x"48" ;
else
data_bus <=x"55" ;
end if ;
next_command<=return_home;
if ( preset='1') then
next_command <= rst1 ;
end if ;
when return_home =>
lcd_e <= '1';
lcd_rs <= '0';
lcd_rw_int <= '0';
data_bus <= x"02"; ----just now commented
state <= drop_lcd_e;
next_command <=adt_state ;
if ( preset='1') then
next_command <= rst1 ;
end if ;
when drop_lcd_e =>
state <= next_command;
lcd_e <= '0';
when rst1=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '0';
lcd_rw_int <= '0';
sec1_en <='0';
sec0_en <='0' ;
min1_en <='0' ;
min0_en <='0' ;
hour1_en <='0' ;
hour0_en <='0' ;
data_bus <= x"01" ; ---- defualt working x"38";
next_command <= rst2;
when rst2=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '0';
lcd_rw_int <= '0';
data_bus <= x"38"; ---38 working defualt
if ( wait_count =520) then ------ testing
wait_count <=(others=>'0') ;
next_command <= func; ----500 ms reached
else
wait_count <= wait_count +1 ;
end if ;
when rst3=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '0';
lcd_rw_int <= '0';
data_bus <= x"38";
next_command <= rst4; ----500 ms reached
when rst4=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '0';
lcd_rw_int <= '0';
data_bus <= x"38";
next_command <= func; ----500 ms reached
when func=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '0';
lcd_rw_int <= '0';
data_bus <= x"38";
-- next_command <= disp_off; ----500 ms reached WORKING
next_command <= disp_on; ----500 ms reached
when disp_off =>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '0';
lcd_rw_int <= '0';
data_bus <= x"08";
next_command <=clear_screen ; ----500 ms reached
when clear_screen=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '0';
lcd_rw_int <= '0';
data_bus <= x"01";
next_command <= disp_on; ----500 ms reached
when disp_on =>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '0';
lcd_rw_int <= '0';
data_bus <= x"0C"; -- Turns on the Display (0E = Display ON, Cursor ON and Blinking cursor OFF)
-- data_bus <=x"0E"; ----display on , cursor on , blink off
-- next_command <= ADDR; ---- working default
next_command <= MODE;
when MODE =>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '0';
lcd_rw_int <= '0';
data_bus <= x"06";
-- data_bus <= x"07";
next_command <= ADDR;
when ADDR =>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '0';
lcd_rw_int <= '0';
data_bus <= "10000000"; ---dram selection
next_command <= message_enter;
when message_enter=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
sec1_en <='0';
sec0_en <='0' ;
min1_en <='0' ;
min0_en <='0' ;
hour1_en <='0' ;
hour0_en <='0' ;
data_bus <= next_char;
next_command <=message_enter;
if ( message_count ="1111") then
message_count <="0000" ;
IF ( PRESET='0') THEN
next_command<=second_line;
else
next_command<=time_save;
END IF ;
else
message_count <= message_count +1 ;
end if ;
when second_line=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '0';
lcd_rw_int <= '0';
data_bus <= x"C0";
next_command<=cdt_ih10; ---default working
-- when CURSOR_ON=>
-- lcd_e <= '1';
-- lcd_rs <= '0';
-- lcd_rw_int <= '0';
-- data_bus <= x"0E"; -- Turns on the Display (0E = Display ON, Cursor ON and Blinking cursor OFF)
-- state <= drop_lcd_e;
---- next_command <= second_line_data; -----default
---- next_command<= input_data;
-- next_command<= cdt_ih10;
---------start added ------------------
when cdt_ih10=>
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
hour1_en <='1' ;
data_bus <=cdt_hour10s;
state <= drop_lcd_e;
next_command<=cdt_ih1;
when cdt_ih1=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
hour0_en<='1' ;
data_bus <=cdt_hour1s;
next_command<=coln6;
when coln6=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
data_bus <=x"3a";
next_command<=cdt_im10;
when cdt_im10=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
min1_en <='1' ;
data_bus <=cdt_min10s;
next_command<=cdt_im1;
when cdt_im1=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
min0_en <='1' ;
data_bus <=cdt_min1s;
next_command<=coln7;
when coln7=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
data_bus <=x"3a";
next_command<=cdt_is10;
when cdt_is10=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
sec1_en <='1' ;
data_bus <=cdt_sec10s;
next_command<=cdt_is1;
when cdt_is1=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
data_bus <=cdt_sec1s;
next_command<=l2;
-- next_command<=time_save;
-- if (key_q=x"8000" ) then -------save and exit *
-- state <= drop_lcd_e;
-- next_command<=power_up;
-- end if ;
-- if (key_q=x"0800" ) then ----# go to rst1 state
-- state <= drop_lcd_e;
-- next_command<=rst1;
-- end if ;
-- if (key_q=x"4000" ) then ----# d to rst1 state
-- state <= drop_lcd_e;
-- next_command<=power_up;
-- end if ;
when l2=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '0';
lcd_rw_int <= '0';
data_bus <= x"C0";
next_command<=CURSOR_ON;
when CURSOR_ON=>
lcd_e <= '1';
lcd_rs <= '0';
lcd_rw_int <= '0';
data_bus <= x"0E"; -- Turns on the Display (0E = Display ON, Cursor ON and Blinking cursor OFF)
state <= drop_lcd_e;
next_command<= second_linedata;
----------end cursor on -------
when second_linedata=>
-- lcd_e <= '1'; ---default one
-- lcd_rs <= '1';
-- lcd_rw_int <= '0';
-- state <= drop_lcd_e;
-- data_bus <=x"20" ;
-- next_command<=return_home;
next_command<=l2;
if ( key_q =x"0004" ) then ------1
data_bus <= x"31" ;
state <= drop_lcd_e;
next_command<=one;
end if ;
if ( key_q =x"0008") then ----- 2
data_bus <=x"32" ;
state <= drop_lcd_e;
next_command<=two;
end if ;
if (key_q=x"0010" ) then -------3
data_bus <= x"33" ;
state <= drop_lcd_e;
next_command<=three;
end if ;
if (key_q=x"0002" ) then -------4
data_bus <= x"34" ;
state <= drop_lcd_e;
next_command<=four;
end if;
if (key_q=x"0040" ) then ------5
data_bus <= x"35" ;
state <= drop_lcd_e;
next_command<=five;
end if ;
if (key_q=x"0200" ) then --------------6
data_bus <= x"36" ;
state <= drop_lcd_e;
next_command<=six;
end if ;
if (key_q=x"0001" ) then ------ 7
data_bus <= x"37" ;
state <= drop_lcd_e;
next_command<=seven;
end if ;
if (key_q=x"0080" ) then ----- 8
data_bus <= x"38" ;
state <= drop_lcd_e;
next_command<=eight;
end if ;
if (key_q=x"0400" ) then ------ 9
data_bus <= x"39" ;
state <= drop_lcd_e;
next_command<=nine;
end if ;
if (key_q=x"0100" ) then ------ 0
data_bus <= x"30" ;
state <= drop_lcd_e;
next_command<=zero;
end if ;
if (key_q=x"0020" ) then ----A SHIFT THE CURSOR TO THE LIFT
-- data_bus <= x"04" ; ------SHIFT CURSOR TO LEFT
data_bus <= x"14" ; -----SHIFT CURSOR POSITION TO LEFT
state <= drop_lcd_e;
next_command<=forward;
end if ;
if (key_q=x"1000" ) then ---B SHIFT THE DISPLAY AND CURSOR POSITION TO RIGHT
-- data_bus <= x"06" ; ------SHIFT CURSOR TO RIGHT
data_bus <= x"10" ; -----SHIFT CURSOR POSITION TO RIGHT
state <= drop_lcd_e;
next_command<=backward;
end if ;
if (key_q=x"8000" ) then -------save and exit *
state <= drop_lcd_e;
next_command<=power_up;
end if ;
if (key_q=x"0800" ) then ----# go to rst1 state
state <= drop_lcd_e;
next_command<=rst1;
end if ;
if (key_q=x"4000" ) then ----# d to rst1 state
state <= drop_lcd_e;
next_command<=power_up;
end if ;
when one=>
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
data_bus <= x"31"; -- Auto increment address and move cursor to the right
state <= drop_lcd_e;
next_command <=data_delay ;
when two=>
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
data_bus <= x"32"; -- Auto increment address and move cursor to the right
state <= drop_lcd_e;
next_command <=data_delay ;
when three=>
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
data_bus <= x"33"; -- Auto increment address and move cursor to the right
state <= drop_lcd_e;
next_command <=data_delay ;
when four=>
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
data_bus <= x"34"; -- Auto increment address and move cursor to the right
state <= drop_lcd_e;
next_command <=data_delay ;
when five =>
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
data_bus <= x"35"; -- Auto increment address and move cursor to the right
state <= drop_lcd_e;
next_command <=data_delay ;
when six=>
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
data_bus <= x"36"; -- Auto increment address and move cursor to the right
state <= drop_lcd_e;
next_command <=data_delay ;
when seven=>
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
data_bus <= x"37"; -- Auto increment address and move cursor to the right
state <= drop_lcd_e;
next_command <=data_delay ;
when eight=>
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
data_bus <= x"38"; -- Auto increment address and move cursor to the right
state <= drop_lcd_e;
next_command <=data_delay ;
when nine=>
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
data_bus <= x"39"; -- Auto increment address and move cursor to the right
state <= drop_lcd_e;
next_command <=data_delay ;
when zero=>
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
data_bus <= x"30"; -- Auto increment address and move cursor to the right
state <= drop_lcd_e;
next_command <=data_delay ;
when forward=>
lcd_e <= '1';
lcd_rs <= '0';
lcd_rw_int <= '0';
-- data_bus <= x"04"; -- Auto increment address and move cursor to the LEFT
data_bus <= x"14" ; ----SHIFT CURSOR POSTION TO LEFT
state <= drop_lcd_e;
next_command <=delay ;
when backward=>
lcd_e <= '1';
lcd_rs <= '0';
lcd_rw_int <= '0';
-- data_bus <= x"06"; -- Auto increment address and move cursor to the right
data_bus <= x"10" ; ----SHIFT CURSOR POSTION TO RIGHT
state <= drop_lcd_e;
next_command <=delay ;
when data_delay=>
lcd_e <= '0';
lcd_rs <= '1';
lcd_rw_int <= '0';
-- data_bus <=x"20";
wait_1sec <= wait_1sec+1 ;
if ( wait_1sec=60000) then ---- .5 sec wait
wait_1sec <=0 ;
state<=second_linedata ; -----working
end if ;
when delay=>
lcd_e <= '0';
lcd_rs <= '0';
lcd_rw_int <= '0';
-- data_bus <=x"20";
wait_1sec <= wait_1sec+1 ;
if ( wait_1sec=60000) then ---- .5 sec wait
wait_1sec <=0 ;
state<=second_linedata ; ----working
end if ;
when input_data=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
data_bus <=x"20";
next_command<=time_save;
if ( key_q =x"0004" ) then ------1
data_bus <= x"31" ;
state <= drop_lcd_e;
next_command<=delay_state;
end if ;
if ( key_q =x"0008") then ----- 2
data_bus <=x"32" ;
state <= drop_lcd_e;
next_command<=delay_state;
end if ;
if (key_q=x"0010" ) then -------3
data_bus <= x"33" ;
state <= drop_lcd_e;
next_command<=delay_state;
end if ;
if (key_q=x"0002" ) then -------4
data_bus <= x"34" ;
state <= drop_lcd_e;
next_command<=delay_state;
end if;
if (key_q=x"0040" ) then ------5
data_bus <= x"35" ;
state <= drop_lcd_e;
next_command<=delay_state;
end if ;
if (key_q=x"0200" ) then --------------6
data_bus <= x"36" ;
state <= drop_lcd_e;
next_command<=delay_state;
end if ;
if (key_q=x"0001" ) then ------ 7
data_bus <= x"37" ;
state <= drop_lcd_e;
next_command<=delay_state;
end if ;
if (key_q=x"0080" ) then ----- 8
data_bus <= x"38" ;
state <= drop_lcd_e;
next_command<=delay_state;
end if ;
if (key_q=x"0400" ) then ------ 9
data_bus <= x"39" ;
state <= drop_lcd_e;
next_command<=delay_state;
end if ;
if (key_q=x"0100" ) then ------ 0
data_bus <= x"30" ;
state <= drop_lcd_e;
next_command<=delay_state;
end if ;
if (key_q=x"8000" ) then -------save and exit *
data_bus <= x"02" ;
state <= drop_lcd_e;
next_command<=power_up;
end if ;
if (key_q=x"0800" ) then ----# go to rst1 state
data_bus <= x"02" ;
state <= drop_lcd_e;
next_command<=rst1;
end if ;
when delay_state=>
lcd_e <= '1';
lcd_rs <= '1';
lcd_rw_int <= '0';
data_bus <=x"20";
wait_1sec <= wait_1sec+1 ;
-- -- if ( wait_1sec=119617) then ---- .5 sec wait
-- if ( wait_1sec=110000) then ---- .5 sec wait
if ( wait_1sec=60000) then ---- .5 sec wait
-- if ( wait_1sec=6000) then ---- .5 sec wait
wait_1sec <=0 ;
-- state<=second_linedata ;
state<= input_data ; ----defualt working
-- state <=next_command;
end if ;
when time_save=>
state <= drop_lcd_e;
lcd_e <= '1';
lcd_rs <= '0';
lcd_rw_int <= '0';
data_bus <= x"02"; ----just now commented
-- data_bus <= x"80";
next_command<=message_enter;
-- next_command<=input_data;
end case ;
end if ;
end process ;
end Behavioral;-- Company:
---------------------------------------------------------------------------------------------
No comments:
Post a Comment