All pastes #274186 Raw Edit

Anonymous

public text v1 · immutable
·published 2006-12-10 14:29 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
		(
			led : out STD_LOGIC;
			led2 : out STD_LOGIC;
			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;
			kapcsolo : in 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, operational, to_clear, to_clear_sendcmd );
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';
	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';
		led2 <= '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 <= to_clear;
					next_lcd_counter <= CONV_STD_LOGIC_VECTOR(0,20);
				end if;
				
			when operational =>
				led2 <= '1';
				next_state <= lcd_state;
			
			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;

		end case;
	end process;
	process( clock )
	begin
		if rising_edge( clock )
		then
			if (CTR="000000")
			then
				if( allapot = '1' ) then
					allapot <= '0';
				else
					allapot <= '1';
				end if;
			end if;
			CTR <= CTR + 1;
			if (CTR = CONV_STD_LOGIC_VECTOR(25000000,25) )
			then 
				CTR<=CONV_STD_LOGIC_VECTOR(0,25);
			end if;
		end if;
	end process;
	led <= allapot and kapcsolo;
end Behavioral;