嵌入式Linux下LCD驅動簡介
在嵌入式Linux環境下,LCD的驅動已自動加載,其設備文件名為“/dev/em9x60_lcd”。應用程序通過調用5個IOCTL命令來實現對於LCD屏的操作。
EM9X60_LCD_IOCTL_TYPE: 用於設置LCD屏類型。
EM9X60_LCD_IOCTL_LINE: 圖形方式的操作,包括畫點、畫線以及畫Bar條。
EM9X60_LCD_IOCTL_BLOCK:數據塊顯示操作,主要用於字模的顯示。
EM9X60_LCD_IOCTL_CLEAR:清屏操作。
EM9X60_LCD_IOCTL_UPDATE:用於刷新LCD屏數據。
針對於畫點、畫線、畫Bar條命令EM9X60_LCD_IOCTL_LINE需要用到以下結構:
struct lcd_line
{
unsigned int type; // = 0: point; = 1: line; = 2: bar
unsigned int x0;
unsigned int y0;
unsigned int x1;
unsigned int y1;
unsigned int color; // = 0: write '0'; = 1: write '1', = 2: xor operation
};
數據塊顯示操作命令EM9X60_LCD_IOCTL_BLOCK會用到struct lcd_block結構,該結構中的數據data[16]中每個data[n] 值是按照x方向排列的,x 方向的大小最多為8個bit;數據data[0] ~ data[15]是按照y方向排列的,一次最多寫16個字節大小的數據。這種數據塊結構可應用在寫字模,或是公司專用圖形LOGO上。
struct lcd_block
{
unsigned int x0;
unsigned int y0;
unsigned int xsize; // = 1 - 8; left alignment
unsigned int ysize; // = 1 - 16;
unsigned char data[16]; // block data to be copied
};
如寫一個漢字字模為16X16點陣的數據,漢字模為ffont[32],可以用如下代碼來實現:
LCD_WriteByteBlock( x, y, ffont, 16 );
LCD_WriteByteBlock( x+8, y, &ffont[16], 16 );
intLCD_WriteByteBlock( int x, inty, unsigned char* hfont, intNumOfBytes )
{
int rc;
unsigned int cmd;
structlcd_block block;
inti1;
block.x0 = x;
block.y0 = y;
block.xsize = 8;
block.ysize = NumOfBytes;
for( i1=0; i1<NumOfBytes; )
{
block.data[i1]= hfont[i1];
}
cmd = EM9X60_LCD_IOCTL_BLOCK;
rc = ioctl(lcd_fd, cmd, &block );
if(rc < 0)
{
return rc;
}
return rc;
}
LCD應用API函數簡介
為了方便客戶的使用,在基於em9x60_lcd驅動基礎上設計了一套通用的漢字及圖形顯示接口函數,這些函數均定義在LCD_API.H中。LCD_API函數提供了一系列對LCD屏進行畫點、畫線、畫Bar條以及字符串(包括漢字和西文)顯示的接口函數,一共包括了11個函數,關於各個函數的定義說明,可以參見LCD_AP.H頭文件中的中文注釋。其中的漢字支持為標准一級全漢字,為16×16點陣字模或12×12點陣字模,西文(字母、數字和符號)為8×14點陣字模,這兩個字模文件分別為cclib、cclib12.fnt、ascii.chr,放置在EM9160工控板的根文件系統“/lib”目錄中。
目前支持的LCD屏類型包括有:
LCD控制器類型
顯示分辨率
簡要說明
KS0108
128×64
最常用的LCD模塊T6963C
240×128
具有較大的顯示窗口SED1335
320×240
KS0108
192×64
UC1698U
160×160
電力集抄終端標准顯示屏在頭文件LCD_API.H中的對應定義如下。
#define LCD_12864 1 // LCD 128×64 KS0108控制器
#define LCD_240128 2 // LCD 240×128 T6963C控制器
#define LCD_320240 3 // LCD 320×240 SED1335控制器
#define LCD_19264 4 // LCD 192×64 KS0108控制器
#defineLCD_160160 5 // LCD 192×64 UC1698U控制器
經過測試LCD的顯示速率得到了大大的提高,以下為常用的兩種LCD顯示速率:
LCD控制器類型
顯示分辨率
清屏速率
滿屏字符顯示速率
T6963C
240×128
10ms
20ms
UC1698U
160×160
9ms
12ms