All pastes #274465 Raw Edit

Anonymous

public text v1 · immutable
·published 2006-12-10 19:04 UTC
rendered paste body
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity teszt2 is
    Port
		(
			clock : in STD_LOGIC;
			SF_D : out STD_LOGIC_VECTOR(3 downto 0);
			LCD_E : out STD_LOGIC;
			LCD_RW : out STD_LOGIC;
			LCD_RS : out STD_LOGIC;
			SF_CE0 : out STD_LOGIC
		);
end teszt2;

architecture Behavioral of teszt2 is

signal CTR : STD_LOGIC_VECTOR(24 downto 0);
signal allapot: std_logic;
type lcd_state_enum is ( start, first, second, third, fourth, function_set, function_set_sendcmd, entry_mode_set, entry_mode_set_sendcmd, display_on, display_on_sendcmd, to_clear, to_clear_sendcmd, operational );
signal lcd_state, next_state : lcd_state_enum := start;
signal lcd_counter : STD_LOGIC_VECTOR(19 downto 0) := CONV_STD_LOGIC_VECTOR(0,20);
signal next_lcd_counter : STD_LOGIC_VECTOR(19 downto 0) := CONV_STD_LOGIC_VECTOR(0,20);

begin
	LCD_RW <= '0';
	SF_CE0 <= '1';
	assign_next_state : process( clock )
	begin
		if( rising_edge( clock ) ) then
			lcd_state <= next_state;
		end if;
	end process;
	assign_next_counter : process( clock, next_lcd_counter )
	begin
		if( rising_edge( clock ) )
		then
			lcd_counter <= next_lcd_counter;
		end if;
	end process;
	get_next_state : process( lcd_state )
	begin
		next_lcd_counter <= lcd_counter + 1;
		next_state <= lcd_state;
		LCD_E <= '0';
		SF_D <= "0000";
		LCD_RS <= '0';

		case lcd_state is

			when start =>
			   if( lcd_counter = CONV_STD_LOGIC_VECTOR(750000,20) )
				then
					next_state <= first;
					next_lcd_counter <= CONV_STD_LOGIC_VECTOR(0,20);
				end if;

			when first =>
				if( lcd_counter < CONV_STD_LOGIC_VECTOR(12,20) )
				then
					SF_D <= "0011";
					LCD_E <= '1';
				elsif( lcd_counter = CONV_STD_LOGIC_VECTOR(205000,20) )
				then
					next_state <= second;
					next_lcd_counter <= CONV_STD_LOGIC_VECTOR(0,20);
				end if;
				
			when second =>
				if( lcd_counter < CONV_STD_LOGIC_VECTOR(12,20) )
				then
					SF_D <= "0011";
					LCD_E <= '1';
				elsif( lcd_counter = CONV_STD_LOGIC_VECTOR(5000,20) )
				then
					next_state <= third;
					next_lcd_counter <= CONV_STD_LOGIC_VECTOR(0,20);
				end if;
				
			when third =>
				if( lcd_counter < CONV_STD_LOGIC_VECTOR(12,20) )
				then
					SF_D <= "0011";
					LCD_E <= '1';
				elsif( lcd_counter = CONV_STD_LOGIC_VECTOR(2000,20) )
				then
					next_state <= fourth;
					next_lcd_counter <= CONV_STD_LOGIC_VECTOR(0,20);
				end if;
				
			when fourth =>
				if( lcd_counter < CONV_STD_LOGIC_VECTOR(12,20) )
				then
					SF_D <= "0010";
					LCD_E <= '1';
				elsif( lcd_counter = CONV_STD_LOGIC_VECTOR(2000,20) )
				then
					next_state <= function_set;
					next_lcd_counter <= CONV_STD_LOGIC_VECTOR(0,20);
				end if;
				
			when function_set =>
			   LCD_E <= '1';
				LCD_RW <= '0';
				if( lcd_counter > CONV_STD_LOGIC_VECTOR(2,20) )
				then
					next_state <= function_set_sendcmd;
					next_lcd_counter <= CONV_STD_LOGIC_VECTOR(0,20);
				end if;

			when function_set_sendcmd =>
				LCD_E <= '1';
				LCD_RW <= '0';
				if( lcd_counter < 13 )
				then
					SF_D <= "0010";
				elsif( lcd_counter = 13 )
				then
					SF_D <= "1000";
				elsif( lcd_counter = 14 )
				then
					next_state <= entry_mode_set;
					next_lcd_counter <= CONV_STD_LOGIC_VECTOR(0,20);
				end if;
				
			when entry_mode_set =>
			   LCD_E <= '1';
				LCD_RW <= '0';
				if( lcd_counter > CONV_STD_LOGIC_VECTOR(2,20) )
				then
					next_state <= entry_mode_set_sendcmd;
					next_lcd_counter <= CONV_STD_LOGIC_VECTOR(0,20);
				end if;

			when entry_mode_set_sendcmd =>
				LCD_E <= '1';
				LCD_RW <= '0';
				if( lcd_counter < 13 )
				then
					SF_D <= "0000";
				elsif( lcd_counter = 13 )
				then
					SF_D <= "0100";
				elsif( lcd_counter = 14 )
				then
					next_state <= display_on;
					next_lcd_counter <= CONV_STD_LOGIC_VECTOR(0,20);
				end if;
				
			when display_on =>
			   LCD_E <= '1';
				LCD_RW <= '0';
				if( lcd_counter > CONV_STD_LOGIC_VECTOR(2,20) )
				then
					next_state <= display_on_sendcmd;
					next_lcd_counter <= CONV_STD_LOGIC_VECTOR(0,20);
				end if;

			when display_on_sendcmd =>
				LCD_E <= '1';
				LCD_RW <= '0';
				if( lcd_counter < 13 )
				then
					SF_D <= "0000";
				elsif( lcd_counter = 13 )
				then
					SF_D <= "1000";
				elsif( lcd_counter = 14 )
				then
					next_state <= to_clear;
					next_lcd_counter <= CONV_STD_LOGIC_VECTOR(0,20);
				end if;
				
			when to_clear =>
			   LCD_E <= '1';
				LCD_RW <= '0';
				if( lcd_counter > CONV_STD_LOGIC_VECTOR(2,20) )
				then
					next_state <= to_clear_sendcmd;
					next_lcd_counter <= CONV_STD_LOGIC_VECTOR(0,20);
				end if;
			
			when to_clear_sendcmd =>
				LCD_E <= '1';
				LCD_RW <= '0';
				if( lcd_counter < 13 )
				then
					SF_D <= "0000";
				elsif( lcd_counter = 13 )
				then
					SF_D <= "0001";
				elsif( lcd_counter = 14 )
				then
					next_state <= operational;
					next_lcd_counter <= CONV_STD_LOGIC_VECTOR(0,20);
				end if;

			when operational =>
				next_state <= lcd_state;

		end case;	
	end process;

end Behavioral;