s3c2440的LCD字符显示收藏在上一篇文章中,我们详细介绍了如何驱动LCD,对于在LCD屏上呈现各种简单的图形已经不是一件高不可攀的难事。但如何绘制字符呢?其实每一字符就是一幅图像,字符的大小对应于图像的大小,字符的笔画对应于图像的内容。那么如何把字符转换为图像呢?简单的方法是使用“字模提取”之类的软件,它能够把任意的字符转换为一个字节型的数组,数组元素中的每一位代表LCD上的一个像素点,当为1时,表示该位置为字符的一个笔画,需要上色,而为0时,表示不是笔画,不需要上色。例如,一个字符想要在16×16的面积上显示,即该字符的宽和高各为16个像素,因为每一个像素用一位来表示,因此用字模提取软件生成的字节型数组,一共有16×16÷8=32个字节。在字模提取的过程中,还要注意取模的顺序,顺序不同,得到的数组就不同,一般来说是从字符的左上角开始,从左向右,从上到下取模,这样程序编写上会方便一些。相同字体大小的中文字符和ASCII码字符的宽度还有所不同,一般ASCII码字符的宽度是中文字符宽度的一半,所以显示中文字符的程序和显示ASCII码字符的程序还略有不同。当把一个字符取模变成一个数组后,只要对该数组中每个元素的每一位依次进行判断,对值为1的位和值为0的位进行不同的上色处理,即可完成一个字符的绘制。下面的程序给出了一个简单的显示中文字符和ASCII字符的例子,我是用PCtoLCD这款软件来提取程序中想要显示的字符的。#defineU32unsignedint#defineM5D(n)((n)&0x1fffff)//Togetlower21bits#definerGPCCON(*(volatileunsigned*)0x56000020)//PortCcontrol#definerGPCDAT(*(volatileunsigned*)0x56000024)//PortCdata#definerGPCUP(*(volatileunsigned*)0x56000028)//Pull-upcontrolC#definerGPDCON(*(volatileunsigned*)0x56000030)//PortDcontrol#definerGPDDAT(*(volatileunsigned*)0x56000034)//PortDdata#definerGPDUP(*(volatileunsigned*)0x56000038)//Pull-upcontrolD#definerGPGCON(*(volatileunsigned*)0x56000060)//PortGcontrol#definerGPGDAT(*(volatileunsigned*)0x56000064)//PortGdata#definerGPGUP(*(volatileunsigned*)0x56000068)//Pull-upcontrolG#definerLCDCON1(*(volatileunsigned*)0x4d000000)//LCDcontrol1#definerLCDCON2(*(volatileunsigned*)0x4d000004)//LCDcontrol2#definerLCDCON3(*(volatileunsigned*)0x4d000008)//LCDcontrol3#definerLCDCON4(*(volatileunsigned*)0x4d00000c)//LCDcontrol4#definerLCDCON5(*(volatileunsigned*)0x4d000010)//LCDcontrol5#definerLCDSADDR1(*(volatileunsigned*)0x4d000014)//STN/TFTFramebufferstartaddress1#definerLCDSADDR2(*(volatileunsigned*)0x4d000018)//STN/TFTFramebufferstartaddress2#definerLCDSADDR3(*(volatileunsigned*)0x4d00001c)//STN/TFTVirtualscreenaddressset#definerLCDINTMSK(*(volatileunsigned*)0x4d00005c)//LCDInterruptmask#definerTCONSEL(*(volatileunsigned*)0x4d000060)//LPC3600Control---editedbyjunon#defineLCD_WIDTH320#defineLCD_HEIGHT240#defineVSPW(3-1)#defineVBPD(15-1)#defineVFPD(12-1)#defineHSPW(30-1)#defineHBPD(38-1)#defineHFPD(20-1)#defineLINEVAL(LCD_HEIGHT-1)#defineHOZVAL(LCD_WIDTH-1)//forLCDCON1#defineCLKVAL_TFT6#defineMVAL_USED0#definePNRMODE_TFT3#defineBPPMODE_TFT13//#defineVIDEO_OUT0//forLCDCON5#defineBPP24BL0#defineINVVCLK0#defineINVVLINE1#defineINVVFRAME1#defineINVVD0#defineINVVDEN0#definePWREN1#defineBSWP0#defineHWSWP0volatileU32LCD_BUFFER[LCD_HEIGHT][LCD_WIDTH];unsignedcharzhao[]=//赵{0x08,0x00,0x08,0x00,0x08,0x04,0x7E,0x84,0x08,0x48,0x08,0x28,0xFF,0x10,0x08,0x10,0x28,0x28,0x2F,0x28,0x28,0x44,0x28,0x84,0x58,0x00,0x48,0x00,0x87,0xFE,0x00,0x00};unsignedcharchun[]=//春{0x01,0x00,0x01,0x00,0x3F,0xFC,0x01,0x00,0x1F,0xF8,0x02,0x00,0xFF,0xFE,0x04,0x20,0x08,0x18,0x3F,0xEE,0xC8,0x24,0x0F,0xE0,0x08,0x20,0x08,0x20,0x0F,0xE0,0x00,0x00};unsignedcharjiang[]=//江{0x20,0x00,0x10,0x00,0x13,0xFC,0x00,0x40,0x88,0x40,0x48,0x40,0x50,0x40,0x10,0x40,0x10,0x40,0x20,0x40,0xE0,0x40,0x20,0x40,0x20,0x40,0x2F,0xFE,0x20,0x00,0x00,0x00,};unsignedcharASCII_A[]=//A{0x00,0x00,0x00,0x10,010,0x18,0x28,0x28,0x24,0x3C,0x44,0x42,0x42,0xE7,0x00,0x00};unsignedcharASCII_R[]=//R{0x00,0x00,0x00,0xFC,0x42,0x42,0x42,0x7C,0x48,0x48,0x44,0x44,0x42,0xE3,0x00,0x00};unsignedcharASCII_M[]=//M{0x00,0x00,0x00,0xEE,0x6C,0x6C,0x6C,0x6C,0x54,0x54,0x54,0x54,0x54,0xD6,0x00,0x00};//绘制背景voidBrush_Background(U32c){intx,y;for(y=0;yLCD_HEIGHT;y++){for(x=0;xLCD_WIDTH;x++){LCD_BUFFER[y][x]=c;}}}//绘制像素点voidPutPixel(U32x,U32y,U32c){LCD_BUFFER[y][x]=c;}//绘制大小为16×16的中文字符voidDraw_Text16(U32x,U32y,U32color,constunsignedcharch[]){unsignedshortinti,j;unsignedcharmask,buffer;for(i=0;i16;i++){mask=0x80;//掩码buffer=ch[i*2];//提取一行的第一个字节for(j=0;j8;j++){if(buffer&mask){PutPixel(x+j,y+i,color);//为笔画上色}mask=mask1;}mask=0x80;//掩码buffer=ch[i*2+1];//提取一行的第二个字节for(j=0;j8;j++){if(buffer&mask){PutPixel(x+j+8,y+i,color);//为笔画上色}mask=mask1;}}}//绘制大小为8×16的ASCII码voidDraw_ASCII(U32x,U32y,U32color,constunsignedcharch[]){unsignedshortinti,j;unsignedcharmask,buffer;for(i=0;i16;i++){mask=0x80;buffer=ch[i];for(j=0;j8;j++){if(buffer&mask){PutPixel(x+j,y+i,color);}mask=mask1;}}}//LCD初始化voidLCD_Init(){rGPCUP=0x00000000;rGPCCON=0xaaaa02a9;rGPDUP=0x00000000;rGPDCON=0xaaaaaaaa;//InitializeVD[15:8]rLCDCON1=(CLKVAL_TFT8)|(MVAL_USED7)|(PNRMODE_TFT5)|(BPPMODE_TFT1)|0;rLCDCON2=(VBPD24)|(LINEVAL14)|(VFPD6)|(VSPW);rLCDCON3=(HBPD19)|(HOZVAL8)|(HFPD);rLCDCON4=(HSPW);rLCDCON5=(BPP24BL12)|(INVVCLK10)|(INVVLINE9)|(INVVFRAME8)|(07)|(INVVDEN6)|(PWREN3)|(BSWP1)|(HWSWP);rLCDSADDR1=(((U32)LCD_BUFFER22)21)|M5D((U32)LCD_BUFFER1);rLCDSADDR2=M5D(((U32)LCD_BUFFER+(LCD_WIDTH*LCD_HEIGHT*4))1);rLCDSADDR3=LCD_WIDTH*4/2;rLCDINTMSK|=(3);//MASKLCDSubInterruptrTCONSEL=0;//DisableLPC3480rGPGUP=rGPGUP&(~(14))|(14);//Pull-updisablerGPGCON=rGPGCON&(~(38))|(38);//GPG4=LCD_PWRENrGPGDAT=rGPGDAT|(14);rLCDCON5=rLCDCON5&(~(13))|(13);//PWRENrLCDCON5=rLCDCON5&(~(15))|(05);//INVPWREN}voidMain(void){LCD_Init();rLCDCON1|=1;//开启LCD显示Brush_Background(0xFFFFFF);//绘制白色背景//绘制黑色字符Draw_Text16(50,100,