📄 ltv.c
字号:
#include "xllp_gpio.h"
/*
CS GPIO100
CLK GPIO101
SDI GPIO102
RST GPIO103
*/
volatile XLLP_GPIO_T *pGPIORegs;
extern void usWait(unsigned usVal);
/*拉低CS,使得SPI有效*/
void enable_CS()
{
pGPIORegs->GPSR3 &= ~XLLP_BIT_4;
pGPIORegs->GPCR3 |= XLLP_BIT_4;
return;
}
/*拉高CS,使得SPI有效*/
void disable_CS()
{
pGPIORegs->GPSR3 |= XLLP_BIT_4;
return;
}
void clk_HIGH()
{
pGPIORegs->GPSR3 |= XLLP_BIT_5;
return;
}
void clk_LOW()
{
pGPIORegs->GPSR3 &= ~XLLP_BIT_5;
pGPIORegs->GPCR3 |= XLLP_BIT_5;
return;
}
void sdi_HIGH()
{
pGPIORegs->GPSR3 |= XLLP_BIT_6;
return;
}
void sdi_LOW()
{
pGPIORegs->GPSR3 &= ~XLLP_BIT_6;
pGPIORegs->GPCR3 |= XLLP_BIT_6;
return;
}
void spi_WRITE(int mode, unsigned short data)
{
unsigned long tmp;
int i;
if (mode) //addr
tmp = (0x74)<<16 | data;
else //instruction
tmp = (0x76)<<16 | data;
enable_CS();
usWait(10);
//write
for(i = 0 ; i < 24; i++)
{
usWait(10);
clk_LOW();
usWait(20);
if(tmp&0x800000)
sdi_HIGH();
else
sdi_LOW();
usWait(10);
tmp <<=1;
clk_HIGH();
}
disable_CS();
}
void ltv_LCD_reset()
{
/*set reset pin low width >= 3 us*/
pGPIORegs->GPSR3 &= ~XLLP_BIT_7;
pGPIORegs->GPCR3 |= XLLP_BIT_7;
usWait(10);
pGPIORegs->GPSR3 |= XLLP_BIT_7;
}
void ltv_GPIO_init()
{
/* set gpio output level */
// spi cs pin: 100 high
pGPIORegs->GPSR3 |= XLLP_BIT_4;
// spi clk pin: 101 low
pGPIORegs->GPSR3 &= ~XLLP_BIT_5;
pGPIORegs->GPCR3 |= XLLP_BIT_5;
// spi data pin: 102 low
pGPIORegs->GPSR3 &= ~XLLP_BIT_6;
pGPIORegs->GPCR3 |= XLLP_BIT_6;
// lcd reset pin: 103 high
pGPIORegs->GPSR3 |= XLLP_BIT_7;
/* set gpio direction: output*/
pGPIORegs->GPDR3 |= XLLP_BIT_4 | XLLP_BIT_5 | XLLP_BIT_6 | XLLP_BIT_7;
}
void ltv_LCD_init( volatile XLLP_GPIO_T *p_GPIORegs)
{
pGPIORegs = p_GPIORegs;
ltv_GPIO_init();
usWait(5000);
ltv_LCD_reset();
spi_WRITE(1,0x09);
spi_WRITE(0,0x0000);
usWait(10000);
spi_WRITE(1,0x09);
spi_WRITE(0,0x4000);
spi_WRITE(1,0x0a);
spi_WRITE(0,0x2000);
usWait(10);
spi_WRITE(1,0x09);
spi_WRITE(0,0x4055);
usWait(50000);
//something setting
/*set interface mode syn mode:0x409d, de mode:0x609d*/
spi_WRITE(1,0x01);
spi_WRITE(0,0x409d);
/*set data format RGB*/
spi_WRITE(1,0x02);
spi_WRITE(0,0x0204);
spi_WRITE(1,0x03);
spi_WRITE(0,0x100);
spi_WRITE(1,0x04);
spi_WRITE(0,0x3000);
spi_WRITE(1,0x05);
spi_WRITE(0,0x4003);
spi_WRITE(1,0x06);
spi_WRITE(0,0x0022);
spi_WRITE(1,0x07);
spi_WRITE(0,0x0021);
spi_WRITE(1,0x08);
spi_WRITE(0,0x0c00);
spi_WRITE(1,0x10);
spi_WRITE(0,0x0103);
spi_WRITE(1,0x11);
spi_WRITE(0,0x0301);
spi_WRITE(1,0x12);
spi_WRITE(0,0x1f0f);
spi_WRITE(1,0x13);
spi_WRITE(0,0x1f0f);
spi_WRITE(1,0x14);
spi_WRITE(0,0x0707);
spi_WRITE(1,0x15);
spi_WRITE(0,0x0307);
spi_WRITE(1,0x16);
spi_WRITE(0,0x0707);
spi_WRITE(1,0x17);
spi_WRITE(0,0x0000);
spi_WRITE(1,0x18);
spi_WRITE(0,0x0004);
spi_WRITE(1,0x19);
spi_WRITE(0,0x0000);
usWait(12000);
spi_WRITE(1,0x09);
spi_WRITE(0,0x4a55);
spi_WRITE(1,0x05);
spi_WRITE(0,0x5003);
usWait(100);
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -