移植之前 必须保证 成功移植了文件系统,这是在VS2008上运行通过的;
//移植的时候要修改printf 函数为LCD的打印一个点的函数,与文件系统相关的函数 酌情修改
这是显示效果,16*16 的GBK字库 字库的文件名是 "font.DZK"
#include "stdio.h"
#define FONT_SIZE 32//定义单个汉字所占的字节数
void Display(FILE *f,char *str);
void Displays(FILE *f,char *str,unsigned char count);
int main(void)
{
FILE *f;
f=fopen("font.DZK",r");
if(f==NULL)
{
printf("error..");
return 0;
}
Displays(f,"您好",2);
fclose(f);
return 0;
}
void GetFont(FILE *f,char *str,unsigned char *buff)
{
unsigned char High=*str;
unsigned char Low=*(str+1);
unsigned long offset;
High-=0x81;
if(Low<0x7f)
Low-=0x40;
else
Low-=0x41;
offset=(unsigned long)(High*190+Low)*FONT_SIZE;
fseek(f,offset,0);
fread(buff,FONT_SIZE,1,f);
}
void Display(FILE *f,char *str)
{
char i,j;
unsigned char buff[FONT_SIZE],temp;
GetFont(f,str,buff);
for(i=0;i<32;i+=2)
{
temp=buff[i];
for(j=0;j<8;j++)
{
if(temp&0x80)
printf("*");
else
printf(" ");
temp<<=1;
}
temp=buff[i+1];
for(j=0;j<8;j++)
{
if(temp&0x80)
printf("*");
else
printf(" ");
temp<<=1;
}
printf("\n");
}
}
void printblank(void)
{
unsigned char i;
for(i=0;i<16;i++)
printf(" ");
}
void Displays(FILE *f,char *str,unsigned char count)
{
unsigned char i;
for(i=0;i<count;i++,str+=2)
{
Display(f,str);
printblank();
}
}