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

arm之TFT

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

#include "stm32f10x_spi.h"
#include "main.h"
#include "FONTs.h"
#include "lcd.h"

void LCD_WriteReg(u8 LCD_RegValue);
void LCD_WriteDat(u8 LCD_DatValue);


staticvu16 TextColor = 0x0000, BackColor = 0xFFFF;

#defineGREEN0x07e0
#defineRED0xF800
#defineBLUE0x001f
#define XPIXES 8
#define YPIXES 16
//所有函数的目录及函数功能


void STM3210B_LCD_Init(void)
{


RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB| RCC_APB2Periph_GPIOD | RCC_APB1Periph_SPI2, ENABLE);


LCD_CtrlLinesConfig();


LCD_SPIConfig();

//Start
LCD_CtrlLinesWrite(GPIOB, CtrlPin_NCS, Bit_RESET);
LCD_CtrlLinesWrite(GPIOD, CtrlPin_NWR, Bit_SET);
Delay(1);
LCD_CtrlLinesWrite(GPIOD, CtrlPin_NWR, Bit_RESET);
Delay(10);
LCD_CtrlLinesWrite(GPIOD, CtrlPin_NWR, Bit_SET);


LCD_WriteReg(0x11);
Delay(10);

LCD_WriteReg(0x0c0);
LCD_WriteDat(0x05);

LCD_WriteReg(0x0c5);
LCD_WriteDat(0x0d1);

LCD_WriteReg(0x0c6);
LCD_WriteDat(0x17);
Delay(10);

LCD_WriteReg(0x0e0);
LCD_WriteDat(0x00);
LCD_WriteDat(0x01);
LCD_WriteDat(0x0c);
LCD_WriteDat(0x29);
LCD_WriteDat(0x27);
LCD_WriteDat(0x0b);
LCD_WriteDat(0x11);
LCD_WriteDat(0x06);
LCD_WriteDat(0x06);
LCD_WriteDat(0x05);
LCD_WriteDat(0x0e);
LCD_WriteDat(0x0f);
LCD_WriteDat(0x00);
LCD_WriteDat(0x03);
LCD_WriteDat(0x04);
LCD_WriteDat(0x08);

LCD_WriteReg(0x0e1);
LCD_WriteDat(0x06);
LCD_WriteDat(0x1f);
LCD_WriteDat(0x20);
LCD_WriteDat(0x16);
LCD_WriteDat(0x0a);
LCD_WriteDat(0x04);
LCD_WriteDat(0x04);
LCD_WriteDat(0x10);
LCD_WriteDat(0x06);
LCD_WriteDat(0x03);
LCD_WriteDat(0x03);
LCD_WriteDat(0x02);
LCD_WriteDat(0x0e);
LCD_WriteDat(0x0d);
LCD_WriteDat(0x05);
LCD_WriteDat(0x05);

LCD_WriteReg(0x2a);
LCD_WriteDat(0x00);
LCD_WriteDat(0x00);
LCD_WriteDat(0x00);
LCD_WriteDat(0x7f);

LCD_WriteReg(0x2b);//row address set
LCD_WriteDat(0x00);
LCD_WriteDat(0x00);
LCD_WriteDat(0x00);
LCD_WriteDat(0x9f);

LCD_WriteReg(0x3a);
LCD_WriteDat(0x55);

LCD_WriteReg(0x36);//memory data access control(MADCTR)
LCD_WriteDat(0x00);//MY=0; MX=0; MV=0; ML=1; RGB=0

LCD_WriteReg(0x29);//display on
Delay(20);
}

void LCD_WriteReg(u8 LCD_RegValue)
{
LCD_CtrlLinesWrite(GPIOB, CtrlPin_NCS, Bit_RESET);
LCD_CtrlLinesWrite(GPIOD, CtrlPin_RS, Bit_RESET);


while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE)==RESET);

SPI_I2S_SendData(SPI2, LCD_RegValue);

while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) != RESET)
{
}
}

void LCD_WriteDat(u8 LCD_DatValue)
{
LCD_CtrlLinesWrite(GPIOB, CtrlPin_NCS, Bit_RESET);
LCD_CtrlLinesWrite(GPIOD, CtrlPin_RS, Bit_SET);


while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE)==RESET);

SPI_I2S_SendData(SPI2, LCD_DatValue);

while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) != RESET)
{
}
}

void LCD_Display_Color(u16 ColorValue)
{
u8 i,j;
u16 tmp;
//column address set (CASET)
LCD_WriteReg(0x2a);//XS15-XS8
LCD_WriteDat(0x00);
LCD_WriteDat(0x00);//XS7-XS0(X start address)
LCD_WriteDat(0x00);//XE15-XE8
LCD_WriteDat(0x7f);//XE7-XE0(X end address)
//row address set (RASET)
LCD_WriteReg(0x2b); //YS15-YS8
LCD_WriteDat(0x00);//YS7-YS0(Y start
LCD_WriteDat(0x00);//YE15-YE8
LCD_WriteDat(0x00);
LCD_WriteDat(0x9f);//YE7-YE0(Y end address)

LCD_WriteReg(0x2c);//YE7-YE0(Y end address)

for(i=160;i>0;i--)
for(j=128;j>0;j--)
{
tmp=((ColorValue>>8)&0x00ff);
LCD_WriteDat(tmp);
tmp=(ColorValue&0x00ff);
LCD_WriteDat(tmp);
}
}

void LCD_CtrlLinesWrite(GPIO_TypeDef* GPIOx, u16 CtrlPins, BitAction BitVal)
{

GPIO_WriteBit(GPIOx, CtrlPins, BitVal);
}

void LCD_CtrlLinesConfig(void)
{
GPIO_InitTypeDef GPIO_InitStructure;


GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_13 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);


GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_15;
GPIO_Init(GPIOD, &GPIO_InitStructure);



LCD_CtrlLinesWrite(GPIOD, CtrlPin_NWR, Bit_SET);
LCD_CtrlLinesWrite(GPIOD, CtrlPin_RS, Bit_SET);
}

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

网站地图

Top