新華 ARM9_S3C2410 實驗板 - 小銀幕 LCD 輸出範例

程式碼追蹤

============================ demo.c ===============================
int main(void)
{
    int i;
    Initial_Creator();
    for (i=0; i<10; i++)
      LCD_printf("Hello!\n");
    while (1) {}
        return(0);
}

============================ lcd.c ===============================
..
void LCD_printf (char *fmt,...)
{
        va_list     ap;
        char        string[512], *p=string;

        va_start(ap, fmt);
        vsprintf(string, fmt, ap);
        va_end(ap);
        while (*p)
            LCD_putchar(*p++);
}
...
//將單一個字元寫入顯示裝置
void LCD_putchar (char c)
{
        switch (c){
        case '\n' :            //換行字元 
            if (Ypos == (ScrHeight-1))    //如果到達最後一行將往上捲動一行
                LCD_scroll();
            else
                Ypos++;
            Xpos = 0;
            break ;
        case '\t' :            //TAB字元用空白字元替換
            do LCD_putchar(' ');
            while (Xpos%TABS);
            break ;
        default :            //當超過每行最大寬度時自動換行
            if ((Xpos+1) >= ScrWidth){
                LCD_putchar('\n');
            }
            LCD_displ(Xpos++, Ypos, c);    //將字元寫入LCD
            break ;
        }
        if (byCursorOn)            
            LCD_SetCursor(Xpos, Ypos);    //移動游標到所顯式的字元後面
}
...
//將單一個字元寫入LCD
 void LCD_displ (int x, int y, int ch)
{
        unsigned short  addr, data ;
        int             i, YRelation;

    //可顯示自元範圍從0x20~0x7E
    //其餘用空白取代
        data = (ch >= 0x20 && ch <= 0x7E) ? ch : ' ';

        //計算字元所在位置
        YRelation = y - YScrollOffset;
        addr = x + (YRelation * 0x80);    // 每個字元占 128 byte

    //取出字元的圖型資料後寫入LCD
    for (i=0; i < byFontWidth; i++){
            LCD_PutRAMData(addr, charset[data][i]);
            addr += 0x10;
        }
}

//將資料寫入LCD的顯示區域內
void LCD_PutRAMData (unsigned short address, unsigned short data)
{
    SET_ADDRESS_LCD(address);    //設定LCD顯示區域RAM的位址
    SET_RAM_DATA_LCD(data);        //將所指定的資料寫入所指定LCD顯示區域RAM
}

//對LCD設定資料
 void WriteLCD (unsigned short addr, unsigned short data)
{
    LCD_CMD = 0xff;            //MSB
    OptimizationDelay();        //for Optimization    
    LCD_CMD = addr;            //LSB

    LCD_DATA = (data >> 8) ;    //MSB
    OptimizationDelay();        //for Optimization    
    LCD_DATA = data;        //LSB
}

// 規畫LCD操作模式
// 總共多少行, 每行多少字
// 設定游標型態
void Initial_LCD (void)
{
        byFontHeight = 8;            //文字字型高度為8
        byFontWidth = 8;            //文字字型寬度為8
        ScrWidth = 128 / byFontWidth;        //LCD每行共多少文字 (每行 16 個字)
        ScrHeight = 128 / byFontHeight;        //LCD總共有多少行 (共 16 行)

        InitialLCD();                //LCD工作模式設定

        LCD_CursorMode(BLACK_BLINK_CURSOR);    //黑色閃爍的游標
        LCD_EnableCursor(UM);            //啟動游標

}

============================LCD.h=====================================
// 讀寫LCD RAM的Macro 
#define SET_ADDRESS_LCD(x)        WriteLCD(LCD_RAM_ADDR, x);
#define SET_RAM_DATA_LCD(x)        WriteLCD(LCD_RAM_DATA, x);

==========================genfont8_8.h================================
static const unsigned short charset[][8] = { ... }
========================== 2410addr.h ================================
#define LCD_CMD         (*(volatile unsigned short *)(IO_BASE+0x0800))
#define LCD_DATA         (*(volatile unsigned short *)(IO_BASE+0x0802))
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License