- Joined
- Oct 18, 2007
- Messages
- 4
- Reaction score
- 0
Hi there,
I would like to display an integer variable on a LCD display. I am using the Altera DE2 development board which uses the Crystal Fontz HD44780 LCD display. The LCD driver seems to be working fine, because it displays values if I send it in binary form. Below is the code for the variable and LCD display:
CONSTANT COUNTER_LENGTH : NATURAL := 14;
SIGNAL counter : INTEGER := 0;
-- Process that determines the number of clock cycles between
-- loading the code and successful cross-correlation.
count_clk_cycles: PROCESS (EXT_CLOCK, reset, clk_Xcode, loaded, xcorr)
VARIABLE str_counter : STRING (COUNTER_LENGTH downto 1);
VARIABLE success : STD_LOGIC := '0';
BEGIN
--Resets the timer.
IF reset = '0' THEN
counter <= 0;
FOR i in 0 to COUNTER_LENGTH-1 LOOP
clk_Xcode(i) <= X"0";
time_Xcode(i) <= X"0";
END LOOP;
--14-Digit timer counts up every rising edge of clock.
ELSIF (EXT_CLOCK'EVENT AND EXT_CLOCK = '1') THEN
IF (loaded = '1' AND xcorr = '0') THEN
counter <= counter + 1;
END IF;
IF (loaded = '1' AND xcorr = '1') THEN
str_counter := fix(INTEGER'IMAGE(counter));
FOR i in 1 to CODE_LENGTH LOOP
CASE str_counter(i) is
WHEN '0' =>
time_Xcode(i-1) <= X"0";
WHEN '1' =>
time_Xcode(i-1) <= X"1";
WHEN '2' =>
time_Xcode(i-1) <= X"2";
WHEN '3' =>
time_Xcode(i-1) <= X"3";
WHEN '4' =>
time_Xcode(i-1) <= X"4";
WHEN '5' =>
time_Xcode(i-1) <= X"5";
WHEN '6' =>
time_Xcode(i-1) <= X"6";
WHEN '7' =>
time_Xcode(i-1) <= X"7";
WHEN '8' =>
time_Xcode(i-1) <= X"8";
WHEN '9' =>
time_Xcode(i-1) <= X"9";
WHEN OTHERS =>
time_Xcode(i-1) <= X"F";
END CASE;
END LOOP;
END IF;
END IF;
END PROCESS;
The idea of the code is to convert the integer variable 'counter' to a string to access the individual digits of the variable. The corresponding binary code for each digit is then stored in a 2D array 'time_Xcode' which is sent to the LCD driver. If I give the 2D array constant values everything works fine and the LCD displays the values. When it has to convert the variable, then the LCD displays all zeros.
Any suggestions will be appreciated.
Thank you.
I would like to display an integer variable on a LCD display. I am using the Altera DE2 development board which uses the Crystal Fontz HD44780 LCD display. The LCD driver seems to be working fine, because it displays values if I send it in binary form. Below is the code for the variable and LCD display:
CONSTANT COUNTER_LENGTH : NATURAL := 14;
SIGNAL counter : INTEGER := 0;
-- Process that determines the number of clock cycles between
-- loading the code and successful cross-correlation.
count_clk_cycles: PROCESS (EXT_CLOCK, reset, clk_Xcode, loaded, xcorr)
VARIABLE str_counter : STRING (COUNTER_LENGTH downto 1);
VARIABLE success : STD_LOGIC := '0';
BEGIN
--Resets the timer.
IF reset = '0' THEN
counter <= 0;
FOR i in 0 to COUNTER_LENGTH-1 LOOP
clk_Xcode(i) <= X"0";
time_Xcode(i) <= X"0";
END LOOP;
--14-Digit timer counts up every rising edge of clock.
ELSIF (EXT_CLOCK'EVENT AND EXT_CLOCK = '1') THEN
IF (loaded = '1' AND xcorr = '0') THEN
counter <= counter + 1;
END IF;
IF (loaded = '1' AND xcorr = '1') THEN
str_counter := fix(INTEGER'IMAGE(counter));
FOR i in 1 to CODE_LENGTH LOOP
CASE str_counter(i) is
WHEN '0' =>
time_Xcode(i-1) <= X"0";
WHEN '1' =>
time_Xcode(i-1) <= X"1";
WHEN '2' =>
time_Xcode(i-1) <= X"2";
WHEN '3' =>
time_Xcode(i-1) <= X"3";
WHEN '4' =>
time_Xcode(i-1) <= X"4";
WHEN '5' =>
time_Xcode(i-1) <= X"5";
WHEN '6' =>
time_Xcode(i-1) <= X"6";
WHEN '7' =>
time_Xcode(i-1) <= X"7";
WHEN '8' =>
time_Xcode(i-1) <= X"8";
WHEN '9' =>
time_Xcode(i-1) <= X"9";
WHEN OTHERS =>
time_Xcode(i-1) <= X"F";
END CASE;
END LOOP;
END IF;
END IF;
END PROCESS;
The idea of the code is to convert the integer variable 'counter' to a string to access the individual digits of the variable. The corresponding binary code for each digit is then stored in a 2D array 'time_Xcode' which is sent to the LCD driver. If I give the 2D array constant values everything works fine and the LCD displays the values. When it has to convert the variable, then the LCD displays all zeros.
Any suggestions will be appreciated.
Thank you.