PIC Assembler Character Table for LCD Displays
Article Index
1. Obtaining the Ready Made Character Table
2. Building the Font Table
3. Generating the PIC Assembler Table
thumb_lcdcharactertable
Example Rendering

Using an excellent tool developed by Cosmicvoid, I've created a small font for use on LCD displays without a built in character set.

The font is designed to fit in lines 8 pixels high (font is 3-6 pixels high and is 3-5 pixels wide). I took the original font supplied with the editor and shrunk it as much as I could. The example on the left is rendered on a 128x64 pixel screen and you can see there's a lot of room for text.

The display is the interface of a touchscreen project I'm working on and is part of the excellent EA DOG series available here.

1. Obtaining the Ready Made Character Table

You can just download the assembler font table in the download section here.

To use the font table, just include it in your source code and write a function like the one below. You will have to subtract 32 from ASCII codes to translate them to the entries of the character table.

PIC Assembler

cblock
char_num,L_tmp,H_tmp
endc

;////////////////////////////////////////////////////////////
;Blit function will output the pixels of a selected character
;Expects the character number in WREG
blit_char
;Save the character number
movwf char_num

;Load the character table
movlw LOW(char_table)
movwf TBLPTRL
movlw HIGH(char_table)
movwf TBLPTRH
movlw UPPER(char_table)
movwf TBLPTRU

;Determine the table row of the character
movf char_num,W
mullw .4

;Shift the table pointer to that row
movf PRODL,W
addwf TBLPTRL,F
movf PRODH,W
addwfc TBLPTRH,F
movlw .0
addwfc TBLPTRU,F

;Load the number of columns per character
TBLRD*+
movff TABLAT, char_num
;Now goto the characters data row
TBLRD*+
movff TABLAT,L_tmp
TBLRD*+
movff TABLAT,H_tmp
TBLRD*+
movff TABLAT,TBLPTRU
movff H_tmp,TBLPTRH
movff L_tmp,TBLPTRL

;Loop printing each column of pixels of the character
blit_char_loop
TBLRD*+
;Write the character column of pixels to whatever you want, e.g. LCD, framebuffer or whatever
;Here we move it into FSR0
movff TABLAT,POSTINC0

;Test if we're at the end of the character
dcfsnz char_num
return
bra blit_char_loop

If you want to edit the font or make your own from it you will have to build it yourself.

2. Building the Font Table

To build the font you must download the editor from here (Windows only, sorry), and use it to open the font file "font8MB" downloadable here. You should get something like this.

fonteditorscreencap

Edit the font by clicking on the characters, add some custom symbols if you want and then click Save & Exit. Choose ANSI C and Columns as the file format. This will create a Font8MB.c and Font8MB.h file in the current directory.

3. Generating the PIC Assembler Table

To convert the font to a PIC assembly table you can use a short C++ program I've written. Download convert.cpp from here.

To build the file, compile it with gcc and then run it like so
BASH
$ g++ convert.cpp Font8MB.c $ ./a.out > chartable.inc

This will generate the include file and the generated font file is available for download in the download section of the site, here.

Last Updated on Tuesday, 02 February 2010 11:14
 
Please register or login to add your comments to this article.
Copyright © 2014. MarcusBannerman.co.uk.