S3C2440-LCD字符顯示
void Paint_text(U32 x, U32 y, U32 color, unsigned char ch[]){
int i, j, test, s, t = 0;
for(i = 0; i < 16; i++){
test = 0x80;
for(j = 0; j < 16; j++){
if(j == 8){
test = 0x80;
t++;
}
if(ch[t] & test)
LCD_BUFFER[x+i][y+j] = color;
test >>= 1;
}
t++;
}
}
void Paint_text_8(U32 x, U32 y, U32 color, unsigned char ch[]){
int i, j, test;
for(i = 0; i < 16; i++){
test = 0x80;
for(j = 0; j < 8; j++){
if(test & ch[ i])
LCD_BUFFER[x+i][y+j] = color;
test >>= 1;
}
}
}
void Paint_background(U32 c){
unsigned int i, j;
for(j = 0; j < LCD_YSIZE; j++)
for(i = 0; i < LCD_XSIZE; i++)
LCD_BUFFER[j][ i] = c;
}
int LcdMain(){
Init_LCD();
Paint_background(0xFFFFFF);
Paint_text(100,100,0x000000,li);
Paint_text(100,116,0x000000,wan);
Paint_text(100,132,0x000000,peng);
Paint_text_8(116,100,0x000000,L);
Paint_text_8(116,108,0x000000,I);
Paint_text_8(116,116,0x000000,N);
Paint_text_8(116,124,0x000000,U);
Paint_text_8(116,132,0x000000,X);
Paint_text_8(116,140,0x000000,AND);
Paint_text_8(116,148,0x000000,A);
Paint_text_8(116,156,0x000000,R);
Paint_text_8(116,164,0x000000,M);
while(1);
}
如果使用字庫(kù),每個(gè)漢字的地址由兩個(gè)字節(jié)表示。一個(gè)是區(qū)號(hào),一個(gè)是區(qū)中的位置,即位號(hào)。16*16的點(diǎn)陣字庫(kù)中,每個(gè)字符占32個(gè)字節(jié),每94個(gè)字符為一個(gè)區(qū),共87個(gè)區(qū),其中1"15區(qū)為常用符號(hào)區(qū)(包括數(shù)字0"9及大小寫英文字母),16"86為常用漢字,其排列是以漢語拼音為序,從一聲到四聲,第87區(qū)為生僻漢字。漢字的起始地址是0xA1A1,A1+94=255,所以一個(gè)區(qū)有94個(gè)字符。區(qū)和位的起始號(hào)都是1,數(shù)組是從0開始,所以如果想在字庫(kù)中定位一個(gè)字符,(94*(qu-1)+wei)*32。如果中文字符和ASCII碼混合在一樣,如何區(qū)分它們呢?其實(shí)也很簡(jiǎn)單,ASCII碼的最高位是0,而中文的最高位是1,因此當(dāng)讀取到的一個(gè)字節(jié)的最高位是0,則該字節(jié)為ASCII碼,它的下一個(gè)字節(jié)與這個(gè)字節(jié)無關(guān);當(dāng)取得到的字節(jié)的最高位是1,則表示的是中文字符,并且該字節(jié)與它的下一個(gè)字節(jié)組合在一起表示完整的一個(gè)漢字。
#include "Font_Libs.h"
#define rGPCCON (*(volatile unsigned *)0x56000020)
#define rGPCUP (*(volatile unsigned *)0x56000028)
#define rGPDCON (*(volatile unsigned *)0x56000030)
#define rGPDUP (*(volatile unsigned *)0x56000038)
#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 rTPAL (*(volatile unsigned *)0x4d000050)
#define rGPGCON (*(volatile unsigned *)0x56000060) //Port G control
#define rGPGDAT (*(volatile unsigned *)0x56000064) //Port G data
#define rGPGUP (*(volatile unsigned *)0x56000068) //Pull-up control G
#define rLCDINTMSK (*(volatile unsigned *)0x4d00005c)
#define rTCONSEL (*(volatile unsigned *)0x4d000060) //LPC3600 Control --- edited by junon
//垂直同步信號(hào)的脈寬、后肩和前肩
#define VSPW 15
#define VBPD 3
#define VFPD 5
//水平同步信號(hào)的脈寬、后肩和前肩
#define HSPW 8
#define HBPD 58
#define HFPD 15
#define CLKVAL 10
#define HOZVAL 319
#define LINEVAL 239
#define PWREN 1
#define MMODE 0
#define PNRMODE 3
#define BPPMODE 13
#define INVVCLK 0
#define INVVD 0
#define INVVDEN 0
#define U32 unsigned int
#define M5D(n) ((n) & 0x1fffff)
#define PAGEWIDTH 320
#define OFFSIZE 0
#define LCD_XSIZE 320
#define LCD_YSIZE 240
#define SCR_XSIZE 320
#define SCR_YSIZE 240
#define INVVLINE 1
#define INVVFRAME 1
#define BPP24BL 0
#define BSWP 0
#define HWSWP 0
volatile U32 LCD_BUFFER[240][320];
評(píng)論