s3c2440之LCD字符顯示
#define U32 unsigned int
#define M5D(n) ((n) & 0x1fffff)
#define rGPCCON (*(volatile unsigned *)0x56000020)
#define rGPCDAT (*(volatile unsigned *)0x56000024)
#define rGPCUP (*(volatile unsigned *)0x56000028)
#define rGPDCON (*(volatile unsigned *)0x56000030)
#define rGPDDAT (*(volatile unsigned *)0x56000034)
#define rGPDUP (*(volatile unsigned *)0x56000038)
#define rGPGCON (*(volatile unsigned *)0x56000060)
#define rGPGDAT (*(volatile unsigned *)0x56000064)
#define rGPGUP (*(volatile unsigned *)0x56000068)
#define rLCDCON1 (*(volatile unsigned *)0x4d000000)
#define rLCDCON2 (*(volatile unsigned *)0x4d000004)
#define rLCDCON3 (*(volatile unsigned *)0x4d000008)
#define rLCDCON4 (*(volatile unsigned *)0x4d00000c)
#define rLCDCON5 (*(volatile unsigned *)0x4d000010)
#define rLCDSADDR1 (*(volatile unsigned *)0x4d000014)
#define rLCDSADDR2 (*(volatile unsigned *)0x4d000018)
#define rLCDSADDR3 (*(volatile unsigned *)0x4d00001c)
#define rLCDINTMSK (*(volatile unsigned *)0x4d00005c)
#define rTCONSEL (*(volatile unsigned *)0x4d000060)
#define LCD_WIDTH 320
#define LCD_HEIGHT 240
#define VSPW (3-1)
#define VBPD (15-1)
#define VFPD (12-1)
#define HSPW (30-1)
#define HBPD (38-1)
#define HFPD (20-1)
#define LINEVAL (LCD_HEIGHT-1)
#define HOZVAL (LCD_WIDTH-1)
/*for LCDCON1*/
#define CLKVAL_TFT 6
#define MVAL_USED 0
#define PNRMODE_TFT 3
#define BPPMODE_TFT 13
/*for LCDCON5*/
#define BPP24BL 0
#define INVVCLK 0
#define INVVLINE 1
#define INVVFRAME 1
#define INVVD 0
#define INVVDEN 0
#define PWREN 1
#define BSWP 0
#define HWSWP 0
volatile U32 LCD_BUFFER[LCD_HEIGHT][LCD_WIDTH];
unsigned char ning[]= /*寧*/
{
0x00,0x60,0x00,0x00,0x30,0x00,0x00,0x18,0x00,0x10,0x10,0x0C,0x1F,0xFF,0xFE,0x30,0x00,0x18,0x30,0x00,0x10,0x60,0x00,0x20,
0x00,0x00,0x00,0x00,0x00,0x18,0x7F,0xFF,0xFC,0x00,0x18,0x00,0x00,0x18,0x00,0x00,0x18,0x00,0x00,0x18,0x00,0x00,0x18,0x00,
0x00,0x18,0x00,0x00,0x18,0x00,0x00,0x18,0x00,0x00,0x18,0x00,0x00,0x18,0x00,0x01,0xF8,0x00,0x00,0x70,0x00,0x00,0x20,0x00
};
unsigned char bo[]= /*波*/
{
0x00,0x02,0x00,0x30,0x03,0x80,0x18,0x03,0x00,0x0C,0x03,0x00,0x08,0x83,0x0C,0x00,0xFF,0xFE,0x42,0xC3,0x0C,0x62,0xC3,0x18,
0x32,0xC3,0x20,0x34,0xC3,0x00,0x14,0xC3,0x10,0x04,0xFF,0xF8,0x08,0xC8,0x30,0x08,0xC8,0x60,0x18,0xC4,0x60,0x78,0xC4,0xC0,
0x18,0xC2,0xC0,0x18,0xC3,0x80,0x31,0x83,0x80,0x31,0x86,0xC0,0x33,0x0C,0x70,0x12,0x30,0x3E,0x04,0xC0,0x18,0x09,0x00,0x00
};
unsigned char da[]= /*大*/
{
0x00,0x20,0x00,0x00,0x38,0x00,0x00,0x30,0x00,0x00,0x30,0x00,0x00,0x30,0x00,0x00,0x30,0x00,0x00,0x30,0x10,0x00,0x30,0x38,
0x3F,0xFF,0xFC,0x00,0x38,0x00,0x00,0x68,0x00,0x00,0x64,0x00,0x00,0x64,0x00,0x00,0xC6,0x00,0x00,0xC2,0x00,0x01,0x83,0x00,
0x01,0x81,0x80,0x03,0x00,0xC0,0x06,0x00,0xF0,0x0C,0x00,0x78,0x18,0x00,0x3E,0x20,0x00,0x18,0x40,0x00,0x00,0x00,0x00,0x00,
};
unsigned char xue[]= /*學(xué)*/
{
0x00,0x20,0x00,0x08,0x30,0x40,0x04,0x10,0xF0,0x06,0x18,0xC0,0x03,0x18,0x80,0x03,0x11,0x80,0x12,0x01,0x0C,0x1F,0xFF,0xFE,
0x30,0x00,0x0C,0x70,0x00,0x18,0x60,0x00,0xD0,0x07,0xFF,0xE0,0x00,0x01,0x80,0x00,0x16,0x00,0x00,0x18,0x00,0x00,0x18,0x0C,
0x7F,0xFF,0xFE,0x00,0x18,0x00,0x00,0x18,0x00,0x00,0x18,0x00,0x00,0x18,0x00,0x01,0xF8,0x00,0x00,0x70,0x00,0x00,0x20,0x00
};
unsigned char ASCII_A[]= /*A*/
{
0x00, 0x00, 0x00, 0x10, 010, 0x18, 0x28, 0x28, 0x24, 0x3C, 0x44, 0x42, 0x42, 0xE7, 0x00, 0x00
};
unsigned char ASCII_R[]= /*R*/
{
0x00, 0x00, 0x00, 0xFC, 0x42, 0x42, 0x42, 0x7C, 0x48, 0x48, 0x44, 0x44, 0x42, 0xE3, 0x00, 0x00
};
unsigned char ASCII_M[]= /*M*/
{
0x00, 0x00, 0x00, 0xEE, 0x6C, 0x6C, 0x6C, 0x6C, 0x54, 0x54, 0x54, 0x54, 0x54, 0xD6, 0x00, 0x00
};
/*繪制背景*/
void Brush_Background( U32 c)
{
int x,y ;
for( y = 0 ; y < LCD_HEIGHT ; y++ )
{
for( x = 0 ; x < LCD_WIDTH ; x++ )
{
LCD_BUFFER[y][x] = c ;
}
}
}
/*繪制像素點*/
void PutPixel(U32 x,U32 y, U32 c )
{
LCD_BUFFER[y][x] = c;
}
/*繪制大小為24×24的中文字符*/
/*把LCD看成點陣,將數(shù)組char[]中的數(shù)據(jù)讀出,即點亮像素點,像素點顏色有自己來定,即通過PutPixel()函數(shù)來給要顯示的文字上色。每一個中文字符都是由24×24個像素點(可以認為是點陣),本代碼逐行掃描每行,先從左到右,在從上到下掃描點亮像素點。中文字符的寬度與ASCII碼字符寬度不同,一般ASCII字符寬度是中文字符的一半。在字符取模的時候,盡量寬和高都取成8的倍數(shù),這樣讀取字符2進制數(shù)組時比較容易
*/
void Draw_Text24(U32 x,U32 y,U32 color,const unsigned char ch[])
{
unsigned short int i,j;
unsigned char mask,buffer;
for(i=0;i<24;i++)
{
mask=0x80; /*掩碼*/
buffer=ch[i*3]; /*提取一行的第一個字節(jié)*/
for(j=0;j<8;j++)
{
if(buffer&mask)
{
PutPixel(x+j,y+i,color); /*為筆畫上色*/
}
mask=mask>>1;
}
mask=0x80; /*掩碼*/
buffer=ch[i*3+1]; /*提取一行的第二個字節(jié)*/
for(j=0;j<8;j++)
{
if(buffer&mask)
{
PutPixel(x+j+8,y+i,color); /*為筆畫上色*/
}
mask=mask>>1;
}
mask=0x80;
buffer=ch[i*3+2];
for(j=0;j<8;j++)
{
if(buffer&mask)
{
PutPixel(x+j+16,y+i,color); /*為筆畫上色*/
}
mask=mask>>1;
}
}
}
/*繪制大小為8×16的ASCII碼*/
void Draw_ASCII(U32 x,U32 y,U32 color,const unsigned char ch[])
{
unsigned short int i,j;
unsigned char mask,buffer;
for(i=0;i<16;i++)
{
mask=0x80;
buffer=ch[i];
for(j=0;j<8;j++)
{
if(buffer&mask)
{
PutPixel(x+j,y+i,color);
}
mask=mask>>1;
}
}
}
/*LCD初始化*/
void LCD_Init()
{
/*設(shè)置LCD引腳*/
rGPCUP = 0x00000000;
rGPCCON = 0xaaaa02a9;
rGPDUP = 0x00000000;
rGPDCON=0xaaaaaaaa;
rLCDCON1=(CLKVAL_TFT<<8)|(MVAL_USED<<7)|(PNRMODE_TFT<<5)|(BPPMODE_TFT<<1)|0;
rLCDCON2=(VBPD<<24)|(LINEVAL<<14)|(VFPD<<6)|(VSPW);
rLCDCON3=(HBPD<<19)|(HOZVAL<<8)|(HFPD);
rLCDCON4=(HSPW);
rLCDCON5 = (BPP24BL<<12) | (INVVCLK<<10) | (INVVLINE<<9) | (INVVFRAME<<8) | (0<<7) | (INVVDEN<<6) | (PWREN<<3) |(BSWP<<1) | (HWSWP);
rLCDSADDR1=(((U32)LCD_BUFFER>>22)<<21)|M5D((U32)LCD_BUFFER>>1);
rLCDSADDR2=M5D( ((U32)LCD_BUFFER+(LCD_WIDTH*LCD_HEIGHT*4))>>1 );
rLCDSADDR3=LCD_WIDTH*4/2;
rLCDINTMSK|=(3);
rTCONSEL = 0;
rGPGUP=rGPGUP&(~(1<<4))|(1<<4);
rGPGCON=rGPGCON&(~(3<<8))|(3<<8);
rGPGDAT = rGPGDAT | (1<<4) ;
rLCDCON5=rLCDCON5&(~(1<<3))|(1<<3);
rLCDCON5=rLCDCON5&(~(1<<5))|(0<<5);
}
void Main(void)
{
LCD_Init();
rLCDCON1|=1; /*開啟LCD顯示*/
Brush_Background(0xFFFFFF); /*繪制白色背景*/
/*繪制黑色字符*/
Draw_Text16(50,100,0xff,ning);
Draw_Text16(74,100,0xff00,bo);
Draw_Text16(96,100,0xffff00,da);
Draw_Text16(120,100,0xff0000,xue);
Draw_ASCII(50,130,0x0,ASCII_A);
Draw_ASCII(62,130,0x0,ASCII_R);
Draw_ASCII(74,130,0x0,ASCII_M);
while(1)
{
;
}
}
評論