微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > arm之TFT

arm之TFT

时间:11-26 来源:互联网 点击:

void LCD_SPIConfig(void)
{
SPI_InitTypeDefSPI_InitStructure;
GPIO_InitTypeDefGPIO_InitStructure;


RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);


RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);


GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);


SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;

SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(SPI2, &SPI_InitStructure);


SPI_Cmd(SPI2, ENABLE);
}

void LCD_DrawChar(u8 Ypos, u8 Xpos, uc8 *c)
{
u32 index = 0, i = 0;

LCD_SelectRegion(Xpos, Ypos, Xpos+XPIXES -1, Ypos+YPIXES-1);

for(index = 0;index{

for(i = 0; i < XPIXES; i++)
{
if((c[index]&(0x80>>i)) == 0x00)
{
LCD_WriteDat(BackColor>>8);
LCD_WriteDat(BackColor&0xff);
}
else
{
LCD_WriteDat(TextColor>>8);
LCD_WriteDat(TextColor&0xff);
}
}
}
}

void LCD_SetTextColor(vu16 Color)
{
TextColor = Color;
}

void LCD_SetBackColor(vu16 Color)
{
BackColor = Color;
}

void LCD_ClearLine(u8 Line)
{
LCD_DisplayStringLine(Line, 0, "");
}

void LCD_DisplayStringLine(u8 Line, u8 Column, u8 *ptr)
{
u32 i = 0;
u8 refcolumn = Column;//319;

Line = Line*YPIXES;


while ((*ptr != 0) & (i < 16)) //mary??16 chars one line.
{

LCD_DisplayChar(Line, refcolumn, *ptr);

refcolumn += XPIXES;

ptr++;

i++;

//add for change lines.

}
}


void LCD_DisplayChar(u8 Line, u8 Column, u8 Ascii)
{
LCD_DrawChar(Line, Column, &g_ucAscii8x16[Ascii * 16]);
}

void LCD_DisplayPoint(u8 u8Xpos, u8 u8Ypos, vu16 u16Color)
{
LCD_WriteReg(0x2a);//XS15-XS8
LCD_WriteDat(0);
LCD_WriteDat(u8Xpos);//XS7-XS0(X start address)
LCD_WriteDat(0);//XE15-XE8
LCD_WriteDat(u8Xpos);//XE7-XE0(X end address)

//row address set (RASET)
LCD_WriteReg(0x2b);//YS15-YS8
LCD_WriteDat(0);//YS7-YS0(Y start
LCD_WriteDat(u8Ypos);//YE15-YE8
LCD_WriteDat(0);
LCD_WriteDat(u8Ypos);//YE7-YE0(Y end address)

LCD_WriteReg(0x2c);

LCD_WriteDat(u16Color>>8);
LCD_WriteDat(u16Color&0xff);
}

void Xiexian(u8 x1,u8 y1,u8 x2,u8 y2,u16 color)
{
u16 t;
u16 xerr=0,yerr=0,delta_x,delta_y,distance;
u16 incx,incy;
u16 row,col;
delta_x = x2-x1;//计算坐标增量
delta_y = y2-y1;
col=x1;
row=y1;
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;

for(t=0;t<=distance+1;t++)
{//画线输出
LCD_DisplayPoint(col,row,color);
xerr+=delta_x;
yerr+=delta_y;
if(xerr>distance)
{
xerr-=distance;
col+=incx;
}
if(yerr>distance)
{
yerr-=distance;
row+=incy;
}
}
}

void LCD_SelectRegion(u8 u8XBpos, u8 u8YBpos, u8 u8XEpos, u8 u8YEpos)
{
LCD_WriteReg(0x2a);//column address set
LCD_WriteDat(0);//XS15-XS8
LCD_WriteDat(u8XBpos);//XS7-XS0 //X Start ADD
LCD_WriteDat(0);//XE15-XE8
LCD_WriteDat(u8XEpos);//XE7-XE0 //X End ADD

LCD_WriteReg(0x2b);//row address set
LCD_WriteDat(0);//YS15-YS8
LCD_WriteDat(u8YBpos);//YS7-YS0 //Y Start ADD
LCD_WriteDat(0);//YE15-YE8
LCD_WriteDat(u8YEpos);//YE7-YE0 //Y End ADD

LCD_WriteReg(0x2c);
}

void LCD_DrawCircle(u8 Xpos, u8 Ypos, u8 Radius)
//使用格式:(X坐标,y坐标,半径)
{
s32D;
u32CurX;
u32CurY;

D = 3 - (Radius < 1);
CurX = 0;
CurY = Radius;

//LCD_Display_Color(BackColor);

while (CurX <= CurY)
{
LCD_DisplayPoint(Xpos + CurX, Ypos + CurY, TextColor);
LCD_DisplayPoint(Xpos + CurX, Ypos - CurY, TextColor);
LCD_DisplayPoint(Xpos - CurX, Ypos + CurY, TextColor);
LCD_DisplayPoint(Xpos - CurX, Ypos - CurY, TextColor);

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top