|  | 
| 复制代码#include "lcd.h"
#include "2440addr.h"
#define LOW21BITS(n)        ((n) & 0x1FFFFF)
#define Lcd_Enable()        rLCDCON1 |=1
volatile unsigned short LCD_BUFFER[LCD_YSIZE_TFT][LCD_XSIZE_TFT];        //成像缓冲区
extern unsigned char __CHS[];
extern unsigned char __VGA[];
void Lcd_Config(void)
{
        rGPCCON = 0xAAAA02A9;
        rGPDCON = 0xAAAAAAAA;
        rGPCUP  = 0x00000000;
        rGPDUP  = 0x00000000;
        
        rLCDCON1=(CLKVAL_TFT<<8)|(MVAL_USED<<7)|(3<<5)|(12<<1)|0;
            // TFT LCD panel,12bpp TFT,ENVID=off
        rLCDCON2=(VBPD<<24)|(LINEVAL_TFT<<14)|(VFPD<<6)|(VSPW);
        rLCDCON3=(HBPD<<19)|(HOZVAL_TFT<<8)|(HFPD);
        rLCDCON4=(MVAL<<8)|(HSPW);
        rLCDCON5 = (1<<11) | (0<<10) | (1<<9) | (1<<8) | (0<<7) | (0<<6) | (1<<3)  |(BSWP<<1) | (HWSWP);
        rLCDSADDR1=(((unsigned int)LCD_BUFFER>>22)<<21)|LOW21BITS((unsigned int)LCD_BUFFER>>1);
        rLCDSADDR2=LOW21BITS( ((unsigned int)LCD_BUFFER+(SCR_XSIZE_TFT*LCD_YSIZE_TFT*2))>>1 );
        rLCDSADDR3=(((SCR_XSIZE_TFT-LCD_XSIZE_TFT)/1)<<11)|(LCD_XSIZE_TFT/1);
        rLCDINTMSK|=(3); // MASK LCD Sub Interrupt
        rTCONSEL &= (~7) ;     // Disable LPC3480
        rTPAL=0; // Disable Temp Palette
}
static void Lcd_PowerEnable(int powerEnable)
{
        rGPGCON = rGPGCON &(~(3<<8))|(3<<8);
        rGPGDAT |= (1<<4);
        rLCDCON5 = rLCDCON5 &(~(1<<3))|(powerEnable<<3);
}
void Lcd_Init(void)
{
        Lcd_Config();
        Lcd_Enable();
        Lcd_PowerEnable(1);
}
//打印点
void PutPixel(unsigned int x , unsigned int y , unsigned int c)
{
        if((x<LCD_XSIZE_TFT) && (y<LCD_YSIZE_TFT))
        {
                LCD_BUFFER[y][x] = c;
        }
}
//打印图片
void Paint_Bmp(const unsigned char bmp[])
{
        int x,y;
        unsigned short c;
        int p = 0;
        
        for(y=0 ; y<LCD_YSIZE_TFT ; y++)
        {
                for(x=0 ; x<LCD_XSIZE_TFT ; x++){
                        c = bmp[p+1] | (bmp[p]<<8);
                        LCD_BUFFER[y][x] = c;
                        p+=2;
                }
        }
}
//清屏
void Lcd_Clear(unsigned int c)
{
        unsigned int x,y;
        for(y=0 ; y<LCD_YSIZE_TFT ; y++)
        {
                for(x=0 ; x<LCD_XSIZE_TFT ; x++){
                        LCD_BUFFER[y][x] = c;
                }
        }
}
//打印ASCII码
void Lcd_Print_ASCII(unsigned int x,unsigned int y,unsigned char ch,unsigned int c)
{
        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);
                        }
                }
                mask = mask >> 1;
        }
}
//打印汉字
void Lcd_Print_ZW(unsigned int x , unsigned int y , unsigned short int QW , unsigned c)
{
        unsigned short int i,j;
        unsigned char *pZK,mask,buf;
        
        pZK = &__CHS[(((QW>>8)-161)*94+(QW & 0x00FF)-161)*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);
                        }
                        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);
                        }
                        mask = mask >> 1;
                }
        }
}
//打印字符串
void Lcd_Print(unsigned int x , unsigned int y , char* str , unsigned c){
        while(*str){
                if(*str>0xa0)
                {
                        //判断为汉字
                        Lcd_Print_ZW(x,y,*(str+1)+*(str)*256,c);
                        str+=2;
                        x+=16;
                }
                else
                {
                        //ASCII码
                        Lcd_Print_ASCII(x,y,*str,c);
                        str++;
                        x+=8;
                }
        }
}
 | 
 |