"); //-->
最近在做TFT-LCD显示的实验,参考altera嵌入式系统开发套件中关于屏幕显示字符的驱动,发现了一个驱动程序的错误。
字符串显示程序如下:
while (string[i]) {
//Handle newline char here.
if (string[i] == '\n') {
horiz_offset = original_horiz_offset;
vert_offset += font['|' - 33].bounds_height; // we'll use "|" to add the line to line spacing
i++;
continue;
}
// Lay down that character and increment our offsets.
if(string[i] == 32) // this is a space in ASCII
{
if(background_color != CLEAR_BACKGROUND) // need to fill in this spot (setting foreground to background color so that it looks like a drawn in box)
{
vid_print_char_alpha (horiz_offset, vert_offset, background_color, '-', background_color, font, display);
}
horiz_offset += font[45 - 33].bounds_width; // using the width of the '-' character for the space width since it's not present in the font
}
else if( string[i] < 33 || string[i] > 126 ) // Print '.' if it's a character we dont support
{
vid_print_char_alpha (horiz_offset, vert_offset, color, '.', background_color, font, display);
horiz_offset += font['.' - 33].bounds_width;
}
else if(string[i] == '\t') // this is a tab '\t'
{
for( tab = 0; tab < TAB_SPACING; tab++ )
{
if(background_color != CLEAR_BACKGROUND) // need to fill in this spot (setting foreground to background color so that it looks like a drawn in box)
{
vid_print_char_alpha (horiz_offset, vert_offset, background_color, '-', background_color, font, display);
}
horiz_offset += font[45 - 33].bounds_width; // using the width of the '-' character for the space width since it's not present in the font
}
}
else
{
vid_print_char_alpha (horiz_offset, vert_offset, color, string[i], background_color, font, display);
horiz_offset += font[string[i] - 33].bounds_width;
}
i++;
}
功能是将预先定义的字符串显示在彩屏上。可以显示的字符为ASCII码值为33和126之间的字符,如果有'\n'则换行,有空格符(ASCII码为32)则空一格,有'\t'(ASCII码为9)则空出tab(可以自己定义tab的长度);如果字符串中有其他ASCII码值的字符,则显示"."(一个小数点)。
实验发现,定义字符串如"abcd\tefg",显示的却是abcd.efg。即'\t'只显示了一个小数点。经检查,原来是因为'\t'程序段放在了判别ASCII码值大小之后,而'\t'的ASCII码值为9,所以,字符串中的'\t'被首先认为是33~126之外的字符而输出"."。如果将'\t'判别程序段放在判别ASCII码值大小程序段之前,问题得到了解决。更正后的程序如下:
while (string[i]) {
//Handle newline char here.
if (string[i] == '\n') {
horiz_offset = original_horiz_offset;
vert_offset += font['|' - 33].bounds_height; // we'll use "|" to add the line to line spacing
i++;
continue;
}
// Lay down that character and increment our offsets.
if(string[i] == 32) // this is a space in ASCII
{
if(background_color != CLEAR_BACKGROUND) // need to fill in this spot (setting foreground to background color so that it looks like a drawn in box)
{
vid_print_char_alpha (horiz_offset, vert_offset, background_color, '-', background_color, font, display);
}
horiz_offset += font[45 - 33].bounds_width; // using the width of the '-' character for the space width since it's not present in the font
}
else if(string[i] == '\t') // this is a tab '\t'
{
for( tab = 0; tab < TAB_SPACING; tab++ )
{
if(background_color != CLEAR_BACKGROUND) // need to fill in this spot (setting foreground to background color so that it looks like a drawn in box)
{
vid_print_char_alpha (horiz_offset, vert_offset, background_color, '-', background_color, font, display);
}
horiz_offset += font[45 - 33].bounds_width; // using the width of the '-' character for the space width since it's not present in the font
}
}
else if( string[i] < 33 || string[i] > 126 ) // Print '.' if it's a character we dont support
{
vid_print_char_alpha (horiz_offset, vert_offset, color, '.', background_color, font, display);
horiz_offset += font['.' - 33].bounds_width;
}
else
{
vid_print_char_alpha (horiz_offset, vert_offset, color, string[i], background_color, font, display);
horiz_offset += font[string[i] - 33].bounds_width;
}
i++;
}
*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。