标题:
8位数据显示屏
[打印本页]
作者:
axp
时间:
2016-11-1 08:07
标题:
8位数据显示屏
/**************************************************************************************
* 名 称:
* 功 能:
* 参 数:
* 返 回 值:
*
* 修改历史:
* 版本 日期 作者
* ----------------------------------------------------
* 1.0
**************************************************************************************/
void send_command(unsigned int Cmd)
{
CS=0;
RS=0;
num_out=Cmd; RW=0;RW=1;
CS=1;
}
/**************************************************************************************
* 名 称:
* 功 能:
* 参 数:
* 返 回 值:
*
* 修改历史:
* 版本 日期 作者
* ----------------------------------------------------
* 1.0
**************************************************************************************/
void send_byte(uchar Data)
{
RS=1;
CS=0; num_out=Data; RW=0;RW=1; CS=1;
}
/**************************************************************************************
* 名 称:
* 功 能:
* 参 数:
* 返 回 值:
*
* 修改历史:
* 版本 日期 作者
* ----------------------------------------------------
* 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;
}
/**************************************************************************************
* 名 称:
* 功 能:
* 参 数:
* 返 回 值:
*
* 修改历史:
* 版本 日期 作者
* ----------------------------------------------------
* 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;
}
/**************************************************************************************
* 名 称:
* 功 能:
* 参 数:
* 返 回 值:
*
* 修改历史:
* 版本 日期 作者
* ----------------------------------------------------
* 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);
}
/**************************************************************************************
* 名 称:
* 功 能:
* 参 数:
* 返 回 值:
*
* 修改历史:
* 版本 日期 作者
* ----------------------------------------------------
* 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);
}
/**************************************************************************************
* 名 称:
* 功 能:
* 参 数:
* 返 回 值:
*
* 修改历史:
* 版本 日期 作者
* ----------------------------------------------------
* 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
* 功 能: 全屏显示某种颜色
* 参 数: Color : 颜色值
* 返 回 值: 无
*
* 修改历史:
* 版本 日期 作者
* ----------------------------------------------------
* 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
* 功 能: 清除显示屏的显示内容
* 参 数: 无
* 返 回 值: 无
*
* 修改历史:
* 版本 日期 作者
* ----------------------------------------------------
* 1.0
**************************************************************************************/
void DispClear(void)
{
DispOneColor(BLACK);
}
/**************************************************************************************
* 名 称: DrawSingleAscii
* 功 能: 在指定的位置单个字符
* 参 数: x : x坐标
* y : y坐标
* LineColor : 字符的颜色
* FillColor : 字符背景颜色
* 返 回 值: 无
*
* 修改历史:
* 版本 日期 作者
* ----------------------------------------------------
* 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
* 功 能: 在指定的位置显示汉字
* 参 数: x : x坐标
* y : y坐标
* LineColor : 汉字的颜色
* FillColor : 汉字背景颜色
* 返 回 值: 无
*
* 修改历史:
* 版本 日期 作者
* ----------------------------------------------------
* 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;
//---------------------------统计是否在字库中出现
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
* 功 能: 在指定的位置显示多个字符
* 参 数: x : x坐标
* y : y坐标
* LineColor : 字符的颜色
* FillColor : 字符背景颜色
* 返 回 值: 无
*
* 修改历史:
* 版本 日期 作者
* ----------------------------------------------------
* 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;
}
}
}
/**************************************************************************************
* 名 称:
* 功 能:
* 参 数:
* 返 回 值:
*
* 修改历史:
* 版本 日期 作者
* ----------------------------------------------------
* 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色的图片
* 参 数: str : 图片数组名
* 返 回 值: 无
*
* 修改历史:
* 版本 日期 作者
* ----------------------------------------------------
* 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);
}
}
复制代码
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1