mini2440中显示中英文字体

1、工程的建立

      对光盘当中的源文件进行删减即可

2、显示中英文字,需要字库文件

       1)将原文件里面的config.h拷贝到inc文件夹当中去,把Font_Libs.c文件拷贝到src文件夹当中去,并且在项目中添加Font_Libs.c文件;

       2)在main.c文件前面添加如下代码:(头文件、字库数组申明,函数申明)

#include "config.h"
#include "stdarg.h"

extern unsigned char __VGA[];//为字库添加的声明,英文ASCII编码 
extern unsigned char __CHS[];//为字库添加的声明,汉子字库数组 
 
void  Lcd_PutHZ(unsigned  int  x,unsigned  int  y,unsigned  short  int  QW,unsigned  int c,unsigned int bk_c,unsigned int st);//为字库添加的声明
void  Lcd_PutASCII(unsigned  int  x,unsigned  int  y,unsigned  char  ch,unsigned  int c,unsigned int bk_c,unsigned int st);//为字库添加的声明 
void  Lcd_printf(unsigned  int  x,unsigned  int  y,unsigned  int  c,unsigned  int bk_c,unsigned int st,char *fmt,...);//为字库添加的声明

        3)在Lcd.c文件中添加如下代码:

前面添加如下:(头文件、字库数组申明)

#include "config.h"
#include "stdarg.h"


extern unsigned char __VGA[];
extern unsigned char __CHS[];

后面添加函数定义:(函数定义)

/**************************************************************
在LCD屏幕上指定坐标点写ASCII码
**************************************************************/
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;
        }
	}
}

/**************************************************************
在LCD屏幕上指定坐标点写汉字
**************************************************************/
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;
	}
   
}




你可能感兴趣的:(mini2440)