|
- /**************************************************************************************
- * 名 稱:
- * 功 能:
- * 參 數(shù):
- * 返 回 值:
- *
- * 修改歷史:
- * 版本 日期 作者
- * ----------------------------------------------------
- * 1.0
- **************************************************************************************/
- void send_command(unsigned int Cmd)
- {
- CS=0;
- RS=0;
- num_out=Cmd; RW=0;RW=1;
- CS=1;
- }
- /**************************************************************************************
- * 名 稱:
- * 功 能:
- * 參 數(shù):
- * 返 回 值:
- *
- * 修改歷史:
- * 版本 日期 作者
- * ----------------------------------------------------
- * 1.0
- **************************************************************************************/
- void send_byte(uchar Data)
- {
- RS=1;
- CS=0; num_out=Data; RW=0;RW=1; CS=1;
- }
- /**************************************************************************************
- * 名 稱:
- * 功 能:
- * 參 數(shù):
- * 返 回 值:
- *
- * 修改歷史:
- * 版本 日期 作者
- * ----------------------------------------------------
- * 1.0
- **************************************************************************************/
- void send_data(uint num)
- {
- RS=1;
- CS=0; num_out=(num>>8); RW=0;RW=1; CS=1;
- CS=0; num_out=num; RW=0;RW=1; CS=1;
- }
- /**************************************************************************************
- * 名 稱:
- * 功 能:
- * 參 數(shù):
- * 返 回 值:
- *
- * 修改歷史:
- * 版本 日期 作者
- * ----------------------------------------------------
- * 1.0
- **************************************************************************************/
- void write_com(unsigned int Cmd,unsigned int num)
- {
- CS=0;
- Rd=1;
- RS=0;
- num_out=Cmd; RW=0;RW=1;
- RS=1;
- num_out=num; RW=0;RW=1;
- CS=1;
- }
- /**************************************************************************************
- * 名 稱:
- * 功 能:
- * 參 數(shù):
- * 返 回 值:
- *
- * 修改歷史:
- * 版本 日期 作者
- * ----------------------------------------------------
- * 1.0
- **************************************************************************************/
- void lcd_init(void)
- {
- CS=1; RW=1; Rd=1; RS=1;
- RST=0; DelayNS( 1000 );RST=1;
- send_command(0x11); DelayNS( 1500 );
- // sleep out/power on(SLPOUT)
- send_command(0x20); // display inversion off
- send_command(0x38); // ID mode off (IDMOFF)
- send_command(0x13); // Normal display mode on (Partial mode off)
- // color mode Interface pixel format (COLMOD)
- write_com(0x3A,0x05); // 16-bit/pixel , 1-times data transfer
- write_com(0xC0,0x00); // power control 1 (PWCTR1) , GVDD voltage set 4.65
- write_com(0xC1,0x05);DelayNS( 1500 );
- // VCOMH voltage set 4.10V
- write_com(0xC5,0xc7); //;c0h VCOMH voltage set 4.175V
- write_com(0xC6,0x07);DelayNS( 1500 );
- //;07 ;VCOMAC voltage set 4.8V ;
- // Gamma voltage adjustalbe level
- //Gamma + Polarity correction characteristics set
- send_command(0xE0);
- send_byte(0x21);
- send_byte(0x11);
- send_byte(0x21);
- send_byte(0x22);
- send_byte(0x22);
- send_byte(0x33);
- send_byte(0x03);
- write_com(0x36,0x10); // MY=1; MX=0; MV=0; ML=0; RGB=0
- send_command(0x37);
- send_byte(0x00);
- send_byte(0x00); // display on
- send_command(0x29);
- }
- /**************************************************************************************
- * 名 稱:
- * 功 能:
- * 參 數(shù):
- * 返 回 值:
- *
- * 修改歷史:
- * 版本 日期 作者
- * ----------------------------------------------------
- * 1.0
- **************************************************************************************/
- void LCD_SetArea( uchar x0, uchar y0, uchar x1, uchar y1 )
- {
- send_command(0x2A);
- send_byte(0x00);
- send_byte(x0);
- send_byte(0x00);
- send_byte(x1);
- send_command(0x2B);
- send_byte(0x00);
- send_byte(y0);
- send_byte(0x00);
- send_byte(y1);
- }
- /**************************************************************************************
- * 名 稱:
- * 功 能:
- * 參 數(shù):
- * 返 回 值:
- *
- * 修改歷史:
- * 版本 日期 作者
- * ----------------------------------------------------
- * 1.0
- **************************************************************************************/
- void Set_ramaddr(uchar x,uchar y)
- {
- send_command(0x2A);
- send_byte(0x00);
- send_byte(x);
- send_byte(0x00);
- send_byte(x);
- send_command(0x2B);
- send_byte(0x00);
- send_byte(y);
- send_byte(0x00);
- send_byte(y);
- }
- /**************************************************************************************
- * 名 稱: DispOneColor
- * 功 能: 全屏顯示某種顏色
- * 參 數(shù): Color : 顏色值
- * 返 回 值: 無(wú)
- *
- * 修改歷史:
- * 版本 日期 作者
- * ----------------------------------------------------
- * 1.0
- **************************************************************************************/
- void DispOneColor(uint Color)
- {
- uchar i,j;
- LCD_SetArea(0,0,kuan-1,gao);
- send_command(0x2C);
- for(j=0;j<kuan;j++)
- for(i=0;i<gao;i++)
- send_data(Color);
- }
- /**************************************************************************************
- * 名 稱: DispClear
- * 功 能: 清除顯示屏的顯示內(nèi)容
- * 參 數(shù): 無(wú)
- * 返 回 值: 無(wú)
- *
- * 修改歷史:
- * 版本 日期 作者
- * ----------------------------------------------------
- * 1.0
- **************************************************************************************/
- void DispClear(void)
- {
- DispOneColor(BLACK);
- }
- /**************************************************************************************
- * 名 稱: DrawSingleAscii
- * 功 能: 在指定的位置單個(gè)字符
- * 參 數(shù): x : x坐標(biāo)
- * y : y坐標(biāo)
- * LineColor : 字符的顏色
- * FillColor : 字符背景顏色
- * 返 回 值: 無(wú)
- *
- * 修改歷史:
- * 版本 日期 作者
- * ----------------------------------------------------
- * 1.0
- **************************************************************************************/
- 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++)
- {
- str = *(AsciiLib + OffSet + i);
- for (j=0;j<8;j++)
- {
- Set_ramaddr(x+j,y+i);
- send_command(0x2C);
- 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(0x2C);
- }
- }
- }
- }
- }
- /**************************************************************************************
- * 名 稱: DrawSingleHz
- * 功 能: 在指定的位置顯示漢字
- * 參 數(shù): x : x坐標(biāo)
- * y : y坐標(biāo)
- * LineColor : 漢字的顏色
- * FillColor : 漢字背景顏色
- * 返 回 值: 無(wú)
- *
- * 修改歷史:
- * 版本 日期 作者
- * ----------------------------------------------------
- * 1.0
- **************************************************************************************/
- void DrawSingleHz(uint x, uint y, uchar *pHz, uint LineColor,uint FillColor, uchar Mod)
- {
- uint j=0,i=0,k=0;
- uint str,len;
- //---------------------------統(tǒng)計(jì)是否在字庫(kù)中出現(xiàn)
- 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++)
- {
- str = (uchar)HzLib[j].Msk[i*2]<<8|(uchar)HzLib[j].Msk[i*2+1];
- for (k=0;k<HZ_column;k++)
- {
- Set_ramaddr(x+k,y+i);
- send_command(0x2C);
- 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(0x2C);
- }
- }
- }
- }
- }
- }
- /**************************************************************************************
- * 名 稱: DrawString
- * 功 能: 在指定的位置顯示多個(gè)字符
- * 參 數(shù): x : x坐標(biāo)
- * y : y坐標(biāo)
- * LineColor : 字符的顏色
- * FillColor : 字符背景顏色
- * 返 回 值: 無(wú)
- *
- * 修改歷史:
- * 版本 日期 作者
- * ----------------------------------------------------
- * 1.0
- **************************************************************************************/
- 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;
- }
- }
- }
- /**************************************************************************************
- * 名 稱:
- * 功 能:
- * 參 數(shù):
- * 返 回 值:
- *
- * 修改歷史:
- * 版本 日期 作者
- * ----------------------------------------------------
- * 1.0
- **************************************************************************************/
- void DispNum(unsigned int x, unsigned int y, unsigned short num)
- {
- unsigned char str[5];
- str[0] = num/1000+0x30;
- str[1] = (num%1000)/100+0x30;
- str[2] = (num%1000)%100/10+0x30;
- str[3] = (num%1000)%100%10+0x30;
- str[4] = '\0';
- DrawString(x, y, str, RED, YELLOW, NORMAL);
- }
- /**************************************************************************************
- * 名 稱: DispSmallPic
- * 功 能: 在指定的位置顯示一張65K色的圖片
- * 參 數(shù): str : 圖片數(shù)組名
- * 返 回 值: 無(wú)
- *
- * 修改歷史:
- * 版本 日期 作者
- * ----------------------------------------------------
- * 1.0
- **************************************************************************************/
- void DispSmallPic(uint x, uint y, uint w, uint h, const uchar *str)
- {
- uint i,j,temp;
- LCD_SetArea(x,y,x+w-1,y+h-1);
- send_command(0x2C);
- for(i=0;i<w*h;i++)
- { //send_data(*(unsigned short *)(&str[(j*w+i)*2])); //高位在前
- temp=str[(j*w+i)*2+1]<<8; //低位在前
- temp|=str[(j*w+i)*2];
- send_data(temp);
- }
- }
復(fù)制代碼 |
評(píng)分
-
查看全部評(píng)分
|