楼下的你好啊:
我想的读TFT2.4’的像索 {MOD}数据,老是读出0X4368 的值,诚心求解。(TFT可以正常写入,相对坐标上画圈,显示字符,读出的ID:0X6809 )
以下用的代码:
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
/*************************************************
函数名:LCD_SetCursor
功能:设置光标位置
入口参数:xy坐标
返回值:无
*************************************************/
__inline void LCD_SetCursor(uint16_t Xpos, uint16_t Ypos)
{
LCD_WriteReg(0X20, Xpos);
LCD_WriteReg(0X21, Ypos);
}
//写寄存器函数
void LCD_WR_REG(uint16_t data)
{
LCD_RS_CLR;//写地址
LCD_CS_CLR;
DATAOUT(data);
LCD_WR_CLR;
LCD_WR_SET;
LCD_CS_SET;
}
void LCD_WR_DATA(uint16_t data)
{
LCD_RS_SET;
LCD_CS_CLR;
DATAOUT(data);
LCD_WR_CLR;
LCD_WR_SET;
LCD_CS_SET;
}
//读LCD数据
//返回值:读到的值
uint16_t LCD_RD_DATA(void)
{
uint16_t t;
GPIOD->MODER=0;
LCD_RS_SET;
LCD_CS_CLR;
//读取数据(读寄存器时,并不需要读2次)
LCD_RD_CLR;
delay_us(1); //FOR 8989,延时2us
LCD_RD_SET;
t=DATAIN;
LCD_CS_SET;
GPIOD->MODER=0X55555555; //PD0-15 输出
return t;
}
//读寄存器
uint16_t LCD_ReadReg(uint8_t reg)
{
LCD_WR_REG(reg); //写入要读的寄存器号
return LCD_RD_DATA();
}
//******************************************************************
//函数名: LCD_WriteReg
//功能: 写寄存器数据
//输入参数:LCD_Reg:寄存器地址
// LCD_RegValue:要写入的数据
//返回值: 无
//修改记录:无
//******************************************************************
void LCD_WriteReg(uint16_t LCD_Reg, uint16_t LCD_RegValue)
{
LCD_WR_REG(LCD_Reg);
LCD_WR_DATA(LCD_RegValue);
}
//******************************************************************
//函数名: LCD_WriteRAM_Prepare
//功能: 开始写GRAM
// 在给液晶屏传送RGB数据前,应该发送写GRAM指令
//输入参数:无
//返回值: 无
//修改记录:无
//******************************************************************
void LCD_WriteRAM_Prepare(void)
{
//LCD_WR_REG(R34);
LCD_WR_REG(0X22);
}
//读取个某点的颜 {MOD}值
//x,y:坐标
//返回值:此点的颜 {MOD}
uint16_t LCD_ReadPoint(uint16_t x,uint16_t y)
{
LCD_SetCursor(x,y);//设置光标位置
LCD_WriteRAM_Prepare();//开始写入GRAM
LCD_RD_DATA();
return LCD_RD_DATA();
}
TFT INIT
//初始化lcd
//该初始化函数可以初始化各种ILI93XX液晶,但是其他函数是基于ILI9320的!!!
//在其他型号的驱动芯片上没有测试!
void LCD_Init(void)
{
uint16_t t;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); /* 打开GPIO时钟 */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; /* 设为输出口 */
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; /* 设为开漏模式 */
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; /* 上下拉电阻不使能 */
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; /* IO口最大速度 */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_Init(GPIOD, &GPIO_InitStructure);
// RCC->APB1ENR|=1<<2;//先使能外设PORTB时钟
// RCC->APB1ENR|=1<<3;//先使能外设PORTC时钟
//RCC->APB2ENR|=1<<0; //开启辅助时钟
//JTAG_Set(SWD_ENABLE); //开启SWD
//PORTC6~10复用推挽输出
GPIOC->UPDR = 0X00555000;
GPIOC->MODER= 0X000555000; //PD0-15 输入
GPIOC->ODR=0X0FC0; //全部输出高
LCD_RST_SET;
delay_ms(50);
LCD_RST_CLR;
delay_ms(50);
LCD_RST_SET
delay_ms(50); // delay 50 ms
LCD_WriteReg(0x0000,0x0001);
delay_ms(50); // delay 50 ms
//LCD_WR_REG(0X0000);
LCD_id = LCD_ReadReg(0);
if(t == 0xffff)
{
__NOP();
}
LCD_WriteReg(0x00e7,0x0010);
LCD_WriteReg(0x0000,0x0001);//开启内部时钟
LCD_WriteReg(0x0001,0x0100);
LCD_WriteReg(0x0002,0x0700);//电源开启
//LCD_WriteReg(0x0003,(1<<3)|(1<<4) ); //65K RGB
//DRIVE TABLE(寄存器 03H)
//BIT3=AM BIT4:5=ID0:1
//AM ID0 ID1 FUNCATION
// 0 0 0 R->L D->U
// 1 0 0 D->U R->L
// 0 1 0 L->R D->U
// 1 1 0 D->U L->R
// 0 0 1 R->L U->D
// 1 0 1 U->D R->L
// 0 1 1 L->R U->D 正常就用这个.
// 1 1 1 U->D L->R
LCD_WriteReg(0x0003,(1<<12)|(3<<4)|(0<<3) );//65K
LCD_WriteReg(0x0004,0x0000);
LCD_WriteReg(0x0008,0x0207);
LCD_WriteReg(0x0009,0x0000);
LCD_WriteReg(0x000a,0x0000);//display setting
LCD_WriteReg(0x000c,0x0001);//display setting
LCD_WriteReg(0x000d,0x0000);//0f3c
LCD_WriteReg(0x000f,0x0000);
//电源配置
LCD_WriteReg(0x0010,0x0000);
LCD_WriteReg(0x0011,0x0007);
LCD_WriteReg(0x0012,0x0000);
LCD_WriteReg(0x0013,0x0000);
delay_ms(50);
LCD_WriteReg(0x0010,0x1590);
LCD_WriteReg(0x0011,0x0227);
delay_ms(50);
LCD_WriteReg(0x0012,0x009c);
delay_ms(50);
LCD_WriteReg(0x0013,0x1900);
LCD_WriteReg(0x0029,0x0023);
LCD_WriteReg(0x002b,0x000e);
delay_ms(50);
LCD_WriteReg(0x0020,0x0000);
LCD_WriteReg(0x0021,0x013f);
delay_ms(50);
//伽马校正
LCD_WriteReg(0x0030,0x0007);
LCD_WriteReg(0x0031,0x0707);
LCD_WriteReg(0x0032,0x0006);
LCD_WriteReg(0x0035,0x0704);
LCD_WriteReg(0x0036,0x1f04);
LCD_WriteReg(0x0037,0x0004);
LCD_WriteReg(0x0038,0x0000);
LCD_WriteReg(0x0039,0x0706);
LCD_WriteReg(0x003c,0x0701);
LCD_WriteReg(0x003d,0x000f);
delay_ms(50);
LCD_WriteReg(0x0050,0x0000); //水平GRAM起始位置
LCD_WriteReg(0x0051,0x00ef); //水平GRAM终止位置
LCD_WriteReg(0x0052,0x0000); //垂直GRAM起始位置
LCD_WriteReg(0x0053,0x013f); //垂直GRAM终止位置
LCD_WriteReg(0x0060,0xa700);
LCD_WriteReg(0x0061,0x0001);
LCD_WriteReg(0x006a,0x0000);
LCD_WriteReg(0x0080,0x0000);
LCD_WriteReg(0x0081,0x0000);
LCD_WriteReg(0x0082,0x0000);
LCD_WriteReg(0x0083,0x0000);
LCD_WriteReg(0x0084,0x0000);
LCD_WriteReg(0x0085,0x0000);
LCD_WriteReg(0x0090,0x0010);
LCD_WriteReg(0x0092,0x0000);
LCD_WriteReg(0x0093,0x0003);
LCD_WriteReg(0x0095,0x0110);
LCD_WriteReg(0x0097,0x0000);
LCD_WriteReg(0x0098,0x0000);
//开启显示设置
LCD_WriteReg(0x0007,0x0133);
LCD_WriteReg(0x0020,0x0000);
LCD_WriteReg(0x0021,0x013f);
//LCD_LED=1;//点亮背光
LCD_LED_SET;
LCD_Clear(BRRED);
}
然后主函数
int main(void)
{
// uint16_t ucStatus,i;
uint8_t x=0;
uint16_t id,j,i;
bsp_InitUart();
PrintfLogo(); /* 打印例程Logo到串口1 */
delay_init(168); //延时初始化
LCD_Init();
LCD_Clear(0x0000);
id = LCD_ReadPoint(10,10);
if(id == 0xa255)
{
__NOP();
}
LCD_WritePoint(2,10,0xa155);
id = LCD_ReadPoint(2,10);
if(id == 0xa155)
{
__NOP();
}
。。。。。。
}
在主函数上的粗体字体读出的“id”变量数值总是0X4368 .(如果用正常读出的数据应该是我输入 的数据,即输入0X0000应该读出的就是0X0000。)
一周热门 更多>