⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tft_240_320.c

📁 s24193 液晶ARM
💻 C
字号:

//====================================================================================
#include <string.h>
#include <LPC214x.h>
#include ".\font\HzLib_65k.h"
#include "lpc213x_user.h"
/**************************************************************************************
* 名    称:
* 功    能: 
* 参    数: 
* 返 回 值:
*
* 修改历史:
*   版本    日期     作者     
*   ----------------------------------------------------
*   1.0   2008.8.13  孙逸洁       www.http://shop35330111.taobao.com
**************************************************************************************/
void Delay(uint k)
{
    uint i;
    ulong j;
    for(i = k;i > 0;i--)
        for(j = 200000;j > 0;j--);  
}
/**************************************************************************************
* 名    称:
* 功    能: 
* 参    数: 
* 返 回 值:
*
* 修改历史:
*   版本    日期     作者     
*   ----------------------------------------------------
*   1.0   2008.8.13  孙逸洁       www.http://shop35330111.taobao.com
**************************************************************************************/
void DelayMs( int k)
{
    uint i;
    ulong j;
    for(i = k;i > 0;i--)
        for(j = 1000;j > 0;j--);    
}
/**************************************************************************************
* 名    称:
* 功    能: 
* 参    数: 
* 返 回 值:
*
* 修改历史:
*   版本    日期     作者     
*   ----------------------------------------------------
*   1.0   2008.8.13  孙逸洁       www.http://shop35330111.taobao.com
**************************************************************************************/
void WriData(uint ch)
{
    LCD_RS_1;
    LCD_WR_1;
    LCD_CS_0;
    LCD_DATA(ch);
    LCD_WR_0;
    LCD_CS_1;
}
/**************************************************************************************
* 名    称:
* 功    能: 
* 参    数: 
* 返 回 值:
*
* 修改历史:
*   版本    日期     作者     
*   ----------------------------------------------------
*   1.0   2008.8.13  孙逸洁       www.http://shop35330111.taobao.com
**************************************************************************************/
void WriCom(uint ch)
{
    LCD_RS_0;
    LCD_WR_1;
    LCD_CS_0;
    LCD_DATA(ch);
    LCD_WR_0;
    LCD_CS_1;
}
/**************************************************************************************
* 名    称:
* 功    能: 
* 参    数: 
* 返 回 值:
*
* 修改历史:
*   版本    日期     作者     
*   ----------------------------------------------------
*   1.0   2008.8.13  孙逸洁       www.http://shop35330111.taobao.com
**************************************************************************************/
void write_com(uint address,uint num)
{
    WriCom(address);
    WriData(num);
}
/**************************************************************************************
* 名    称:
* 功    能: 
* 参    数: 
* 返 回 值:
*
* 修改历史:
*   版本    日期     作者     
*   ----------------------------------------------------
*   1.0   2008.8.13  孙逸洁       www.http://shop35330111.taobao.com
**************************************************************************************/
void TftInit(void)
{
	LCD_RESET_0;      //低电平复位
    DelayMs(10);
    LCD_RESET_1;
    write_com(0x00,0x0000);DelayMs(10);
    write_com(0x07,0x0001);DelayMs(10);//Display Control 1
    write_com(0x08,0x0405);DelayMs(10);//Display Control 2 0808
    write_com(0x30,0x0707);DelayMs(10);
    write_com(0x31,0x0407);DelayMs(10);
    write_com(0x32,0x0203);DelayMs(10);
    write_com(0x33,0x0303);DelayMs(10);
    write_com(0x34,0x0303);DelayMs(10);
    write_com(0x35,0x0202);DelayMs(10);
    write_com(0x36,0x1007);DelayMs(10);//0x1111
    write_com(0x37,0x0707);DelayMs(10);//0x0606
    write_com(0x38,0x0407);DelayMs(10);//0x0606
    write_com(0x39,0x0203);DelayMs(10);//0x0606
    write_com(0x3a,0x0202);DelayMs(10);
    write_com(0x3b,0x0303);DelayMs(10);
    write_com(0x3c,0x0606);DelayMs(10);
    write_com(0x3d,0x1313);DelayMs(10);
    write_com(0x07,0x0101);DelayMs(10);//Display Control 1
    write_com(0x17,0x0001);DelayMs(10);//Power Control 5
    write_com(0x10,0x08b0);DelayMs(10);//Power Control 1
    write_com(0x11,0x0001);DelayMs(10);//Power Control 2 0007
    write_com(0x12,0x0118);DelayMs(10);//Power Control 3
    write_com(0x13,0x0B00);DelayMs(10);//Power Control 4 0x1400
    write_com(0x29,0x0004);DelayMs(10);//VCOM High Voltage 0x0c
    write_com(0x2a,0x0000);DelayMs(10);//VCOM High Voltage 0x0080
    write_com(0x12,0x01B8);DelayMs(10);//Power Control 3 0x013e
    write_com(0x01,0x0100);DelayMs(10);//Driver Output Control
    write_com(0x02,0x0300);DelayMs(10);//LCD Driving Wave Control 0x0701
    write_com(0x03,0x1030);DelayMs(10);//Entry Mode 0x1030
    write_com(0x04,0x0000);DelayMs(10);//Resizing Control
    write_com(0x09,0x0028);DelayMs(10);//Display Control 3 0x0028
    write_com(0x0c,0x0000);DelayMs(10);//interface select
    write_com(0x50,0x0000);DelayMs(10);//Window Horizontal RAM Address Start
    write_com(0x51,0x00ef);DelayMs(10);//Window Horizontal RAM Address End
    write_com(0x52,0x0000);DelayMs(10);//Window Vertical RAM Address Start
    write_com(0x53,0x013f);DelayMs(10);//Window Vertical RAM Address End
    write_com(0x60,0x2700);DelayMs(10);//Driver Output Control
    write_com(0x61,0x0001);DelayMs(10);//Base Image Display Control
    write_com(0x90,0x0015);DelayMs(10);//Panel interface control 1 0010
    write_com(0x92,0x0000);DelayMs(10);//Panel interface control 2
    write_com(0x93,0x0000);DelayMs(10);//Panel interface control 3
    write_com(0x20,0x00ef);DelayMs(10);//RAM Address Set (Horizontal Address)
    write_com(0x21,0x013f);DelayMs(10);//RAM Address Set (Vertical Address)
    write_com(0x07,0x0021);DelayMs(10);//Display Control 1
    write_com(0x07,0x0061);DelayMs(10);//Display Control 1
    write_com(0x07,0x0173);DelayMs(10);//Display Control 1
    write_com(0x10,0x16b0);DelayMs(10);//10bo  0x18b0
    write_com(0x20,0x0000);DelayMs(10);
    write_com(0x21,0x0000);DelayMs(10);
}
/**************************************************************************************
* 名    称:
* 功    能: 
* 参    数: 
* 返 回 值:
*
* 修改历史:
*   版本    日期     作者     
*   ----------------------------------------------------
*   1.0   2008.8.13  孙逸洁       www.http://shop35330111.taobao.com
**************************************************************************************/
void Set_ramaddr(uint x,uint y)
{
    write_com(0x0021,y);        //行首址
    write_com(0x0020,x);        //列首址
}
/**************************************************************************************
* 名    称:
* 功    能: 
* 参    数: 
* 返 回 值:
*
* 修改历史:
*   版本    日期     作者     
*   ----------------------------------------------------
*   1.0   2008.8.13  孙逸洁       www.http://shop35330111.taobao.com
**************************************************************************************/
void DispOneColor(int Color)
{
    int i,j;
    Set_ramaddr(0,0);
    WriCom(0x22);
    for(j=0;j<320;j++)
        for(i=0;i<240;i++)  
            WriData(Color);
}
/**************************************************************************************
* 名    称:
* 功    能: 
* 参    数: 
* 返 回 值:
*
* 修改历史:
*   版本    日期     作者     
*   ----------------------------------------------------
*   1.0   2008.8.13  孙逸洁       www.http://shop35330111.taobao.com
**************************************************************************************/
void DispClear(void)
{
    DispOneColor(BLACK);
}
/**************************************************************************************
* 名    称:
* 功    能: 
* 参    数: 
* 返 回 值:
*
* 修改历史:
*   版本    日期     作者     
*   ----------------------------------------------------
*   1.0   2008.8.13  孙逸洁       www.http://shop35330111.taobao.com
**************************************************************************************/
void DrawPixel(uint x, uint y, int Color)
{
	Set_ramaddr(x,y);
    WriCom(0x22); 
    WriData(Color);
}
/**************************************************************************************
* 名    称:
* 功    能: 
* 参    数: 
* 返 回 值:
*
* 修改历史:
*   版本    日期     作者     
*   ----------------------------------------------------
*   1.0   2008.8.13  孙逸洁       www.http://shop35330111.taobao.com
**************************************************************************************/
void DispPic240_320(const unsigned char *str)
{
    int i;
	Set_ramaddr(0,0);
    WriCom(0x22); 
    for (i = 0; i < 240 * 320; i++)
    {
        WriData(*(unsigned short *)(&str[ 2 * i]));
    }
}
/**************************************************************************************
* 名    称:
* 功    能: 
* 参    数: 
* 返 回 值:
*
* 修改历史:
*   版本    日期     作者     
*   ----------------------------------------------------
*   1.0   2008.8.13  孙逸洁       www.http://shop35330111.taobao.com
**************************************************************************************/
void DispSmallPic(uint x, uint y, uint w, uint h, const uchar *str)
{
    uint i,j,temp;
    for(j=0;j<h;j++)
    {
        Set_ramaddr(x,y+j);
        WriCom(0x22); 
        for(i=0;i<w;i++)
        {   //send_data(*(unsigned short *)(&str[(j*w+i)*2]));       //高位在前
            temp=str[(j*w+i)*2+1]<<8;     //低位在前
            temp|=str[(j*w+i)*2];
            WriData(temp);
        }
    }
}
/**************************************************************************************
* 名    称:
* 功    能: 
* 参    数: 
* 返 回 值:
*
* 修改历史:
*   版本    日期     作者     
*   ----------------------------------------------------
*   1.0   2008.8.13  孙逸洁       www.http://shop35330111.taobao.com
**************************************************************************************/
void DrawSingleHz(uint x, uint y, uchar *pHz, uint LineColor,uint FillColor, uchar Mod)
{
    uchar Ch1,Ch2;
    uchar i, k;
    uint str;
    uint OffSet;

    Ch1 = *pHz;
    Ch2 = *(pHz + 1);
    OffSet = ((Ch1 - 0xb0)*94 + (Ch2 - 0xa1))*32;

       for (i=0;i<16;i++)
        {
            Set_ramaddr(x,y+i);
            WriCom(0x22);
			str = *(HzLib + OffSet + i*2)<<8|*(HzLib + OffSet + i*2+1);
            for (k=0;k<16;k++)
            {
                if ( str & (0x8000>>k) )     //0x8000>>k
                {
                    WriData((uint)(LineColor&0xffff));
                }
                else
                {
                    if (NORMAL == Mod) 
                        WriData((uint)(FillColor&0xffff));
                    else
                    {
                        Set_ramaddr(x+k+1,y+i);
                        WriCom(0x22);  
                    }
                }               
            } 
        }
}
/**************************************************************************************
* 名    称:
* 功    能: 
* 参    数: 
* 返 回 值:
*
* 修改历史:
*   版本    日期     作者     
*   ----------------------------------------------------
*   1.0   2008.8.13  孙逸洁       www.http://shop35330111.taobao.com
**************************************************************************************/
void DrawSingleAscii(uint x, uint y, uchar *pAscii, uint LineColor,uint FillColor, uchar Mod)
{
    uchar i, j;
    uchar str;
    uint OffSet;

    OffSet = (*pAscii - 32)*16;

    for (i=0;i<16;i++)
    {
        Set_ramaddr(x,y+i);
        WriCom(0x22);
        str = *(AsciiLib + OffSet + i);  
        for (j=0;j<8;j++)
        {
            if ( str & (0x80>>j) )     //0x80>>j
            {
                WriData((uint)(LineColor&0xffff));
            }
            else
            {
                if (NORMAL == Mod) 
                    WriData((uint)(FillColor&0xffff));
                else
                {
                    Set_ramaddr(x+j+1,y+i);
                    WriCom(0x22);  
                }
            }               
        } 
    }
}
/**************************************************************************************
* 名    称:
* 功    能: 
* 参    数: 
* 返 回 值:
*
* 修改历史:
*   版本    日期     作者     
*   ----------------------------------------------------
*   1.0   2008.8.13  孙逸洁       www.http://shop35330111.taobao.com
**************************************************************************************/
void DrawString(uint x, uint y, uchar *pStr, uint LineColor,uint FillColor, uchar Mod)
{

    while(1)
    {
        if (*pStr == 0)	{return;}
        if (*pStr > 0x80)           //汉字
        {
            DrawSingleHz(x, y, pStr, LineColor, FillColor, Mod);
            x += 16;
            pStr += 2;              
        }
        else                        //英文字符
        {
            DrawSingleAscii(x, y, pStr, LineColor, FillColor, Mod);
            x += 8;
            pStr += 1;              
        }
    }   
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -