uLCD Fonts and Sizes
Description
Different fonts can be displayed on the uLCD-144-G2 color display using an IDE tool to convert fonts into usable formats stored into the modules micro SD card. This is done by using a free 4D Workshop IDE containing the necessary tools and using a FAT formatted micro SD card, which can all be done using a PC with an SD card port. Instructions on downloading and using the 4D Workshop IDE is located here: http://www.4dsystems.com.au/downloads/Application-Notes/4D-AN-G5001-Serial-Displaying-Third-Party-Fonts-REV1.pdf.
When the SD card with stored fonts is inserted in the uLCD, the mbed uses serial commands to load the fonts. For speed, the FAT formatted micro SD card uses disk sector addresses instead of file names in serial commands to locate the data, and files are stored in a contiguous RAW format.
In the following example, four different fonts (including the default font) are loaded onto the the micro SD card and then inserted into the uLCD. Using push buttons and interrupts, the user can cycle through and change the size of the displayed fonts.
Hookup Guide
mbed | uLCD Header | uLCD Cable |
---|---|---|
5V=VU | 5V | 5V |
Gnd | Gnd | Gnd |
TX=p9 | RX | TX |
RX=p10 | TX | RX |
P11 | Reset | Reset |
Image
Video
Code
This program uses pushbuttons to control the size and font of the text. Push button 1 increases the text size. Push button 2 decreases the text size. Push button 3 switches between the available fonts. The different fonts are stored on the Transcend Micro SD card. Read the Description section for more information on this.
// uLCD-144-G2 different fonts // #include "mbed.h" #include "uLCD_4DGL.h" #include "PinDetect.h" uLCD_4DGL uLCD(p9,p10,p11); // serial tx, serial rx, reset pin; PinDetect pb1(p15); PinDetect pb2(p16); PinDetect pb3(p17); int volatile sizeCount=1; //font size count, set to 1 initially int volatile fontCount=0; //font count int volatile isInterrupted=1; //indicate an interrupt //pb1 to increase font size void pb1_hit_callback (void) { if (sizeCount < 4) {sizeCount++;} uLCD.cls(); isInterrupted=1; } //pb2 to decrease font size void pb2_hit_callback (void) { if (sizeCount > 1) {sizeCount--;} uLCD.cls(); isInterrupted=1; } //pb3 changes font. Loops through default, calibri, harlow solid italic, and parchment. void pb3_hit_callback (void) { if (fontCount < 3) {fontCount++;} else {fontCount = 0;} uLCD.cls(); isInterrupted=1; } int main() { pb1.mode(PullUp); pb2.mode(PullUp); pb3.mode(PullUp); wait(.01); // Setup Interrupt callback functions for a pb hit pb1.attach_deasserted(&pb1_hit_callback); pb2.attach_deasserted(&pb2_hit_callback); pb3.attach_deasserted(&pb3_hit_callback); // Start sampling pb inputs using interrupts pb1.setSampleFrequency(); pb2.setSampleFrequency(); pb3.setSampleFrequency(); uLCD.media_init(); // initialize uSD card uLCD.printf("\n Hello\n Font\n World"); while (1) { //change font settings if a button is pushed if(isInterrupted == 1) { uLCD.cls(); isInterrupted = 0; //comic sans if(fontCount == 1) { uLCD.set_sector_address(0,0); uLCD.set_font(MEDIAFONT); } //tahoma else if(fontCount == 2) { uLCD.set_sector_address(0,0xE); uLCD.set_font(MEDIAFONT); } //courier new else if(fontCount == 3) { uLCD.set_sector_address(0,0x1C); uLCD.set_font(MEDIAFONT); } //default font else { uLCD.set_sector_address(0,0); uLCD.set_font(FONT_7X8); } //increase or decrease font uLCD.text_width(sizeCount); //1X size text uLCD.text_height(sizeCount); uLCD.printf("\n Hello\n Font\n World"); } } }
Import programuLCDFontImport
Load different fonts into uLCD.
Please log in to post comments.