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

📄 lcd.c

📁 这是一个用52来触摸液晶屏的keil工程
💻 C
字号:
/**************************************************************************************
* 名    称: 
* 功    能:
* 参    数:
* 返 回 值:
*
* 修改历史:
*   版本    日期     作者     
*   ----------------------------------------------------
*   1.0   2008.8.13  孙逸洁       www.http://shop35330111.taobao.com
**************************************************************************************/
void send_command(uint out_data)              
{
RS=0;
DATA_H=out_data>>8;
DATA_L=out_data;
RW=0;
CS=0;
RW=1;
CS=1;
}
/**************************************************************************************
* 名    称: 
* 功    能:
* 参    数:
* 返 回 值:
*
* 修改历史:
*   版本    日期     作者     
*   ----------------------------------------------------
*   1.0   2008.8.13  孙逸洁       www.http://shop35330111.taobao.com
**************************************************************************************/
void send_data(uint out_data)           
{
RS=1;
CS=0;
DATA_H=out_data>>8;
DATA_L=out_data;
RW=0;
RW=1;
CS=1;
}
/**************************************************************************************
* 名    称: 
* 功    能:
* 参    数:
* 返 回 值:
*
* 修改历史:
*   版本    日期     作者     
*   ----------------------------------------------------
*   1.0   2008.8.13  孙逸洁       www.http://shop35330111.taobao.com
**************************************************************************************/
uint rece_data(void)              
{
uint i;
RS=1;
DATA_H=0xff;
DATA_L=0xff;
CS=0;
rd=0;
i=DATA_H;
i<<=8;
i|=DATA_L;
rd=1;
CS=1;
return i;
}
/**************************************************************************************
* 名    称: 
* 功    能:
* 参    数:
* 返 回 值:
*
* 修改历史:
*   版本    日期     作者     
*   ----------------------------------------------------
*   1.0   2008.8.13  孙逸洁       www.http://shop35330111.taobao.com
**************************************************************************************/
void write_com(uint address,uint num)
{
    send_command(address);
    send_data(num);
}
/**************************************************************************************
* 名    称: 
* 功    能:
* 参    数:
* 返 回 值:
*
* 修改历史:
*   版本    日期     作者     
*   ----------------------------------------------------
*   1.0   2008.8.13  孙逸洁       www.http://shop35330111.taobao.com
**************************************************************************************/
void lcd_init(void)
{
    write_com(0x00,0x0000);DelayNS(1000);
    write_com(0x07,0x0001);DelayNS(1000);//Display Control 1
    write_com(0x08,0x0405);DelayNS(1000);//Display Control 2 0808
    write_com(0x30,0x0707);DelayNS(1000);
    write_com(0x31,0x0407);DelayNS(1000);
    write_com(0x32,0x0203);DelayNS(1000);
    write_com(0x33,0x0303);DelayNS(1000);
    write_com(0x34,0x0303);DelayNS(1000);
    write_com(0x35,0x0202);DelayNS(1000);
    write_com(0x36,0x1007);DelayNS(1000);//0x1111
    write_com(0x37,0x0707);DelayNS(1000);//0x0606
    write_com(0x38,0x0407);DelayNS(1000);//0x0606
    write_com(0x39,0x0203);DelayNS(1000);//0x0606
    write_com(0x3a,0x0202);DelayNS(1000);
    write_com(0x3b,0x0303);DelayNS(1000);
    write_com(0x3c,0x0606);DelayNS(1000);
    write_com(0x3d,0x1313);DelayNS(1000);	   
    write_com(0x07,0x0101);DelayNS(1000);//Display Control 1
    write_com(0x17,0x0001);DelayNS(1000);//Power Control 5
    write_com(0x10,0x08b0);DelayNS(1000);//Power Control 1
    write_com(0x11,0x0001);DelayNS(1000);//Power Control 2 0007
    write_com(0x12,0x0118);DelayNS(1000);//Power Control 3
    write_com(0x13,0x0B00);DelayNS(1000);//Power Control 4 0x1400
    write_com(0x29,0x0004);DelayNS(1000);//VCOM High Voltage 0x0c
    write_com(0x2a,0x0000);DelayNS(1000);//VCOM High Voltage 0x0080
    write_com(0x12,0x01B8);DelayNS(1000);//Power Control 3 0x013e
    write_com(0x01,0x0100);DelayNS(1000);//Driver Output Control
    write_com(0x02,0x0300);DelayNS(1000);//LCD Driving Wave Control 0x0701
    write_com(0x03,0x1030);DelayNS(1000);//Entry Mode 0x1030
    write_com(0x04,0x0000);DelayNS(1000);//Resizing Control
    write_com(0x09,0x0028);DelayNS(1000);//Display Control 3 0x0028
    write_com(0x0c,0x0000);DelayNS(1000);//interface select
    write_com(0x50,0x0000);DelayNS(1000);//Window Horizontal RAM Address Start
    write_com(0x51,0x00ef);DelayNS(1000);//Window Horizontal RAM Address End
    write_com(0x52,0x0000);DelayNS(1000);//Window Vertical RAM Address Start
    write_com(0x53,0x013f);DelayNS(1000);//Window Vertical RAM Address End
    write_com(0x60,0x2700);DelayNS(1000);//Driver Output Control
    write_com(0x61,0x0001);DelayNS(1000);//Base Image Display Control
    write_com(0x90,0x0015);DelayNS(1000);//Panel interface control 1 0010
    write_com(0x92,0x0000);DelayNS(1000);//Panel interface control 2
    write_com(0x93,0x0000);DelayNS(1000);//Panel interface control 3
    write_com(0x20,0x00ef);DelayNS(1000);//RAM Address Set (Horizontal Address)
    write_com(0x21,0x013f);DelayNS(1000);//RAM Address Set (Vertical Address)
    write_com(0x07,0x0021);DelayNS(1000);//Display Control 1
    write_com(0x07,0x0061);DelayNS(1000);//Display Control 1
    write_com(0x07,0x0173);DelayNS(1000);//Display Control 1
    write_com(0x10,0x16b0);DelayNS(1000);//10bo  0x18b0
    write_com(0x20,0x0000);DelayNS(1000);
    write_com(0x21,0x0000);DelayNS(1000);
}

/**************************************************************************************
* 名    称: 
* 功    能:
* 参    数:
* 返 回 值:
*
* 修改历史:
*   版本    日期     作者     
*   ----------------------------------------------------
*   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);        //列首址
}
/**************************************************************************************
* 名    称: DispOneColor
* 功    能: 全屏显示某种颜色
* 参    数: Color   : 颜色值
* 返 回 值: 无
*
* 修改历史:
*   版本    日期     作者     
*   ----------------------------------------------------
*   1.0   2008.8.13  孙逸洁       www.http://shop35330111.taobao.com
**************************************************************************************/
void DispOneColor(uint Color)
{
    int i,j;
    Set_ramaddr(0,0);        //
    send_command(0x22);
    for(j=0;j<320;j++)
        for(i=0;i<240;i++)
            send_data(Color);
}
/**************************************************************************************
* 名    称: DispClear
* 功    能: 清除显示屏的显示内容
* 参    数: 无
* 返 回 值: 无
*
* 修改历史:
*   版本    日期     作者     
*   ----------------------------------------------------
*   1.0   2008.8.13  孙逸洁       www.http://shop35330111.taobao.com
**************************************************************************************/
void DispClear(void)
{
    DispOneColor(BLACK);
}
/**************************************************************************************
* 名    称: DrawSingleAscii
* 功    能: 在指定的位置单个字符
* 参    数: x           : x坐标
*                       y         : y坐标
*               LineColor : 字符的颜色
*           FillColor   : 字符背景颜色
* 返 回 值: 无
*
* 修改历史:
*   版本    日期     作者     
*   ----------------------------------------------------
*   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);
        send_command(0x22);
        str = *(AsciiLib + OffSet + i);  
        for (j=0;j<8;j++)
        {
            if ( str & (0x80>>j) )     //0x80>>j
            {
                send_data((uint)(LineColor&0xffff));
            }
            else
            {
                if (NORMAL == Mod) 
                    send_data((uint)(FillColor&0xffff));
                else
                {
                    Set_ramaddr(x+j+1,y+i);
                    send_command(0x22);  
                }
            }               
        } 
    }
}
/**************************************************************************************
* 名    称: DrawSingleHz
* 功    能: 在指定的位置显示汉字
* 参    数: x           : x坐标
*                       y       : y坐标
*               LineColor : 汉字的颜色
*           FillColor   : 汉字背景颜色
* 返 回 值: 无
*
* 修改历史:
*   版本    日期     作者     
*   ----------------------------------------------------
*   1.0   2008.8.13  孙逸洁       www.http://shop35330111.taobao.com
**************************************************************************************/
void DrawSingleHz(uint x, uint y, uchar *pHz, uint LineColor,uint FillColor, uchar Mod)
{
uint j=0,i=0,k=0;
uint str,len;
//---------------------------统计是否在字库中出现 
len=sizeof(HzLib)/sizeof(HzLib[0]);
for(j=0;j<sizeof(HzLib)/sizeof(HzLib[0]);j++)   
    if((uchar)HzLib[j].Index[0]==pHz[0]&&(uchar)HzLib[j].Index[1]==pHz[1])break;
//--------------------------      
    if(j<len)
    {
        for (i=0;i<HZ_column;i++)
        {
            Set_ramaddr(x,y+i);
            send_command(0x22);

            str = (uchar)HzLib[j].Msk[i*2]<<8|(uchar)HzLib[j].Msk[i*2+1]; 

            for (k=0;k<HZ_column;k++)
            {
                if ( str & (0x8000>>k) )     //0x8000>>k
                {
                    send_data((uint)(LineColor&0xffff));
                }
                else
                {
                    if (NORMAL == Mod) 
                        send_data((uint)(FillColor&0xffff));
                    else
                    {
                        Set_ramaddr(x+k+1,y+i);
                        send_command(0x22);  
                    }
                }               
            } 
        }
    }
}

/**************************************************************************************
* 名    称: DrawString
* 功    能: 在指定的位置显示多个字符
* 参    数: x           : x坐标
*                       y         : y坐标
*               LineColor : 字符的颜色
*           FillColor   : 字符背景颜色
* 返 回 值: 无
*
* 修改历史:
*   版本    日期     作者     
*   ----------------------------------------------------
*   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 += HZ_column;
            pStr += 2;              
        }
		else
		{
			DrawSingleAscii(x, y, pStr, LineColor, FillColor, Mod);
            x += 8;
            pStr += 1; 
		} 
       
    }   
}
/**************************************************************************************
* 名    称: 
* 功    能:
* 参    数:
* 返 回 值:
*
* 修改历史:
*   版本    日期     作者     
*   ----------------------------------------------------
*   1.0   2008.8.13  孙逸洁       www.http://shop35330111.taobao.com
**************************************************************************************/

void DispNum(unsigned int x, unsigned int y, unsigned short num)
{
    unsigned char str[2];

    str[0] = num+0x30;   
    str[1] = '\0';

    DrawString(x, y, str, RED, 0x333333, NORMAL);
}

void DisNum(unsigned int x, unsigned int y, unsigned short num, unsigned int color)
{
    unsigned char str[2];

    str[0] = num+0x30;   
    str[1] = '\0';

    DrawString(x, y, str, RED, color, NORMAL);
}

⌨️ 快捷键说明

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