ili9481.c
来自「STM32F103VET6驱动CMOS摄像头」· C语言 代码 · 共 1,131 行 · 第 1/2 页
C
1,131 行
buf+=length_null;//偏移多出的那段BMP 跳过去
}
}
void TFT_OV(u16 x_star,u16 y_star,u16 length,u16 height,u8 val)
{
u16 i=0,length_null=0;
u16 j=0,k;
//CHECK_LOC(x_star,y_star);
//如果超出屏幕范围,则计算超出的长度
if(x_star+length>MAX_X)
{
length_null=x_star+length-MAX_X;
}
//如果超出屏幕范围,则计算可用的高度
if(y_star+height>MAX_Y)
{
height-=y_star+height-MAX_Y;
}
TFT_WriteIndex(R2C);
for(j=0;j<height;j++)
{
TFTSetXY(x_star,y_star);//Y0会跟随变化,所以要放到循环中执行
for(i=0;i<length;i++)
{
k=val;
TFT_WriteData((val<<8)|k);
}
y_star++;
// buf+=length_null;//偏移多出的那段BMP 跳过去
}
}
/*void lcd_displaychar(unsigned int row, unsigned int column, unsigned char *asc)
{
u16 i=0;
u16 j=0;
for (i=0;i<16;i++)
{
for (j=0;j<8;j++)
{
if ( (*asc >> 7-j) & 0x01 == 0x01)
{
TFT_SetPoint(row+j,column+i,Txt_Color); // 字符颜色
}
else
{
TFT_SetPoint(row+j,column+i,Back_Ground); // 背景颜色
}
}
*asc++;
}
lcd_set_cursor(row, column+8);//光标放到下一个字符起始处
}
*/
/*---------------------------------------------------------------------------
功能: 画英文字符 8宽*16高
---------------------------------------------------------------------------*/
void TFT_DisplayChar(unsigned int row, unsigned int column, unsigned char ascii)
{
unsigned char i = 0, j = 0;
unsigned int z = row;
for (j = 0; j < 16; j++)
{
lcd_set_cursor(z, column);
TFT_WriteIndex(R2C);//写GRAM之前 要先写0x002C
for (i = 0; i< 8; i++)
{
if (font[ascii-32][j] & (0x80>>i)) //空格 ascii =32
{
TFT_WriteData(Txt_Color);
}
else
{
TFT_WriteData(Back_Ground);
}
}
z++;
}
lcd_set_cursor(row, column+8);//光标放到下一个字符起始处
}
/*******************************************************************************
* Function Name : LCD_DisplayStringLine
* Description : Displays a maximum of 20 char on the LCD.
* Input : - Line: the Line where to display the character shape .
* This parameter can be one of the following values:
* - Linex: where x can be 0..9
* - *ptr: pointer to string to display on LCD.
* Output : None
* Return : None
*******************************************************************************/
void TFT_DisplayString(u8 Line,u16 refcolumn, u8 *ptr)
{
/* Send the string character by character on lCD */
while ((*ptr != 0))
{
/* Display one character on LCD */
TFT_DisplayChar(refcolumn, Line, *ptr);
/* Decrement the column position by 16 */
//refcolumn+= 16;
Line+=8;
/* Point on the next character */
ptr++;
/* Increment the character counter */
}
}
/*void LCD_DisplayStringLine(u8 Line, u8 *ptr)
{
u32 i = 0;
u16 refcolumn = 0;
// Send the string character by character on lCD
while ((*ptr != 0) & (i < 15))
{
// Display one character on LCD
LCD_DisplayChar(refcolumn, Line, *ptr);
// Decrement the column position by 16
refcolumn+= 16;
// Point on the next character
ptr++;
// Increment the character counter
i++;
}
}
*/
void TFT_DrawCircle(u8 Xpos, u16 Ypos, u16 Radius)
{
s32 D;/* Decision Variable */
u32 CurX;/* Current X Value */
u32 CurY;/* Current Y Value */
D = 3 - (Radius << 1);
CurX = 0;
CurY = Radius;
while (CurX <= CurY)
{
TFT_SetCursor(Xpos + CurX, Ypos + CurY);
TFT_WriteIndex(R2C);
TFT_WriteData(Txt_Color);
TFT_SetCursor(Xpos + CurX, Ypos - CurY);
TFT_WriteIndex(R2C);
TFT_WriteData(Txt_Color);
TFT_SetCursor(Xpos - CurX, Ypos + CurY);
TFT_WriteIndex(R2C);
TFT_WriteData(Txt_Color);
TFT_SetCursor(Xpos - CurX, Ypos - CurY);
TFT_WriteIndex(R2C);
TFT_WriteData(Txt_Color);
TFT_SetCursor(Xpos + CurY, Ypos + CurX);
TFT_WriteIndex(R2C);
TFT_WriteData(Txt_Color);
TFT_SetCursor(Xpos + CurY, Ypos - CurX);
TFT_WriteIndex(R2C);
TFT_WriteData(Txt_Color);
TFT_SetCursor(Xpos - CurY, Ypos + CurX);
TFT_WriteIndex(R2C);
TFT_WriteData(Txt_Color);
TFT_SetCursor(Xpos - CurY, Ypos - CurX);
TFT_WriteIndex(R2C);
TFT_WriteData(Txt_Color);
if (D < 0)
{
D += (CurX << 2) + 6;
}
else
{
D += ((CurX - CurY) << 2) + 10;
CurY--;
}
CurX++;
}
}
/****************************************************************************
* 名 称:void GUI_Line(u16 x0, u16 y0, u16 x1, u16 y1,u16 color)
* 功 能:在指定座标画直线
* 入口参数:x0 A点行座标
* y0 A点列座标
* x1 B点行座标
* y1 B点列座标
* color 线颜色
* 出口参数:无
* 说 明:
* 调用方法:GUI_Line(0,0,240,320,0x0000);
****************************************************************************/
void GUI_Line(u16 x0, u16 y0, u16 x1, u16 y1,u16 color)
{
u16 x,y;
u16 dx;
u16 dy;
if(y0==y1)
{
if(x0<=x1)
{
x=x0;
}
else
{
x=x1;
x1=x0;
}
while(x <= x1)
{
TFT_SetPoint(x,y0,color);
x++;
}
return;
}
else if(y0>y1)
{
dy=y0-y1;
}
else
{
dy=y1-y0;
}
if(x0==x1)
{
if(y0<=y1)
{
y=y0;
}
else
{
y=y1;
y1=y0;
}
while(y <= y1)
{
TFT_SetPoint(x0,y,color);
y++;
}
return;
}
else if(x0 > x1)
{
dx=x0-x1;
x = x1;
x1 = x0;
y = y1;
y1 = y0;
}
else
{
dx=x1-x0;
x = x0;
y = y0;
}
if(dx == dy)
{
while(x <= x1)
{
x++;
if(y>y1)
{
y--;
}
else
{
y++;
}
TFT_SetPoint(x,y,color);
}
}
else
{
TFT_SetPoint(x, y, color);
if(y < y1)
{
if(dx > dy)
{
s16 p = dy * 2 - dx;
s16 twoDy = 2 * dy;
s16 twoDyMinusDx = 2 * (dy - dx);
while(x < x1)
{
x++;
if(p < 0)
{
p += twoDy;
}
else
{
y++;
p += twoDyMinusDx;
}
TFT_SetPoint(x, y,color);
}
}
else
{
s16 p = dx * 2 - dy;
s16 twoDx = 2 * dx;
s16 twoDxMinusDy = 2 * (dx - dy);
while(y < y1)
{
y++;
if(p < 0)
{
p += twoDx;
}
else
{
x++;
p+= twoDxMinusDy;
}
TFT_SetPoint(x, y, color);
}
}
}
else
{
if(dx > dy)
{
s16 p = dy * 2 - dx;
s16 twoDy = 2 * dy;
s16 twoDyMinusDx = 2 * (dy - dx);
while(x < x1)
{
x++;
if(p < 0)
{
p += twoDy;
}
else
{
y--;
p += twoDyMinusDx;
}
TFT_SetPoint(x, y,color);
}
}
else
{
s16 p = dx * 2 - dy;
s16 twoDx = 2 * dx;
s16 twoDxMinusDy = 2 * (dx - dy);
while(y1 < y)
{
y--;
if(p < 0)
{
p += twoDx;
}
else
{
x++;
p+= twoDxMinusDy;
}
TFT_SetPoint(x, y,color);
}
}
}
}
}
/****************************************************************************
* 名 称:void GUI_Circle(u16 cx,u16 cy,u16 r,u16 color,u8 fill)
* 功 能:在指定座标画圆,可填充
* 入口参数:
* 出口参数:
* 说 明:
* 调用方法:
****************************************************************************/
void GUI_Circle(u16 cx,u16 cy,u16 r,u16 color,u8 fill)
{
u16 x,y;
s16 delta,tmp;
x=0;
y=r;
delta=3-(r<<1);
while(y>x)
{
if(fill)
{
GUI_Line(cx+x,cy+y,cx-x,cy+y,color);
GUI_Line(cx+x,cy-y,cx-x,cy-y,color);
GUI_Line(cx+y,cy+x,cx-y,cy+x,color);
GUI_Line(cx+y,cy-x,cx-y,cy-x,color);
}
else
{
TFT_SetPoint(cx+x,cy+y,color);
TFT_SetPoint(cx-x,cy+y,color);
TFT_SetPoint(cx+x,cy-y,color);
TFT_SetPoint(cx-x,cy-y,color);
TFT_SetPoint(cx+y,cy+x,color);
TFT_SetPoint(cx-y,cy+x,color);
TFT_SetPoint(cx+y,cy-x,color);
TFT_SetPoint(cx-y,cy-x,color);
}
x++;
if(delta>=0)
{
y--;
tmp=(x<<2);
tmp-=(y<<2);
delta+=(tmp+10);
}
else
{
delta+=((x<<2)+6);
}
}
}
void TFT_DisplayHZ(unsigned int row, unsigned int column, u8 *chinese)
{
unsigned char i = 0, j = 0;
unsigned int z = row;
for (j = 0; j < 16; j++)//列
{
lcd_set_cursor(z, column);
TFT_WriteIndex(R2C);//写GRAM之前 要先写0x002C
for (i = 0; i < 8; i++)//前半行
{
if (*chinese & (0x80>>i))
{
TFT_WriteData(Txt_Color);
}
else
{
TFT_WriteData(Back_Ground);
}
}
*chinese++;
for (i = 0; i < 8; i++)//后半行
{
if (*chinese & (0x80>>i))
{
TFT_WriteData(Txt_Color);
}
else
{
TFT_WriteData(Back_Ground);
}
}
*chinese++;
z++;
}
lcd_set_cursor(row, column+16);//光标放到下一个字符起始处
}
/*---------------------------------------------------------------------------
功能: 画中文字符 16宽*16高
---------------------------------------------------------------------------*//*
void TFT_ShowChinese(unsigned int row, unsigned int column, unsigned long index)
{
unsigned char i = 0, j = 0;
unsigned int z = row;
for (j = 0; j < 16; j++)//列
{
lcd_set_cursor(z, column);
TFT_WriteIndex(R2C);//写GRAM之前 要先写0x002C
for (i = 0; i < 8; i++)//前半行
{
if (hzdot[index] & (0x80>>i))
{
TFT_WriteData(Txt_Color);
}
else
{
TFT_WriteData(Back_Ground);
}
}
for (i = 0; i < 8; i++)//后半行
{
if (hzdot[index+1] & (0x80>>i))
{
TFT_WriteData(Txt_Color);
}
else
{
TFT_WriteData(Back_Ground);
}
}
index += 2;//2*16=32个数据
z++;
}
lcd_set_cursor(row, column+16);//光标放到下一个字符起始处
}
/*---------------------------------------------------------------------------
功能: 显示字符串 中英文混合
---------------------------------------------------------------------------*/
/*
void TFT_DisplayAll(unsigned int row, unsigned int column, unsigned char *pdata)
{
unsigned int i = column;
unsigned int j = row;
while (*pdata)
{
if (*pdata < 128)
{
lcd_display_char(j, i, *pdata);
i += 8;
pdata += 1;
}
else
{
lcd_display_hzchar(j, i, pdata);
i += 16;
pdata += 2;
//delay_ms(20); //
}
if(i>319)//一行写满了
{
i=0;
j+=16;
delay_ms(20); //延时5秒
}
if(j>479)//整屏写满了
{
j=0;
delay_ms(5000); //延时5秒
TFT_Clear(YELLOW); //清屏为黄色背景
}
if ((i > 304)&&(*pdata > 128)&& (i!=320))//防止一行的最后半字
{
lcd_display_char(j, i, ' ');//清边界残留
i=0;
j+=16;
}
}
}
*/
/*---------------------------------E N D--------------------------------------*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?