Start
P
Is For PC/104
Easy PIC Video
MC104P Functions
Be A Hero
Sources and PDF
EASY
PIC VIDEO
One
of the real eye catchers at the MASTERs Conference
was the MC104P driving the flat panel PC display.
The video hardware behind the spectacle is shown
in Photo 2. Calmotion provides a video library for
VGA cards that employ a GD542X chipset like the
one shown in the photo. The Calmotion video library
was built using Microchip’s C18 C compiler librarian
utilities.
|

(Click
here to enalrge)
|
Photo
2—What you see here is a standard PC/104 video
card. It looks like this one may have come
from Arcom.
|
Using
the video library’s functions is simple. Simply
incorporate the calmotion_video.lib library in your
project. Call the four video functions in the library
as you need them.
There’s
another file that you must fold into the project.
The calmotion_MCP104P.lib library file contains
MC104P hardware initialization routines and other
functions that enable you to move data in the MC104P
memory and I/O areas covered in Figure 1.
For
now, let’s concentrate on the MC104P video library
and examine the code in Listing 1, which generated
the image shown in Photo 3. I’ve shown the code
behind the #include
“pc104.h” statement. As you can see, this
C include statement contains prototypes of the functions
contained in the calmotion_MCP104P.lib and calmotion_video.lib
libraries. Flowing down just before the main function
are definitions for row,
column,
foreground,
and background.
These character definitions are merely placeholders
for arguments that will be used in some of the video
function calls. The col and the x are used
in the letters.c function calls. A typical function
to form a letter is shown at the bottom of Listing
1.
|

(Click
here to enlarge)
|
Photo
3—This shot was inspired by my old mainframe
experiences. I was tapping keys on those old
glass terminals long before my hands even touched
a PC keyboard. |
The
video display area is composed of 25 rows and 80
columns. The locate function uses row and column
values to position the cursor on the screen. A value
of zero for either the row or column values doesn’t
alter the current row or column setting. Issuing
a call to the locate function in this manner, locate(1,1)
positions the cursor at the top left of the display.
The locate(25,80)
statement places the cursor at the bottom right
corner of the display. That’s simple enough.
The
color function uses foreground and background variables.
Eight shades of grey and the primary colors found
in any box of Crayola crayons can be mixed and matched
as foreground and background screen colors. For
instance, the color(0x07,0x00)
statement produces white characters against a black
background. Calmotion provides sample video code
that displays all of the possible foreground and
background color combinations.
The
first function call in Listing 1 is made to code
contained within the calmotion_MCP104P.lib file.
The init_mc104p
function initializes all of the hardware peripherals
and sets up the PC/104 bus. The MC104P’s hardware
peripherals include the board’s digital I/O ports,
the analog inputs, and any user LEDs that may be
on the MC104P PCB. This type of function is found
in the firmware of numerous SBC modules. As you
can see in this case, it’s usually a good idea to
run a function like this right off the bat.
The
video functionality provided by the add-on PC/104
card begins with a call to the init_cirrus_video
function. This function initializes the VGA foreground
and background color attributes. Also, the init_cirrus_video
function redirects the standard I/O so that the
C language printf
functions write to the video display instead
of the PIC’s USART. If you need to revert stdout
to the USART, just code stdout
= _H_USART. The stdout
= _H_USER C statement will redirect standard
I/O to the video card. As the cls
clear screen function executes, you’ll realize just
how easy putting up a PC-like alphanumeric video
image using the MC104P is going to be.
The
remainder of this little piece of video demonstration
code in Listing 1 sets up the foreground and background
colors and places the cursor initially at the home
position (1, 1) in the upper left corner of the
display. I used the locate
function in conjunction with the printf
function in the letters.c
function set to paint the display shown in Photo
3.