hobbyiclearner
Full Member level 2
Hello there,
I was going through a LCD controller code and have the following query:
As I know the if else statement is a sequential construct and therefore multiple statements in either if / elsif/ else sections of a statement will execute in the order they are written. If so pls. consider the code snippet below (it basically interfaces with the lcd controller and prints '123456789' on the display).
If I have understood the code correctly, this is what it should do:
**Check for rising edge of clk. If it has occurred, checks lcd_busy and lcd_enable status. If lcd is not busy, it enables it.
**Next, it should check for the value of variable char, and if it is less than 10, starts counter and executes it till value of char is 9. Since char is a variable, it stores (or at least should store) its last value ie. 9
**Next, the case statement is executed. Since the value stored in char is 9, the lcd_bus should get only the last case ie
'1000111001' , the character equivalent of numeral 9. Hence the lcd should display only character 9.
When I copy pasted the code in Xilinx and implemented the lcd_controller with lcd_example, entire sequence of numbers was printed on it ie. '123456789'. What could be the reason. Where is my understanding / concept wrong pls.
The code ofr lcd_contoller is here and code for driving it, ie. the source of the above snippet is here.
Thanks for your time.
Hobbyiclearner
I was going through a LCD controller code and have the following query:
As I know the if else statement is a sequential construct and therefore multiple statements in either if / elsif/ else sections of a statement will execute in the order they are written. If so pls. consider the code snippet below (it basically interfaces with the lcd controller and prints '123456789' on the display).
Code:
PROCESS(clk)
VARIABLE char : INTEGER RANGE 0 TO 10 := 0;
BEGIN
IF(clk'EVENT AND clk = '1') THEN
IF(lcd_busy = '0' AND lcd_enable = '0') THEN
lcd_enable <= '1';
IF(char < 10) THEN
char := char + 1;
END IF;
CASE char IS
WHEN 1 => lcd_bus <= "1000110001";
WHEN 2 => lcd_bus <= "1000110010";
WHEN 3 => lcd_bus <= "1000110011";
WHEN 4 => lcd_bus <= "1000110100";
WHEN 5 => lcd_bus <= "1000110101";
WHEN 6 => lcd_bus <= "1000110110";
WHEN 7 => lcd_bus <= "1000110111";
WHEN 8 => lcd_bus <= "1000111000";
WHEN 9 => lcd_bus <= "1000111001";
WHEN OTHERS => lcd_enable <= '0';
END CASE;
ELSE
lcd_enable <= '0';
END IF;
END IF;
END PROCESS;
If I have understood the code correctly, this is what it should do:
**Check for rising edge of clk. If it has occurred, checks lcd_busy and lcd_enable status. If lcd is not busy, it enables it.
**Next, it should check for the value of variable char, and if it is less than 10, starts counter and executes it till value of char is 9. Since char is a variable, it stores (or at least should store) its last value ie. 9
**Next, the case statement is executed. Since the value stored in char is 9, the lcd_bus should get only the last case ie
'1000111001' , the character equivalent of numeral 9. Hence the lcd should display only character 9.
When I copy pasted the code in Xilinx and implemented the lcd_controller with lcd_example, entire sequence of numbers was printed on it ie. '123456789'. What could be the reason. Where is my understanding / concept wrong pls.
The code ofr lcd_contoller is here and code for driving it, ie. the source of the above snippet is here.
Thanks for your time.
Hobbyiclearner