I have migrated from a 16×2 alpha-numeric display to a 128×64 graphical in existing project. With that in mind, I am planning on using a larger font instead of the "easy" 5×7. How do I integrate TTF font file in C?? How to generate hex for the same?
Incorporate TTF file in C
glcdstm32f3
Related Solutions
I just simulated the character you added to your question, and it looks OK to me. For reference, I wrote this code:
unsigned char cha[] = {0x00, 0x0C, 0x00, 0x03, 0xC0, 0x01, 0x30, 0x01, 0x0C, 0x01, 0x30, 0x01, 0xC0, 0x01, 0x00, 0x03, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
void main(void) {
int i;
int j;
for (i=0; i<sizeof(cha); i++) {
for (j=0; j<8; j++) {
printf("%c",(cha[i]&(1<<j)) ? '#' : '.');
}
i++;
for (j=0; j<8; j++) {
printf("%c",(cha[i]&(1<<j)) ? '#' : '.');
}
printf("\n");
}
}
and it prints out:
..........##....
........##......
......###.......
....##..#.......
..##....#.......
....##..#.......
......###.......
........##......
..........##....
................
................
................
................
So it seems that your font data for the character "A" seems ok and to write this to the LCD's row 0, you'd write bytes 0,2,4,6,8,... (0x00, 0x00, 0xc0, 0x30...) to row 0 and bytes 1,3,5,7,9... (0x0C, 0x03, 0x01, 0x01,...) to row 1.
I have only worked with LCDs on a direct hardware level. In case it's useful to you or someone else familiar with this platform, I can explain how to write byte B to row R, column C using the LCD display you seem to be using (NT75451):
First give the command SET PAGE (R), which in c language is (0xB0 | R). Then SET HIGH COLUMN ADDRESS, command (0x10 | (C >> 4)) and SET LOW COLUMN ADDRESS (0x00 | (C & 0xf)). Finally send the data byte (B).
Commands are sent with the LCD display's pin A0 pulled low and data is sent with A0 pulled high, but I suspect you already know this.
Hope this is helpful to you or someone else.
[EDIT]: Based on the draw function added to the question, you might try something like this to draw the big character:
void LCD_Draw_Char(uint8_t Line, uint8_t Column, unsigned char Char) // Bypass shadow display characters matrix to directly draw one character.
{
Task_S_T Task;
uint8_t Index;
LCD_Write_Command_SetPage(Line); // Set the virtual line index.
LCD_Write_Command_SetColumn(Column); // Set the column index.
Task.Command = TASK_WRITING;
Task.Iter = 0;
for( Index = 0; Index < 13; Index++ )
{
if( (Column + Index > DISPLAY_LAST_COLUMN)
|| (Line > DISPLAY_LAST_LINE ) )
{
return; /* Ran out of space :( */
};
Task.Data = Combination_Of(ACTION_WRITE_DATA_TO_RAM, Font_13x16[Char - BIG_FONT_FIRST_CHAR_CODE][Index*2]);
LCD_FIFO_Push(Task);
};
Task.Data = Combination_Of(ACTION_WRITE_DATA_TO_RAM, 0x00); /* The separator column of each char is set here to prevent dirty pixels being left unerased. */
LCD_FIFO_Push(Task); /* The separator column of each char is set here to prevent dirty pixels being left unerased. */
LCD_Write_Command_SetPage(Line+1); // Set the virtual line index.
LCD_Write_Command_SetColumn(Column); // Set the column index.
Task.Command = TASK_WRITING;
Task.Iter = 0;
for( Index = 0; Index < 13; Index++ )
{
if( (Column + Index > DISPLAY_LAST_COLUMN)
|| (Line > DISPLAY_LAST_LINE ) )
{
return; /* Ran out of space :( */
};
Task.Data = Combination_Of(ACTION_WRITE_DATA_TO_RAM, Font_13x16[Char - BIG_FONT_FIRST_CHAR_CODE][Index*2+1]);
LCD_FIFO_Push(Task);
};
Task.Data = Combination_Of(ACTION_WRITE_DATA_TO_RAM, 0x00); /* The separator column of each char is set here to prevent dirty pixels being left unerased. */
LCD_FIFO_Push(Task); /* The separator column of each char is set here to prevent dirty pixels being left unerased. */
return;
}
Best Answer
TTF is a vector font format, you first need to convert it into a bitmap with 1 bit color depth, then load it as an array in your code.
GIMP can save the bitmap as a C array.