"); //-->
最近在做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++;
}
专栏文章内容及配图由作者撰写发布,仅供工程师学习之用,如有侵权或者其他违规问题,请联系本站处理。 联系我们
相关推荐
Arm 驱动下一代机器人创新浪潮
图形化的嵌入式系统设计方案介绍(演讲者NI CEO Dr. T)(视频教程20分钟 中文)
台湾大学的FPGA教程
选对运用软件的方法,使 AI 创新如虎添翼
三星接近与高通达成2纳米代工协议,随着晶圆代工业务复苏势头增强
D触发器组成的曝光定时器
我这儿有TTL的常用芯片资料(PDF)不知怎么上传
JEC-2组成的延时电路(一)
JEC-2组成的延时电路(二)
CoolSiC™ MOSFET G2如何正确选型
无人机核心系统解析:自主导航与感知系统
[Android开发视频教学]Activity布局初步(二)(10)
用FPGACPLD设计UART
多相电机的奇妙世界(1):从三相到多相的跨越
[Android开发视频教学]Activity的布局初步(三)(11)
嵌入式系统清华教材
请问
[Android开发视频教学]Activity的生命周期(二)(08)
运放5G28组成的自动曝光定时器
[Android开发视频教学]Activity布局初步(一)(09)
10 亿营收+千人团队!宇树科技在机器人赛道杀疯了
物联网设备5大安全认证和标准,一文讲透!
JEC-2组成的限时动作电路
考,不能上传附件k
请问
s3c2410 lcd FRAME BUFFER START ADDRESS 求助
AI 时代,如何为消费电子设备的安全性保驾护航?
于 CPU 和专用编解码芯片的DVR 方案设计浅析
码住这份指南:Edge AI与机器学习常用硬件类型与开发板全解析
[Android开发视频教学]Activity生命周期(一)(07)