http://blog.csdn.net/boygrass/article/details/6824352
无OS的课程基本都完成了。有之前C/C++的基础,完成得还是比较轻松的。
刚刚完成了 从uC/OS中提取字库,并移植到无OS的环境下。
理解了:
点阵字库实际上就是点阵的二进制表示,通常英文字符用16*8的点阵,中文字符用16*16的点阵。
比如一个英文字符,在字库中就是用16个8位的数来表示,每个数代表点阵的一行。
类似地,汉字在字库中就是用16个16位的数来表示。如下图中,每个点,黑色为1,白色为0,就组成了点阵字库
几个关键的函数
-
-
void Lcd_PutASCII(unsigned int x,unsigned int y,unsigned char ch,unsigned int
-
c,unsigned int bk_c,unsigned int st)
-
{
-
unsigned short int i,j;
-
unsigned char *pZK,mask,buf;
-
pZK = &__VGA[ch*16];
-
for( i = 0 ; i < 16 ; i++ )
-
{
-
mask = 0x80;
-
buf = pZK[i];
-
for( j = 0 ; j < 8 ; j++ )
-
{
-
if( buf & mask )
-
{
-
PutPixel(x+j,y+i,c);
-
}
-
else
-
{
-
if( !st )
-
{
-
PutPixel(x+j,y+i,bk_c);
-
}
-
}
-
mask = mask >> 1;
-
}
-
}
-
}
-
-
-
-
-
void Lcd_PutHZ(unsigned int x,unsigned int y,unsigned short int QW,unsigned int c,unsigned int bk_c,unsigned int st)
-
{
-
unsigned short int i,j;
-
unsigned char *pZK,mask,buf;
-
-
pZK = &__CHS[ ( ( (QW >> 8) - 1 )*94 + (QW & 0x00FF)- 1 )*32 ];
-
for( i = 0 ; i < 16 ; i++ )
-
{
-
-
mask = 0x80;
-
buf = pZK[i*2];
-
for( j = 0 ; j < 8 ; j++ )
-
{
-
if( buf & mask )
-
{
-
PutPixel(x+j,y+i,c);
-
}
-
else
-
{
-
if( st )
-
{
-
PutPixel(x+j,y+i,bk_c);
-
}
-
}
-
mask = mask >> 1;
-
}
-
-
-
mask = 0x80;
-
buf = pZK[i*2 + 1];
-
for( j = 0 ; j < 8 ; j++ )
-
{
-
if( buf & mask )
-
{
-
PutPixel(x+j + 8,y+i,c);
-
}
-
else
-
{
-
if( st )
-
{
-
PutPixel(x+j + 8,y+i,bk_c);
-
}
-
}
-
mask = mask >> 1;
-
}
-
}
-
}
-
-
-
void Lcd_printf(unsigned int x,unsigned int y,unsigned int c,unsigned int bk_c,unsigned int st,char *fmt,...)
-
{
-
char __LCD_Printf_Buf[256];
-
va_list ap;
-
unsigned char *pStr = (unsigned char *)__LCD_Printf_Buf;
-
unsigned int i = 0;
-
-
va_start(ap,fmt);
-
vsprintf(__LCD_Printf_Buf,fmt,ap);
-
va_end(ap);
-
-
while(*pStr != 0 )
-
{
-
switch(*pStr)
-
{
-
case '\n' :
-
{
-
-
break;
-
}
-
-
default:
-
{
-
if( *pStr > 0xA0 & *(pStr+1) > 0xA0 )
-
{
-
Lcd_PutHZ( x , y , (*pStr - 0xA0)*0x0100 + *(pStr+1) - 0xA0 , c , bk_c , st);
-
-
pStr++;
-
i++;
-
-
x += 16;
-
}
-
else
-
{
-
Lcd_PutASCII( x , y , *pStr , c , bk_c , st );
-
-
x += 8;
-
-
}
-
-
break;
-
}
-
}
-
-
pStr++;
-
i++;
-
-
if( i > 256 ) break;
-
}
-
-
}
-
-
阅读(543) | 评论(0) | 转发(0) |