Displaying Arbitrary Characters on a VGA Display

Trevor Semeniuk, Winter 2001

Code                     Code Discussion                  Pin Assignment

    Introductionline


This application note will provide an easy method of displaying arbitrary characters on a VGA display. This code was used in our binary keyboard project and provides a method for displaying characters by sending the ASCII code of the character to be displayed, and an enable signal when it is to be displayed.

The characters are stored in a RAM buffer as they are entered, which was arbitrarily set to hold 256 characters. Each character will appear to the right of the last displayed character, unless a backspace character is received thus causing the cursor to move left one character. The code implements carriage returns at the end of the screen and recognition of the screen bottom. Unfortunately, the previous character does not stay on the screen when a new character is presented, which is a persistent bug in the code and must be fixed for this code to be truly useful.

An understanding of VGA operation is assumed, which can be gained from the Dicerace Project of 1998, or the updated VGA application note from the Probe Display Project of 2000. My code and application note is built only with reference to the Dicerace code which was found to be quite intuitive and useful.


    Code


Please download the .zip package of the required code. Four pieces of code are required for displaying characters:

chardisplay.vhd – This is the top level package which controls the other 3 code files , and accepts the ASCII data and enable signal.

screen_data.vhd – This file is where the data to be displayed is defined, including what to display, where on the screen to display it, and when to display it.

count_xy.vhd – This code file was used from the Dicerace Project without modification, please see that website for references.

syncgen.vhd – This code file was used from the Dicerace Project without modification, please see that website for references.


In addition to these, two .mif files are required which load the character ROM with the character set and fixed message:

char_set.mif – This file contains the character set which defines which character on the screen corresponds to the input data. The character set is loaded into ROM during configuration. This code file was used from the Dicerace Project without modification, please see that website for further information.

title_msg.mif – Defines a constant title which is displayed above the character data. In our case the title reads, "EE552 PROJECT BINARY KEYBOARD" If this is not desired this file can be disregarded and the screen data code easily modified to eliminate a title message.


    Discussion of Code


chardisplay.vhd


For this package (see listing One), four signals must be assigned:

entity chardisplay is

Port(

clock : in std_logic;

vga_h_sync, vga_v_sync : out boolean;

reset : in std_logic;

data_ready : in std_logic;

data_in : in std_logic_vector(7 downto 0);

vga_red, vga_green, vga_blue : out boolean

);

end chardisplay;

Listing One: Entity declaration for Chardisplay


Clock is assigned to the common clock, and reset can be assigned to a pushbutton or any other pin desired. The reset is not entirely necessary and if this functionality is not desired it can be neglected.

Data_in is the 7 bit ASCII data which defines the character to be displayed. A very important note about data_in is that despite it being an 8 bit signal, the most significant 2 bits are dropped later on since a full ASCII character set is not defined by this code. In order to use the full 127 ASCII characters, it would be necessary to modify char_set.mif and add in the additional characters desired (which would be a daunting task for any mortal).

Data_ready must be set high when the ASCII data is put onto the bus and must remain high for at least one clock cycle. There is no maximum length for data_ready since the character will not be sent to the screen until data_ready goes low again. This will be explained later on when screen_data.vhd is looked at. Another note is data_ready high worked for my implementation, but if a pushbutton or other signal is to be used to signify the data_ready signal it would be best to set data_ready to active low, like reset.

The remaining code in chardisplay.vhd simply defines the package structure for incorporating the four files together.


screen_data.vhd

A large part of this code was modified from the Dicerace Project and will not be discussed.

The first part of this code which is additional to the Dicerace code is the implementation of RAM as a character buffer. When characters are received, they are written to ram in the consecutive spots (LPM_DQ ram functions as a two dimensional array, so that ram address 1 corresponds to character one, ram address 2 corresponds to character two, etc). The RAM size is set be the generic ram_address_width so that the number of characters which the RAM will hold before overwriting the first character is defined as 2 ram_address_width .

Writing to the RAM is achieved by setting the address of RAM which is to be written to, setting WE (write enable) high, then assigning the character data (ASCII data minus 2 MSB's) to ram_data_in. Reading from RAM is similar, except WE is not used; therefore, the address is set, then that data from ram_data_out is read.

In order to display the characters from RAM on the screen, the same method is used as for the Dicerace Project, expect instead of reading from ROM the data is read from RAM.


    Pin Assignments

The following pin assignments were used with a Flex 10k20 and UP1 Board. The order of ASCII Data pins is fairly arbitrary since it is dependent on whether you will be using active low or active high data. The placement of these data pins on the UP1 board is also arbitrary, therefore, use this only as a suggestion.

Use Signal Max+Plus2 Pin Assignment UP1 Board Designation




Common Clock Clock 91 Global Clock Pin
Common Reset Reset 28 Flex Push Button 1




ASCII Data 6 data_in6 63 Flex Expansion A - Hole 27
ASCII Data 5 data_in5 61 Flex Expansion A - Hole 25
ASCII Data 4 data_in4 55 Flex Expansion A - Hole 23
ASCII Data 3 data_in3 53 Flex Expansion A - Hole 21
ASCII Data 2 data_in2 50 Flex Expansion A - Hole 19
ASCII Data 1 data_in1 48 Flex Expansion A – Hole 17
ASCII Data 0 data_in0 45 Flex Expansion A - Hole 15




Red Gun vga_red 236 VGA connector
Green Gun vga_green 237 VGA connector
Blue Gun vga_blue 238 VGA connector
HSync vga_h_sync 239 VGA connector
VSync vga_v_sync 240 VGA connector