📄 lcd.c
字号:
void LCD_Putpixel(uchar x,uchar y)
{
uchar b;
uint addr = LCD_GRAPH_HOME_ADDR + y * LCD_WIDTH + x / 8;
b = 7 - (x % 8);
LCD_WriteInt(addr,0x24);
LCD_Comm(0xf8|b);
}
/* x,y处显示光标 */
/*
void LCD_ShowCursor(uchar x,uchar y)
{
//LCD_CE = 0;
LCD_Comm(0x97); //光标开
LCD_Write2(x,y,0x21);
}
*/
/* 取消光标 */
/*
void LCD_HideCursor(void)
{
//LCD_CE = 0;
LCD_Comm(0x9c);
}
*/
void LCD_PutImg(uchar x,uchar y,uchar w,uchar h,uchar *img)
{
uint data addr;
uchar data i,j;
uchar data c;
addr = LCD_GRAPH_HOME_ADDR + LCD_WIDTH * y + (x >> 3);
//LCD_CE = 0;
for(j=0;j<h;j++)
{
LCD_WriteInt(addr,0x24);
LCD_Comm(0xb0);
for(i=0;i<w;i++)
{
c = img[j*w+i] ;
LCD_AutoWrite(c);
//LCD_WriteInt(addr +i,0x24); //+ LCD_WIDTH *j
//LCD_Write1(c,0xc0);
}
LCD_Comm(0xb2);
addr += LCD_WIDTH;
}
}
/*
void LCD_PrintNumStr(uchar x,uchar y,uchar *s)
{
x =(x / 8) * 8;
while(*s)
{
LCD_PutImg(x,y,1,11,Num_Tab + (*s - '0') * 11);
x = x + 8;
s++;
}
}
void LCD_PrintBlackBlock(uchar x,uchar y,bool not_empty)
{
x =(x / 8) * 8;
LCD_PutImg(x,y,1,11,BlockTab + (not_empty?0:1) * 11);
}
*/
void LCD_ReverseRect(uchar x,uchar y,uchar w,uchar h)
{
uint data addr;
uchar data i,j;
uchar data c;
x =(x / 8) * 8;
addr = LCD_GRAPH_HOME_ADDR + LCD_WIDTH * y + x/8;
for(j=0;j<h;j++)
{
for(i=0;i<w;i++)
{
LCD_WriteInt(addr +i,0x24);
LCD_Comm(LC_NOC_RD);
c = LCD_Read();
c = ~c;
LCD_Write1(c,LC_NOC_WR);
}
addr += LCD_WIDTH;
}
}
/*
void LCD_PrintWord(uchar x,uchar y,uint16 n,uchar start)
{
uchar buf[4];
int i;
if(start > 3) start = 0;
for(i = 0; i < 4; i++)
{
buf[i] = n % 10;
n /= 10;
}
x =(x / 8) * 8;
for(i = 3-start; i >= 0; i--)
{
LCD_PutImg(x,y,1,11,Num_Tab + buf[i] * 11);
x = x + 8;
}
}
void LCD_PrintHex(uchar x,uchar y,uchar hex)
{
uchar c1,c2;
//低4位
c1 = hex & 0x0f; //lo
//高4位
c2 = (hex >> 4) & 0x0f; //hi
LCD_PutImg(x,y,1,11,Num_Tab + c2 * 11);
LCD_PutImg(x+8,y,1,11,Num_Tab + c1 * 11);
}
void LCD_GrapPutchar(uchar x,uchar y,uchar num)
{
uchar i,j;
uchar dot;
num = (num- '0')*9;
//LCD_CE = 0;
for(i=0; i< 12;i++)
{
dot = Num_Tab[num + i];
for(j = 0; j < 7; j++)
{
if( dot & 0x80)
LCD_Putpixel(x+j,y);
else
LCD_ClrPixel(x+j,y);
dot <<= 1;
}
y++;
}
}
void LCD_GrapPrint(uchar x,uchar y,uchar code *s)
{
while(*s)
{
LCD_GrapPutchar(x,y,*s);
x += 8;
s++;
}
}
*/
/*--------------显示字符------------------*/
/*
void LCD_TextPutchar(uchar x,uchar y,uchar c)
{
//LCD_CE = 0;
LCD_WriteInt(LCD_TEXT_HOME_ADDR + LCD_WIDTH * y + x,0x24);
LCD_Comm(0xb0);
LCD_AutoWrite(c - 0x20);
LCD_Comm(0xb2);
}
void LCD_TextPrint(uchar x,uchar y,char *s)
{
//LCD_CE = 0;
LCD_WriteInt(LCD_TEXT_HOME_ADDR + LCD_WIDTH * y + x,0x24);
LCD_Comm(0xb0);
while(*s)
{
LCD_AutoWrite(*s - 0x20);
s++;
}
LCD_Comm(0xb2);
}
void LCD_TextPrintWord(uchar x,uchar y,uint16 n,uchar start)
{
uchar buf[4];
int i;
if(start > 3) start = 0;
for(i = 0; i < 4; i++)
{
buf[i] = n % 10;
n /= 10;
}
for(i = 3-start; i >= 0; i--)
{
LCD_TextPutchar(x,y,'0' + buf[i]);
x ++;
}
}
void LCD_TextPrintHex(uchar x,uchar y,uchar hex)
{
uchar c1,c2;
//低4位
c1 = hex & 0x0f; //lo
//高4位
c2 = (hex >> 4) & 0x0f; //hi
LCD_TextPutchar(x,y,HexTable[c2]);
LCD_TextPutchar(x+1,y,HexTable[c1]);
}
*/
/************************************************/
/*画线。任意方向的斜线,直线数学方程 aX+bY=1 */
/************************************************/
/*
void LCD_Linexy(uchar x0,uchar y0,uchar xt,uchar yt)
{
register uchar t;
int xerr=0,yerr=0,delta_x,delta_y,distance;
int incx,incy,uRow,uCol;
delta_x = xt-x0; //计算坐标增量
delta_y = yt-y0;
uRow = x0;
uCol = y0;
if(delta_x>0) incx=1; //设置单步方向
else if( delta_x==0 ) incx=0; //垂直线
else {incx=-1;delta_x=-delta_x;}
if(delta_y>0) incy=1;
else if( delta_y==0 ) incy=0; //水平线
else {incy=-1;delta_y=-delta_y;}
if( delta_x > delta_y ) distance=delta_x; //选取基本增量坐标轴
else distance=delta_y;
//LCD_CE = 0;
for( t=0;t <= distance+1; t++ )
{ //画线输出
LCD_Putpixel(uRow,uCol); //画点
xerr += delta_x ;
yerr += delta_y ;
if( xerr > distance )
{
xerr-=distance;
uRow+=incx;
}
if( yerr > distance )
{
yerr-=distance;
uCol+=incy;
}
}
}
*/
void LCD_LineH(uchar y)
{
char i;
//LCD_CE = 0;
LCD_WriteInt(LCD_GRAPH_HOME_ADDR + LCD_WIDTH * y ,0x24);
LCD_Comm(0xb0);
for(i=0;i<LCD_WIDTH;i++)
LCD_AutoWrite(0xff);
LCD_Comm(0xb2);
}
void LCD_LineV(uchar x,uchar y1,uchar y2)
{
int i;
//LCD_CE = 0;
for(i = y1; i < y2; i++)
{
LCD_Putpixel(x,i);
}
}
void LCD_LineXX(uchar x1,uchar x2,uchar y)
{
int i;
for(i = x1; i < x2; i++)
{
LCD_Putpixel(i,y);
}
}
/*
void LCD_Rectange(uchar x1,uchar y1,uchar x2,uchar y2)
{
LCD_LineXX(x1,x2,y1);
LCD_LineXX(x1,x2,y2);
LCD_LineV(x1,y1,y2);
LCD_LineV(x2,y1,y2);
}
*/
FNT_GB12 code *GetHzk12(uchar c1,uchar c2)
{
int i = 0;
while(HZK12[i].Index[0] != 0)
{
if(c1 == HZK12[i].Index[0] && c2 == HZK12[i].Index[1])
return &HZK12[i];
i ++;
}
return NULL;
}
FNT_GB16 code *GetHzk16(uchar c1,uchar c2)
{
int i = 0;
while(HZK16[i].Index[0] != 0)
{
if(c1 == HZK16[i].Index[0] && c2 == HZK16[i].Index[1])
return &HZK16[i];
i ++;
}
return NULL;
}
void LCD_PrintHz12(uchar x,uchar y,uchar *s)
{
uchar c1,c2;
//x坐标必需是8位对齐
x =(x / 8) * 8;
while(*s)
{
c1 = *s++;
if(c1 == ' ')
x += 8;
else if( c1 > 0x80)
{
//汉字
c2 = *s++;
LCD_PutImg(x,y+2,2,12,GetHzk12(c1,c2)->Msk);
x += 16;
}
else //ASCII
{
LCD_PutImg(x,y,1,16,ASC8x16[c1]); //-
x += 8;
}
}
}
void LCD_PrintHz16(uchar x,uchar y,uchar *s)
{
uchar c1,c2;
//x坐标必需是8位对齐
x =(x / 8) * 8;
while(*s)
{
c1 = *s++;
if(c1 == ' ')
{
x += 8;
}
else if( c1 > 0x80)
{
//汉字
c2=*s++;
LCD_PutImg(x,y,2,16,GetHzk16(c1,c2)->Msk);
x += 16;
}
else //ASCII
{
LCD_PutImg(x,y+2,1,16,ASC8x16[c1]); //-
x += 8;
}
}
}
//显示6x8的数字
void LCD_Print6X8(uchar x, uchar y,uchar *s)
{
//x坐标必需是8位对齐
x =(x / 8) * 8;
while(*s)
{
LCD_PutImg(x,y,1,8,font6x8[*s - 32]); //-
x += 8;
s ++;
}
}
//显示24x32的数字
void LCD_Print24X32(uchar x, uchar y,uchar *s)
{
//x坐标必需是8位对齐
x =(x / 8) * 8;
while(*s)
{
if( *s >= '0' && *s <= '9') //显示
{
LCD_PutImg(x,y,3,32,Font24X32[*s-'0']);
x += 24;
}
else if( *s == ' ')
{
x += 8;
}
else
{
LCD_PutImg(x,y+16,1,16,ASC8x16[*s]); //-
x += 8;
}
s ++;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -