------------------------------------------------------------------------

-- File: char_generator.vhd

--

-- Group: Korrey Scott 237118

-- Milton Mah 341428

-- Mike Holden 346386

--

-- Course: EE 552

-- Project: ASM

-- Instructor: Dr. Duncan Elliott

-- Completed: Apr. 3, 1998

------------------------------------------------------------------------

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_arith.all;

use ieee.std_logic_unsigned.all;

use ieee.all;

------------------------------------------------------------------------

-- Entity: char_generator

--

-- Inputs: state_vector: input from the state_machine module giving the

-- current state of the system

-- data1: input from the state_machine module holding the data of

-- the current state (holds the minutes in clock state)

-- data2: hold the hours in clock state

--

-- Outputs: top_line_cols: 8-bit ASCII codes sent to the write_lcd module

-- generated from the data1 and data2 numbers

-- bottom_line_cols: 8-bit ASCII codes sent to the write_lcd module

------------------------------------------------------------------------

entity char_generator is

generic ( max_vector : positive := 7 );

port ( state_vector : in std_logic_vector (2 downto 0);

data1: in std_logic_vector (7 downto 0);

data2: in std_logic_vector (3 downto 0);

direct2: in std_logic_vector (2 downto 0);

top_line_col_1: out std_logic_vector (7 downto 0);

top_line_col_2: out std_logic_vector (7 downto 0);

top_line_col_3: out std_logic_vector (7 downto 0);

top_line_col_4: out std_logic_vector (7 downto 0);

top_line_col_5: out std_logic_vector (7 downto 0);

top_line_col_6: out std_logic_vector (7 downto 0);

top_line_col_7: out std_logic_vector (7 downto 0);

top_line_col_8: out std_logic_vector (7 downto 0);

bottom_line_col_1: out std_logic_vector (7 downto 0);

bottom_line_col_2: out std_logic_vector (7 downto 0);

bottom_line_col_3: out std_logic_vector (7 downto 0);

bottom_line_col_4: out std_logic_vector (7 downto 0);

bottom_line_col_5: out std_logic_vector (7 downto 0)

);

end char_generator;

------------------------------------------------------------------------

-- Architecture: behaviour of char_generator

--

-- Description: The purpose of this module is to calculate the ASCII codes

-- needed by the write_lcd module to write the data of the current

-- state to the LCD.

------------------------------------------------------------------------

architecture behaviour of char_generator is

constant A : std_logic_vector(7 downto 0) := "01000001";

constant C : std_logic_vector(7 downto 0) := "01000011";

constant D : std_logic_vector(7 downto 0) := "01000100";

constant E : std_logic_vector(7 downto 0) := "01000101";

constant G : std_logic_vector(7 downto 0) := "01000111";

constant H : std_logic_vector(7 downto 0) := "01001000";

constant I : std_logic_vector(7 downto 0) := "01001001";

constant J : std_logic_vector(7 downto 0) := "01001010";

constant K : std_logic_vector(7 downto 0) := "01001011";

constant L : std_logic_vector(7 downto 0) := "01001100";

constant M : std_logic_vector(7 downto 0) := "01001101";

constant N : std_logic_vector(7 downto 0) := "01001110";

constant O : std_logic_vector(7 downto 0) := "01001111";

constant P : std_logic_vector(7 downto 0) := "01010000";

constant R : std_logic_vector(7 downto 0) := "01010010";

constant S : std_logic_vector(7 downto 0) := "01010011";

constant T : std_logic_vector(7 downto 0) := "01010100";

constant U : std_logic_vector(7 downto 0) := "01010101";

constant V : std_logic_vector(7 downto 0) := "01010110";

constant W : std_logic_vector(7 downto 0) := "01010111";

constant Y : std_logic_vector(7 downto 0) := "01011001";

constant SP : std_logic_vector(7 downto 0) := "00100000";

constant COLON : std_logic_vector(7 downto 0) := "00111010";

begin

create_chars : process(state_vector)

variable temp : std_logic_vector(7 downto 0);

variable temp_result : std_logic_vector(7 downto 0);

variable data1_copy : std_logic_vector(7 downto 0);

variable data2_copy : std_logic_vector(3 downto 0);

variable ones_of_hours : std_logic_vector(7 downto 0);

variable tens_of_hours : std_logic_vector(7 downto 0);

variable ones_of_minutes : std_logic_vector(7 downto 0);

variable tens_of_minutes : std_logic_vector(7 downto 0);

constant TEN : std_logic_vector(7 downto 0) := "00001010";

variable ones : std_logic_vector(7 downto 0);

variable tens : std_logic_vector(7 downto 0);

variable hundreds : std_logic_vector(7 downto 0);

variable thousands : std_logic_vector(7 downto 0);

variable state_vector_copy : std_logic_vector(2 downto 0);

begin

if state_vector = "001" then

-- we are in clock state

top_line_col_1 <= C;

top_line_col_2 <= L;

top_line_col_3 <= O;

top_line_col_4 <= C;

top_line_col_5 <= K;

top_line_col_6 <= SP;

top_line_col_7 <= SP;

top_line_col_8 <= SP;

-- getting ones of tens of hours

data2_copy := data2;

ones_of_hours := "00000000";

tens_of_hours := "00000000";

for i in 3 downto 0 loop

-- shifting ones_of_hours

tens_of_hours := tens_of_hours + tens_of_hours;

tens_of_hours(0) := data2_copy(i); -- shifting dividend into temp

if tens_of_hours < TEN then

ones_of_hours(i) := '0';

else

ones_of_hours(i) := '1';

tens_of_hours := (tens_of_hours - TEN);

end if;

end loop;

-- getting ones and tens of minutes

data1_copy := data1;

ones_of_minutes := "00000000";

tens_of_minutes := "00000000";

for i in 5 downto 0 loop

-- shifting tens_of_minutes

tens_of_minutes := tens_of_minutes + tens_of_minutes;

tens_of_minutes(0) := data1_copy(i); -- shifting dividend into temp

if tens_of_minutes < TEN then

ones_of_minutes(i) := '0';

else

ones_of_minutes(i) := '1';

tens_of_minutes := (tens_of_minutes - TEN);

end if;

end loop;

bottom_line_col_1 <= tens_of_hours + "00110000";

bottom_line_col_2 <= ones_of_hours + "00110000";

bottom_line_col_3 <= COLON;

bottom_line_col_4 <= tens_of_minutes + "00110000";

bottom_line_col_5 <= ones_of_minutes + "00110000";

elsif state_vector = "101" then

-- we are displaying direction

top_line_col_4 <= T;

top_line_col_6 <= SP;

top_line_col_7 <= SP;

top_line_col_8 <= SP;

bottom_line_col_5 <= SP;

case direct2 is

when "000" => -- North

top_line_col_1 <= N;

top_line_col_2 <= O;

top_line_col_3 <= R;

top_line_col_5 <= H;

bottom_line_col_1 <= SP;

bottom_line_col_2 <= SP;

bottom_line_col_3 <= SP;

bottom_line_col_4 <= SP;

when "001" => -- North East

top_line_col_1 <= N;

top_line_col_2 <= O;

top_line_col_3 <= R;

top_line_col_5 <= H;

bottom_line_col_1 <= E;

bottom_line_col_2 <= A;

bottom_line_col_3 <= S;

bottom_line_col_4 <= T;

when "010" => -- East

top_line_col_1 <= E;

top_line_col_2 <= A;

top_line_col_3 <= S;

top_line_col_5 <= SP;

bottom_line_col_1 <= SP;

bottom_line_col_2 <= SP;

bottom_line_col_3 <= SP;

bottom_line_col_4 <= SP;

when "011" => -- South East

top_line_col_1 <= S;

top_line_col_2 <= O;

top_line_col_3 <= U;

top_line_col_5 <= H;

bottom_line_col_1 <= E;

bottom_line_col_2 <= A;

bottom_line_col_3 <= S;

bottom_line_col_4 <= T;

when "100" => -- South

top_line_col_1 <= S;

top_line_col_2 <= O;

top_line_col_3 <= U;

top_line_col_5 <= H;

bottom_line_col_1 <= SP;

bottom_line_col_2 <= SP;

bottom_line_col_3 <= SP;

bottom_line_col_4 <= SP;

when "101" => -- South West

top_line_col_1 <= S;

top_line_col_2 <= O;

top_line_col_3 <= U;

top_line_col_5 <= H;

bottom_line_col_1 <= W;

bottom_line_col_2 <= E;

bottom_line_col_3 <= S;

bottom_line_col_4 <= T;

when "110" => -- West

top_line_col_1 <= W;

top_line_col_2 <= E;

top_line_col_3 <= S;

top_line_col_5 <= SP;

bottom_line_col_1 <= SP;

bottom_line_col_2 <= SP;

bottom_line_col_3 <= SP;

bottom_line_col_4 <= SP;

when others => -- North West

top_line_col_1 <= N;

top_line_col_2 <= O;

top_line_col_3 <= R;

top_line_col_5 <= H;

bottom_line_col_1 <= W;

bottom_line_col_2 <= E;

bottom_line_col_3 <= S;

bottom_line_col_4 <= T;

end case;

else

-- we are either displaying Mileage or Velocity

if state_vector = "011" then

top_line_col_1 <= M;

top_line_col_2 <= I;

top_line_col_3 <= L;

top_line_col_4 <= E;

top_line_col_5 <= A;

top_line_col_6 <= G;

top_line_col_7 <= E;

top_line_col_8 <= SP;

else -- "111"

top_line_col_1 <= V;

top_line_col_2 <= E;

top_line_col_3 <= L;

top_line_col_4 <= O;

top_line_col_5 <= C;

top_line_col_6 <= I;

top_line_col_7 <= T;

top_line_col_8 <= Y;

end if;

-- calculating the digits from a number of at most 255

data1_copy := data1;

ones := "00000000";

tens := "00000000";

hundreds := "00000000";

thousands := "00000000";

for i in 7 downto 0 loop

ones := ones + ones;

ones(0) := data1_copy(i);

tens := tens + tens;

thousands := thousands + thousands;

if ones < TEN then

tens(0) := '0';

else

tens(0) := '1';

ones := ones - TEN;

end if;

if tens < TEN then

thousands(0) := '0';

else

thousands(0) := '1';

tens := tens - TEN;

end if;

if thousands < TEN then

hundreds(i) := '0';

else

hundreds(i) := '1';

thousands := thousands - TEN;

end if;

end loop;

-- need to add "00110000" to get the ASCII code

bottom_line_col_1 <= "00110000";

bottom_line_col_2 <= hundreds + "00110000";

bottom_line_col_3 <= tens + "00110000";

bottom_line_col_4 <= ones + "00110000";

bottom_line_col_5 <= SP;

end if;

end process create_chars;

end behaviour;