本帖最后由 assange 于 2014-8-29 13:09 编辑
小弟新手上路,对单片机有些了解,出于好奇最近收购一块2.8寸TFT彩屏,内部含有ILI9325,XPT2046,现在我真是捉急了,没有驱动历程,想到论坛上大神较多,特来请教 ,还望多多指点,谢谢啦。初步决定由K60来做mcu,希望有经验的人士给我点资料,谢谢~
程序写完啦,但是 DeviceCode读的数据一直是6783,还请大神们指点 谢谢
int main(void)
{
DelayInit();
LCD_Init();
while(1)
{
}
}
uint16_t DeviceCode;
//PTB0~8 DB0~8 **** PTA8~15 DB8~15
void DataToIO(uint16_t val)
{
uint16_t dat=0;
dat = GPIO_ReadPort(HW_GPIOB); // DBL 读取端口的32位数据
dat = (dat&0xFF00) | (val&0xFF);
GPIO_WritePort(HW_GPIOB, dat);
dat = GPIO_ReadPort(HW_GPIOA); // DBH
dat = (dat&0xFF00) | ((val>>8)&0xFF);
GPIO_WritePort(HW_GPIOA, dat);
}
#define LCD_WR_DATA(data)\
{ \
LCD_RS_SET;\
LCD_CS_CLR;\
DataToIO(data);\
LCD_WR_CLR;\
LCD_WR_SET;\
LCD_CS_SET;\
}
void LCD_WR_REG(uint16_t data) // 些命令
{
LCD_RS_CLR;//写地址
LCD_CS_CLR;
DataToIO(data);
LCD_WR_CLR;
LCD_WR_SET;
LCD_CS_SET;
}
//写某些寄存期地址
void LCD_WriteReg(uint8_t LCD_Reg, uint16_t LCD_RegValue)
{
LCD_WR_REG(LCD_Reg);
LCD_WR_DATA(LCD_RegValue);
}
//都寄存器
uint16_t LCD_ReadReg(uint8_t LCD_Reg)
{
uint16_t t,i,datH,datL;
LCD_WR_REG(LCD_Reg);
{
GPIO_QuickInit(HW_GPIOB,i,kGPIO_Mode_IPU);
GPIO_WriteBit(HW_GPIOB,i,1);
}
for(i=8;i<16;i++)
{
GPIO_QuickInit(HW_GPIOA,i,kGPIO_Mode_IPU);
GPIO_WriteBit(HW_GPIOA,i,1);
}
LCD_RS_SET;
LCD_CS_CLR;
LCD_RD_CLR;
DelayUs(5);
LCD_RD_SET;
datH = PTA->PDIR; /**< Port Data Input Register, offset: 0x10 */
datL = PTB->PDIR; /**< Port Data Input Register, offset: 0x10 */
LCD_CS_SET;
for(i=0;i<7;i++)
{
GPIO_QuickInit(HW_GPIOB,i,kGPIO_Mode_OPP);
GPIO_WriteBit(HW_GPIOB,i,1);
}
for(i=8;i<16;i++)
{
GPIO_QuickInit(HW_GPIOA,i,kGPIO_Mode_OPP);
GPIO_WriteBit(HW_GPIOA,i,1);
}
t = ((datH<<8)&0xFF00) | (datL&0x00FF);
return t;
}
void LCD_Init(void)
{
uint8_t i;
for(i=5;i<10;i++)
{
GPIO_QuickInit(HW_GPIOD,i,kGPIO_Mode_OPP);
}
LCD_CS_SET;
LCD_RD_SET;
LCD_WR_SET;
DelayMs(50); // delay 50 ms
LCD_WriteReg(0x0000,0x0001);
DelayMs(50); // delay 50 ms
LCD_RD_SET;
LCD_WR_SET;
DeviceCode = LCD_ReadReg(0x0000);
}
|