Question

I found this code which controls an LCD display of an FPGA but it can't seen to understand some of the code, in particular this part

    type LCD_CMDS_T is array(integer range <>) of std_logic_vector(9 downto 0);
    constant LCD_CMDS : LCD_CMDS_T := ( 0 => "00"&X"3C",            --Function Set
                        1 => "00"&X"0C",                --Display ON, Cursor OFF, Blink OFF
                        2 => "00"&X"01",                --Clear Display
                        3 => "00"&X"02",            --return home

                        4 => "10"&X"48",            --H 
                        5 => "10"&X"65",            --e
                        6 => "10"&X"6C",            --l
                        7 => "10"&X"6C",            --l
                        8 => "10"&X"6F",            --o
                        9 => "10"&X"20",            --blank
                        10 => "10"&X"46",           --F
                        11 => "10"&X"72",           --r
                        12 => "10"&X"6F",           --o
                        13 => "10"&X"6D",           --m

                        14 => "10"&X"20",           --blank

                        15 => "10"&X"44",           --D
                        16 => "10"&X"69",           --i
                        17 => "10"&X"67",           --g
                        18 => "10"&X"69",           --i
                        19 => "10"&X"6C",           --l
                        20 => "10"&X"65",           --e
                        21 => "10"&X"6E",           --n
                        22 => "10"&X"74",           --t
                        23 => "00"&X"18");          --Shift left


signal lcd_cmd_ptr : integer range 0 to LCD_CMDS'HIGH + 1 := 0;

I understand that an array has been made to hold values of character to be displayed on the display. but i don't understand this line.

signal lcd_cmd_ptr : integer range 0 to LCD_CMDS'HIGH + 1 := 0;

Can anyone help me to understand whats done here

Was it helpful?

Solution

This signal is being created to index into the string that was created. The constant LCD_CMDS is an array that needs to be indexed. The signal lcd_cmd_ptr is indexing into that constant to drive the display. It is an integer than can be from 0 to 23 in this case.

I bet somewhere there's a line that has: LCD_CMDS(lcd_cmd_ptr)

OTHER TIPS

signal lcd_cmd_ptr : integer range 0 to LCD_CMDS'HIGH + 1 := 0;

This code defines a signal which can range from 0 to 'whatever the highest index in the LCD_CMDS array is + 1'.

The 'tick' attributes in VHDL are very useful for writing generic code. To be completely generic, the line above ought to be:

signal lcd_cmd_ptr : integer range LCD_CMDS'low  to LCD_CMDS'HIGH + 1;

then if someone removed the entry for item 0 in the array, the signal would have a more limited range. Note that explicitly initialising to '0' in the original case and to LCD_CMDS'LOW in the most generic case is not necessary. The VHDL spec guarantees that integers are always initialised to the lowest value they are allowed to have.

If the signal above only needed to go up to the highest value in the array, you could write more concisely:

signal lcd_cmd_ptr : integer range LCD_CMDS'range;

Again, no explicit initialisation required.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top