本帖最后由 鲨鱼 于 2016-11-24 12:40 编辑
[img]file:///C:Program FilesTencentQQEIMUsers2851013008ImageGroupVYLS8J3O(QNZ6KS{SD1[IAE.jpg[/img][img=0,1]file:///C:Program FilesTencentQQEIMUsers2851013008ImageGroupVYLS8J3O(QNZ6KS{SD1[IAE.jpg[/img][img=0,1]file:///C:Program FilesTencentQQEIMUsers2851013008ImageGroupVYLS8J3O(QNZ6KS{SD1[IAE.jpg[/img]
我的屏幕是 480*320的 驱动IC是9481 我现在用战舰的TFTLCD显示程序进行修改,但是现在我屏幕调整为横屏,用fill的填充程序 方向也是已经横屏了,但是横向宽度就是还是320,不知道为什么,哪里设置有问题吗?帮忙下谢谢
竖屏就是正常的
/*************************************************************/
//开始写GRAM
void LCD_WriteRAM_Prepare(void)
{
LCD->LCD_REG=lcddev.wramcmd;
}
//设置LCD显示方向
//dir:0,竖屏;1,横屏
void LCD_Display_Dir(u8 dir)
{
if(dir==0) //竖屏
{
lcddev.wramcmd=0x2C;
lcddev.dir=0; //竖屏
lcddev.width=320;
lcddev.height=480;
lcddev.setxcmd=0x2A;
lcddev.setycmd=0x2B;
LCD_WriteReg(0x36,0x0A);
}
else //横屏
{
lcddev.wramcmd=0x2C;
lcddev.dir=1;//横屏
lcddev.width=480;
lcddev.height=320;
lcddev.setxcmd=0x2A;
lcddev.setycmd=0x2B;
LCD_WriteReg(0x36,0x28);
}
}
//清屏函数
//color:要清屏的填充 {MOD}
void LCD_Clear(u16 color)
{
u32 index=0;
u32 totalpoint=lcddev.width;
totalpoint*=lcddev.height; //得到总点数
LCD_SetCursor(0x00,0x0000); //设置光标位置
LCD_WriteRAM_Prepare(); //开始写入GRAM
for(index=0;index<totalpoint;index++)
{
LCD->LCD_RAM=color;
}
}
//在指定区域内填充单个颜 {MOD}
//(sx,sy),(ex,ey):填充矩形对角坐标,区域大小为
ex-sx+1)*(ey-sy+1)
//color:要填充的颜 {MOD}
void LCD_Fill(u16 sx,u16 sy,u16 ex,u16 ey,u16 color)
{
u16 i,j;
u16 xlen=0;
xlen=ex-sx+1;
for(i=sy;i<=ey;i++)
{
LCD_SetCursor(sx,i); //设置光标位置
LCD_WriteRAM_Prepare(); //开始写入GRAM
for(j=0;j<xlen;j++)LCD_WR_DATA(color); //设置光标位置
}
}
//设置光标位置
//Xpos:横坐标
//Ypos:纵坐标
void LCD_SetCursor(u16 Xpos, u16 Ypos)
{
LCD_WR_REG(lcddev.setxcmd);
LCD_WR_DATA(Xpos>>8);
LCD_WR_DATA(0x00FF&Xpos);
LCD_WR_REG(lcddev.setycmd);
LCD_WR_DATA(Ypos>>8);
LCD_WR_DATA(0x00FF&Ypos);
}
void LCD_Init(void)
{
u16 DeviceCode=0;
GPIO_InitTypeDef GPIO_InitStructure;
FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
FSMC_NORSRAMTimingInitTypeDef readWriteTiming;
FSMC_NORSRAMTimingInitTypeDef writeTiming;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC,ENABLE); //使能FSMC时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOE|RCC_APB2Periph_GPIOG|RCC_APB2Periph_AFIO,ENABLE);//使能PORTB,D,E,G以及AFIO复用功能时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; //PB0 推挽输出 背光
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//PORTD复用推挽输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_14|GPIO_Pin_15; // //PORTD复用推挽输出
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
//PORTE复用推挽输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15; // //PORTD复用推挽输出
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOE, &GPIO_InitStructure);
// //PORTG12复用推挽输出 A0
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_12; // //PORTD复用推挽输出
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOG, &GPIO_InitStructure);
readWriteTiming.FSMC_AddressSetupTime = 0x01; //地址建立时间(ADDSET)为2个HCLK 1/36M=27ns
readWriteTiming.FSMC_AddressHoldTime = 0x00; //地址保持时间(ADDHLD)模式A未用到
readWriteTiming.FSMC_DataSetupTime = 0x0f; // 数据保存时间为16个HCLK,因为液晶驱动IC的读数据的时候,速度不能太快,尤其对1289这个IC。
readWriteTiming.FSMC_BusTurnAroundDuration = 0x00;
readWriteTiming.FSMC_CLKDivision = 0x00;
readWriteTiming.FSMC_DataLatency = 0x00;
readWriteTiming.FSMC_AccessMode = FSMC_AccessMode_A; //模式A
writeTiming.FSMC_AddressSetupTime = 0x00; //地址建立时间(ADDSET)为1个HCLK
writeTiming.FSMC_AddressHoldTime = 0x00; //地址保持时间(A
writeTiming.FSMC_DataSetupTime = 0x03; ////数据保存时间为4个HCLK
writeTiming.FSMC_BusTurnAroundDuration = 0x00;
writeTiming.FSMC_CLKDivision = 0x00;
writeTiming.FSMC_DataLatency = 0x00;
writeTiming.FSMC_AccessMode = FSMC_AccessMode_A; //模式A
FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM4;// 这里我们使用NE4 ,也就对应BTCR[6],[7]。
FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; // 不复用数据地址
FSMC_NORSRAMInitStructure.FSMC_MemoryType =FSMC_MemoryType_SRAM;// FSMC_MemoryType_SRAM; //SRAM
FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;//存储器数据宽度为16bit
FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode =FSMC_BurstAccessMode_Disable;// FSMC_BurstAccessMode_Disable;
FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait=FSMC_AsynchronousWait_Disable;
FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; // 存储器写使能
FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Enable; // 读写使用不同的时序
FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &readWriteTiming; //读写时序
FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &writeTiming; //写时序
FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); //初始化FSMC配置
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM4, ENABLE); // 使能BANK1
delay_ms(50); // delay 50 ms
//************* Start Initial Sequence **********//
LCD_WR_REG(0x11);
delay_ms(20);
LCD_WR_REG(0x13);
LCD_WR_REG(0xD0);
LCD_WR_DATA(0x07);
LCD_WR_DATA(0x40);
LCD_WR_DATA(0x1c);
LCD_WR_REG(0xD1);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x18);//07
LCD_WR_DATA(0x1d);
LCD_WR_REG(0xD2);
LCD_WR_DATA(0x01);
LCD_WR_DATA(0x11);
LCD_WR_REG(0xC0);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x3B);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x02);
LCD_WR_DATA(0x11);
LCD_WR_REG(0xC1);
LCD_WR_DATA(0x10);
LCD_WR_DATA(0x0B);
LCD_WR_DATA(0x88);
LCD_WR_REG(0xC5);
LCD_WR_DATA(0x01);
LCD_WR_REG(0xC8);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x30);
LCD_WR_DATA(0x36);
LCD_WR_DATA(0x45);
LCD_WR_DATA(0x04);
LCD_WR_DATA(0x16);
LCD_WR_DATA(0x37);
LCD_WR_DATA(0x75);
LCD_WR_DATA(0x77);
LCD_WR_DATA(0x54);
LCD_WR_DATA(0x0f);
LCD_WR_DATA(0x00);
LCD_WR_REG(0xE4);
LCD_WR_DATA(0xA0);
LCD_WR_REG(0xF0);
LCD_WR_DATA(0x01);
LCD_WR_REG(0xF3);
LCD_WR_DATA(0x40);
LCD_WR_DATA(0x0a);
LCD_WR_REG(0xF7);
LCD_WR_DATA(0x80);
LCD_WR_REG(0x36);
LCD_WR_DATA(0x0A);
LCD_WR_REG(0x3A);
LCD_WR_DATA(0x55);
LCD_WR_REG(0x2A);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x01);
LCD_WR_DATA(0x3F);
LCD_WR_REG(0x2B);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x01);
LCD_WR_DATA(0xdf);
delay_ms(120);
LCD_WR_REG(0x29);
LCD_WR_REG(0x002c);
LCD_Display_Dir(1); //默认为竖屏
LCD_LED=1; //点亮背光
LCD_Clear(RED);
}
int main(void)
{
u8 x=0;
u8 lcd_id[12]; //存放LCD ID字符串
delay_init(); //延时函数初始化
NVIC_Configuration(); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
uart_init(9600); //串口初始化为9600
LED_Init(); //LED端口初始化
LCD_Init();
LCD_Fill(0,0,470,20,BLUE);
while(1)
{
x++;
if(x==6)x=0;
LED0=!LED0;
delay_ms(1000);
}
}
一周热门 更多>