• Pic® Basic


  • PPRINT Enabling Variable Fonts on a Graphic LCD

    By Tim Box
    Nov 03

    While working a project using a graphical LCD, I was thinking that the display would look better if the font was a little bigger, thus Pprint was conceived. At first it was a simple basic program that obliterated all other print around it and generating the font was a laborious affair, even to make one character. A call to the gang on the forum produced a little program by MACPAD called Fontconverter. This code enabled you to take any PC font and converted it into the Cdata tables required to make Pprint work. From there I enhanced Pprint to mask the new print onto the data already on the screen, proud of my work I posted it back to the Forum for all to enjoy. That is as far it as it would have gone, a basic program that required you to send each character in turn to the routine.
    But I had not reckoned on Les doing his magic, over the months since then Les has enhanced my code and converted Proton+ to work with Pprint to enable seamless printing in just about any font you could imagine. Fontconverter has not stood still either, with MACPAD adding more and more functionally until Oliver took on the mantel and produced the program we use today.
    That’s the story, but what about the code and how do you use it.
    GLCD_EXTERNAL_PRINT = PPRINT
    By issuing this command the compiler disables its own print routines and loads in the code stored in PPRINT.INC (which can be found in you INC folder). From there on you will notice very little. All normal print commands work, as you would expect, the exceptions being CURSOR, AT and PRINT FONT.
    Printing normally works on a byte bounders on the Y axis and in 6 pixel points on the X axis, so limiting the possible positions to 0 –7 and 0 to 20 respectably.
    PPRINT by comparison enables you to print AT individual pixels, hence the name Pprint or Pixel Print.
    PRINT AT ypos (0 to 63),xpos (0 to 123) Position the cursor on the LCD
    CURSOR is now addressable to individual pixels
    CURSOR ypos (0 to 63),xpos (0 to 123) Position the cursor on the LCD
    Where values 0,0 will be the top left corner of the LCD.
    PRINT FONT X
    Normally X would be a number but as the font now has a name you use that.
    PRINT FONT times_bold14
    The label name can be found at the top of the font. If you have just used Fonfconverter, it is also possible to paste the full line, included the name of the font by pressing .
    The printing reference point for each character is defined as the top left pixel of the character. As an example, a font 14 pixels high when printed AT 0,0 will generate a character that will extend down to the 14th pixel on the GLCD display.
    Masking is provided so only those pixels visible on the screen are printed. Printing to position 60 with a 14 pixel high font will result in only the top 4 pixels of that character being displayed.
    As Pprint integrates so seamlessly in to Proton+ all the normal Print modifiers work with no modifications: -
    BIN{1..32} Display binary digits
    DEC{1..10} Display decimal digits
    HEX{1..8} Display hexadecimal digits
    SBIN{1..32} Display signed binary digits
    SDEC{1..10} Display signed decimal digits
    SHEX{1..8} Display signed hexadecimal digits
    IBIN{1..32} Display binary digits with a preceding '%' identifier

    IDEC{1..10} Display decimal digits with a preceding '#' identifier
    IHEX{1..8} Display hexadecimal digits with a preceding '$' identifier
    ISBIN{1..32} Display signed binary digits with a preceding '%' identifier
    ISDEC{1..10} Display signed decimal digits with a preceding '#' identifier
    ISHEX{1..8} Display signed hexadecimal digits with a preceding '$' identifier

    REP c\n Display character c repeated n times
    STR array\n Display all or part of an array

    CSTR cdata Display string data defined in a CDATA statement.

    INVERSE 0-1 Invert the characters sent to the GLCD
    OR 0-1 OR the new character with the original
    XOR 0-1 XOR the new character with the original

    Here are some examples
    In this first routine we force Proton+ to use Pprint and include a font to use, in the following examples I have omitted it
    INCLUDE"PROTON_G4.INT" ' INCLUDE THE PROTON BOARD DEFAULTS
    GLCD_EXTERNAL_PRINT=PPRINT
    PRINT FONT ARIAL____12
    CLS
    PRINT CSTR TEXT1
    PRINT CSTR TEXT2
    PRINT CSTR TEXT3
    STOP
    TEXT1:
    CDATA"HELLO WORLD" , 0
    TEXT2:
    CDATA"HOW ARE YOU?" , 0
    TEXT3:
    CDATA"I AM FINE!" , 0
    INCLUDE"ARIAL_12.FNT"

    DIM FLT ASFLOAT
    FLT = -
    3.1456832
    PRINT DEC5 FLT ' DISPLAY 5 VALUES AFTER THE DECIMAL POINT
    DIM MYARRAY [10] ASBYTE ' CREATE A 10-BYTE ARRAY.
    STR MYARRAY =
    "HELLO" ' LOAD THE FIRST 5 BYTES OF THE ARRAY
    PRINT STR MYARRAY \5 ' SEND 5-BYTE STRING.

    PRINTAT0,0, "Hello"
    PRINT INVERSE 1 ' NOW PRINT INVERTED
    PRINTAT20,0, "Hello"
    STOP
    PPRINT FONT CONSTRUCTION
    Fonts from 1x1 to 24 x 128 can be displayed using PPRINT.
    The font is constructed by a series of vertical byte’s that are fixed for all characters in that font. However each character can vary in width as required.
    The constructs of the font are :-
    The first value is the font height in pixels
    The next section of words is used as a lookup table to the address of the character data with in the table. The use of variable width fonts necessitates the use of this look up table. With the 16 series PIC® (16f877 for example) this word is stored as a 14 bit value in ROM, this method not only increases the speed of the routine but saves data space as well. 18 series PIC® are saved in byte chunks, but due to the 16 bit ROM all data is stored very compactly when it comes to the core font data.
    TIMES_BOLD14:-

    CDATA14 ; Font is 14 pixels high
    CDATA TIMES_BOLD_0,TIMES_BOLD_1 ...
    ...
    TIMES_BOLD_0:-
    CDATA2,0,0,0,0,0' Code for char
    TIMES_BOLD_1:-
    CDATA4,0,0,30,3,126,3,0,0,0' Code for char !
    The actual data for each character is constructed by first identifying the character length in pixels followed by the data which represents the character in vertically arranged bytes. If you look at Fig x you will see that byte 0 bit one is the top left of the character, byte 1 is next describing the lower 8 bits, byte 2 is the top or the next column….
    The normal design for the character is to have no space at the start of the character just at the end.


    An example of how a 12 x 6 pixel high character is constructed
    A font can be up to 3 bytes tall (24 pixels) and each character up to 255 bytes wide (no point making it any bigger than 128 though as you can view only 128 Pixels at once).
    Fonts though take a lot of ROM space and you might want to reduce the font data to just cover the characters required. For details of how to do it look here

    USING FONTCONVERTER
    If you have not already done so Fontonverter should be saved to the ….INC\ EXTERNAL PROGRAMS folder. This will enable you to access the program easily from within the editor .










    Fontconverter can be used in two modes, Basic and Advanced. When using Basic mode you can down load the converted font directly into to the program you are writing. Simply open Fontconverter, choose the font and hit the convert button. Once the conversion has finished you can Quit. On return to the Editor the converted font is placed where you left your cursor.
    There is also a small 'extra'. After the previous step and by placing the cursor at the position where you need the "PRINT FONT" statement and pressing , you will automatically paste the correct sentence and font name as it was stored in the clipboard.
    The 'Configuration' menu gives the ability to make Fontconverter compatible with PROTON PLUS V2.11 or V2.13 and up.


    Advanced mode enables you place greater control over the creation of the font. As understanding how to use the Advanced mode requires a lot of explanation I will leave it to for another article.


    Some screen captures from Isis* simulating a basic program running on a 16F877 and a GLCD to show some font printing in action.

    Big Numbers

    A Hand writing font

    Over lapping print by using the OR modifier

    Inverting with PRINT INVERSE 1
    Download the Manual Inset for PPRINT Here
    Down load the latest Version of Fontconverter Here
    * Isis is a schematic capture and SPICE simulator from Labcenter Electronics
    November 03
    (Last edition: 17/11/03)
    Tim
  • Recent Activity

    John Drew-26

    Microsoft security essentials blues

    Thread Starter: shantanu@india

    Hi, A strange thing happened just now.My Windows 7 Micrsoft Sercurity Essentials suddenly gave a warning that prplus.exe(Compiler) is a potential...

    John Drew Yesterday, 08:55 Go to last post
    John Lawton-121

    SPI mssp

    Thread Starter: picprotonguy

    Just ordered Digital to Analog IC MCP4822 with SPI interface and immediately opened proton manual. I'm very disappointed, it looks like Proton...

    John Lawton Yesterday, 11:32 Go to last post
    John Drew-26

    IR Sensor Codes in Proton IDE

    Thread Starter: Mesgu

    Hello guys can someone help me plsssss... How to write a codes for IR sensor in proton ide? given: Transmitter = portb.1 Receiver = portb.0 Led...

    John Drew Today, 03:12 Go to last post
    picprotonguy-1827

    working weird

    Thread Starter: rverm

    Device = 18F2220 Xtal 4 TRISA = 111 TRISB = 0 TRISC = 0 Declare CCP1_Pin PORTC.2 ' Select Hpwm port and bit for CCP1 module. 'Declare CCP2_Pin...

    picprotonguy Yesterday, 08:03 Go to last post
    mhanley-1294

    18F47J13 or 18F47J53 Definition Files

    Thread Starter: mhanley

    Hi, I want to use either the 18F47J13 or 18F47J53 but Proton does not have a definition file for either micro. I need the extra program...

    mhanley Yesterday, 09:57 Go to last post