高级会员
- 积分
- 546
- 金钱
- 546
- 注册时间
- 2019-11-1
- 在线时间
- 85 小时
|
1金钱
本帖最后由 longwu4886 于 2023-2-8 16:41 编辑
void LcdInit(void)
{
RCC->AHBENR|=1<<8; //使能FSMC时钟
RCC->APB2ENR|=1<<3; //使能PORTB时钟
RCC->APB2ENR|=1<<5; //使能PORTD时钟
RCC->APB2ENR|=1<<6; //使能PORTE时钟
RCC->APB2ENR|=1<<8; //使能PORTG时钟
GPIOB->CRL&=0XFFFFFFF0; //PB0 推挽输出 背光
GPIOB->CRL|=0X00000003;
//PORTD复用推挽输出
GPIOD->CRH&=0X00FFF000;
GPIOD->CRH|=0XBB000BBB;
GPIOD->CRL&=0XFF00FF00;
GPIOD->CRL|=0X00BB00BB;
//PORTE复用推挽输出
GPIOE->CRH&=0X00000000;
GPIOE->CRH|=0XBBBBBBBB;
GPIOE->CRL&=0X0FFFFFFF;
GPIOE->CRL|=0XB0000000;
//PORTG12复用推挽输出
GPIOG->CRH&=0XFFF0FFFF;
GPIOG->CRH|=0X000B0000;
GPIOG->CRL&=0XFFFFFFF0;//PG0->RS
GPIOG->CRL|=0X0000000B;
//寄存器清零
//bank1有NE1~4,每一个有一个BCR+TCR,所以总共八个寄存器。
//这里我们使用NE4 ,也就对应BTCR[6],[7]。
FSMC_Bank1->BTCR[6]=0X00000000;
FSMC_Bank1->BTCR[7]=0X00000000;
FSMC_Bank1E->BWTR[6]=0X00000000;
//操作BCR寄存器 使用异步模式
FSMC_Bank1->BTCR[6]|=1<<12; //存储器写使能
FSMC_Bank1->BTCR[6]|=1<<14; //读写使用不同的时序
FSMC_Bank1->BTCR[6]|=1<<4; //存储器数据宽度为16bit
//操作BTR寄存器
//读时序控制寄存器
FSMC_Bank1->BTCR[7]|=0<<28; //模式A
FSMC_Bank1->BTCR[7]|=1<<0; //地址建立时间(ADDSET)为2个HCLK 1/36M=27ns(实际>200ns)
//因为液晶驱动IC的读数据的时候,速度不能太快,尤其对1289这个IC。
FSMC_Bank1->BTCR[7]|=0XF<<8; //数据保存时间为16个HCLK
//写时序控制寄存器
FSMC_Bank1E->BWTR[6]|=0<<28; //模式A
FSMC_Bank1E->BWTR[6]|=0<<0; //地址建立时间(ADDSET)为1个HCLK
//4个HCLK(HCLK=72M)因为液晶驱动IC的写信号脉宽,最少也得50ns。72M/4=24M=55ns
FSMC_Bank1E->BWTR[6]|=3<<8; //数据保存时间为4个HCLK
//使能BANK1,区域4
FSMC_Bank1->BTCR[6]|=1<<0; //使能BANK1,区域4
DelayMs(50); // delay 50 ms
lcddev.id=LcdReadReg(0x0000); //读ID(9320/9325/9328/4531/4535等IC)
LcdWriteReg(0XD4);
lcddev.id=LcdReadData();//dummy read
lcddev.id=LcdReadData();//读回0X01
lcddev.id=LcdReadData();//读回0X53
lcddev.id<<=8;
lcddev.id|=LcdReadData(); //这里读回0X10
//printf(" LCD ID:%x\r\n",lcddev.id); //打印LCD ID
//if(lcddev.id==0x5310)
LcdWriteReg(0xED);
LcdWriteData(0x01);
LcdWriteData(0xFE);
LcdWriteReg(0xEE);
LcdWriteData(0xDE);
LcdWriteData(0x21);
LcdWriteReg(0xF1);
LcdWriteData(0x01);
LcdWriteReg(0xDF);
LcdWriteData(0x10);
//VCOMvoltage//
LcdWriteReg(0xC4);
LcdWriteData(0x8F); //5f
LcdWriteReg(0xC6);
LcdWriteData(0x00);
LcdWriteData(0xE2);
LcdWriteData(0xE2);
LcdWriteData(0xE2);
LcdWriteReg(0xBF);
LcdWriteData(0xAA);
LcdWriteReg(0xB0);
LcdWriteData(0x0D);
LcdWriteData(0x00);
LcdWriteData(0x0D);
LcdWriteData(0x00);
LcdWriteData(0x11);
LcdWriteData(0x00);
LcdWriteData(0x19);
LcdWriteData(0x00);
LcdWriteData(0x21);
LcdWriteData(0x00);
LcdWriteData(0x2D);
LcdWriteData(0x00);
LcdWriteData(0x3D);
LcdWriteData(0x00);
LcdWriteData(0x5D);
LcdWriteData(0x00);
LcdWriteData(0x5D);
LcdWriteData(0x00);
LcdWriteReg(0xB1);
LcdWriteData(0x80);
LcdWriteData(0x00);
LcdWriteData(0x8B);
LcdWriteData(0x00);
LcdWriteData(0x96);
LcdWriteData(0x00);
LcdWriteReg(0xB2);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x02);
LcdWriteData(0x00);
LcdWriteData(0x03);
LcdWriteData(0x00);
LcdWriteReg(0xB3);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteReg(0xB4);
LcdWriteData(0x8B);
LcdWriteData(0x00);
LcdWriteData(0x96);
LcdWriteData(0x00);
LcdWriteData(0xA1);
LcdWriteData(0x00);
LcdWriteReg(0xB5);
LcdWriteData(0x02);
LcdWriteData(0x00);
LcdWriteData(0x03);
LcdWriteData(0x00);
LcdWriteData(0x04);
LcdWriteData(0x00);
LcdWriteReg(0xB6);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteReg(0xB7);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x3F);
LcdWriteData(0x00);
LcdWriteData(0x5E);
LcdWriteData(0x00);
LcdWriteData(0x64);
LcdWriteData(0x00);
LcdWriteData(0x8C);
LcdWriteData(0x00);
LcdWriteData(0xAC);
LcdWriteData(0x00);
LcdWriteData(0xDC);
LcdWriteData(0x00);
LcdWriteData(0x70);
LcdWriteData(0x00);
LcdWriteData(0x90);
LcdWriteData(0x00);
LcdWriteData(0xEB);
LcdWriteData(0x00);
LcdWriteData(0xDC);
LcdWriteData(0x00);
LcdWriteReg(0xB8);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteReg(0xBA);
LcdWriteData(0x24);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteReg(0xC1);
LcdWriteData(0x20);
LcdWriteData(0x00);
LcdWriteData(0x54);
LcdWriteData(0x00);
LcdWriteData(0xFF);
LcdWriteData(0x00);
LcdWriteReg(0xC2);
LcdWriteData(0x0A);
LcdWriteData(0x00);
LcdWriteData(0x04);
LcdWriteData(0x00);
LcdWriteReg(0xC3);
LcdWriteData(0x3C);
LcdWriteData(0x00);
LcdWriteData(0x3A);
LcdWriteData(0x00);
LcdWriteData(0x39);
LcdWriteData(0x00);
LcdWriteData(0x37);
LcdWriteData(0x00);
LcdWriteData(0x3C);
LcdWriteData(0x00);
LcdWriteData(0x36);
LcdWriteData(0x00);
LcdWriteData(0x32);
LcdWriteData(0x00);
LcdWriteData(0x2F);
LcdWriteData(0x00);
LcdWriteData(0x2C);
LcdWriteData(0x00);
LcdWriteData(0x29);
LcdWriteData(0x00);
LcdWriteData(0x26);
LcdWriteData(0x00);
LcdWriteData(0x24);
LcdWriteData(0x00);
LcdWriteData(0x24);
LcdWriteData(0x00);
LcdWriteData(0x23);
LcdWriteData(0x00);
LcdWriteData(0x3C);
LcdWriteData(0x00);
LcdWriteData(0x36);
LcdWriteData(0x00);
LcdWriteData(0x32);
LcdWriteData(0x00);
LcdWriteData(0x2F);
LcdWriteData(0x00);
LcdWriteData(0x2C);
LcdWriteData(0x00);
LcdWriteData(0x29);
LcdWriteData(0x00);
LcdWriteData(0x26);
LcdWriteData(0x00);
LcdWriteData(0x24);
LcdWriteData(0x00);
LcdWriteData(0x24);
LcdWriteData(0x00);
LcdWriteData(0x23);
LcdWriteData(0x00);
LcdWriteReg(0xC4);
LcdWriteData(0x62);
LcdWriteData(0x00);
LcdWriteData(0x05);
LcdWriteData(0x00);
LcdWriteData(0x84);
LcdWriteData(0x00);
LcdWriteData(0xF0);
LcdWriteData(0x00);
LcdWriteData(0x18);
LcdWriteData(0x00);
LcdWriteData(0xA4);
LcdWriteData(0x00);
LcdWriteData(0x18);
LcdWriteData(0x00);
LcdWriteData(0x50);
LcdWriteData(0x00);
LcdWriteData(0x0C);
LcdWriteData(0x00);
LcdWriteData(0x17);
LcdWriteData(0x00);
LcdWriteData(0x95);
LcdWriteData(0x00);
LcdWriteData(0xF3);
LcdWriteData(0x00);
LcdWriteData(0xE6);
LcdWriteData(0x00);
LcdWriteReg(0xC5);
LcdWriteData(0x32);
LcdWriteData(0x00);
LcdWriteData(0x44);
LcdWriteData(0x00);
LcdWriteData(0x65);
LcdWriteData(0x00);
LcdWriteData(0x76);
LcdWriteData(0x00);
LcdWriteData(0x88);
LcdWriteData(0x00);
LcdWriteReg(0xC6);
LcdWriteData(0x20);
LcdWriteData(0x00);
LcdWriteData(0x17);
LcdWriteData(0x00);
LcdWriteData(0x01);
LcdWriteData(0x00);
LcdWriteReg(0xC7);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteReg(0xC8);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteReg(0xC9);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteReg(0xE0);
LcdWriteData(0x16);
LcdWriteData(0x00);
LcdWriteData(0x1C);
LcdWriteData(0x00);
LcdWriteData(0x21);
LcdWriteData(0x00);
LcdWriteData(0x36);
LcdWriteData(0x00);
LcdWriteData(0x46);
LcdWriteData(0x00);
LcdWriteData(0x52);
LcdWriteData(0x00);
LcdWriteData(0x64);
LcdWriteData(0x00);
LcdWriteData(0x7A);
LcdWriteData(0x00);
LcdWriteData(0x8B);
LcdWriteData(0x00);
LcdWriteData(0x99);
LcdWriteData(0x00);
LcdWriteData(0xA8);
LcdWriteData(0x00);
LcdWriteData(0xB9);
LcdWriteData(0x00);
LcdWriteData(0xC4);
LcdWriteData(0x00);
LcdWriteData(0xCA);
LcdWriteData(0x00);
LcdWriteData(0xD2);
LcdWriteData(0x00);
LcdWriteData(0xD9);
LcdWriteData(0x00);
LcdWriteData(0xE0);
LcdWriteData(0x00);
LcdWriteData(0xF3);
LcdWriteData(0x00);
LcdWriteReg(0xE1);
LcdWriteData(0x16);
LcdWriteData(0x00);
LcdWriteData(0x1C);
LcdWriteData(0x00);
LcdWriteData(0x22);
LcdWriteData(0x00);
LcdWriteData(0x36);
LcdWriteData(0x00);
LcdWriteData(0x45);
LcdWriteData(0x00);
LcdWriteData(0x52);
LcdWriteData(0x00);
LcdWriteData(0x64);
LcdWriteData(0x00);
LcdWriteData(0x7A);
LcdWriteData(0x00);
LcdWriteData(0x8B);
LcdWriteData(0x00);
LcdWriteData(0x99);
LcdWriteData(0x00);
LcdWriteData(0xA8);
LcdWriteData(0x00);
LcdWriteData(0xB9);
LcdWriteData(0x00);
LcdWriteData(0xC4);
LcdWriteData(0x00);
LcdWriteData(0xCA);
LcdWriteData(0x00);
LcdWriteData(0xD2);
LcdWriteData(0x00);
LcdWriteData(0xD8);
LcdWriteData(0x00);
LcdWriteData(0xE0);
LcdWriteData(0x00);
LcdWriteData(0xF3);
LcdWriteData(0x00);
LcdWriteReg(0xE2);
LcdWriteData(0x05);
LcdWriteData(0x00);
LcdWriteData(0x0B);
LcdWriteData(0x00);
LcdWriteData(0x1B);
LcdWriteData(0x00);
LcdWriteData(0x34);
LcdWriteData(0x00);
LcdWriteData(0x44);
LcdWriteData(0x00);
LcdWriteData(0x4F);
LcdWriteData(0x00);
LcdWriteData(0x61);
LcdWriteData(0x00);
LcdWriteData(0x79);
LcdWriteData(0x00);
LcdWriteData(0x88);
LcdWriteData(0x00);
LcdWriteData(0x97);
LcdWriteData(0x00);
LcdWriteData(0xA6);
LcdWriteData(0x00);
LcdWriteData(0xB7);
LcdWriteData(0x00);
LcdWriteData(0xC2);
LcdWriteData(0x00);
LcdWriteData(0xC7);
LcdWriteData(0x00);
LcdWriteData(0xD1);
LcdWriteData(0x00);
LcdWriteData(0xD6);
LcdWriteData(0x00);
LcdWriteData(0xDD);
LcdWriteData(0x00);
LcdWriteData(0xF3);
LcdWriteData(0x00);
LcdWriteReg(0xE3);
LcdWriteData(0x05);
LcdWriteData(0x00);
LcdWriteData(0xA);
LcdWriteData(0x00);
LcdWriteData(0x1C);
LcdWriteData(0x00);
LcdWriteData(0x33);
LcdWriteData(0x00);
LcdWriteData(0x44);
LcdWriteData(0x00);
LcdWriteData(0x50);
LcdWriteData(0x00);
LcdWriteData(0x62);
LcdWriteData(0x00);
LcdWriteData(0x78);
LcdWriteData(0x00);
LcdWriteData(0x88);
LcdWriteData(0x00);
LcdWriteData(0x97);
LcdWriteData(0x00);
LcdWriteData(0xA6);
LcdWriteData(0x00);
LcdWriteData(0xB7);
LcdWriteData(0x00);
LcdWriteData(0xC2);
LcdWriteData(0x00);
LcdWriteData(0xC7);
LcdWriteData(0x00);
LcdWriteData(0xD1);
LcdWriteData(0x00);
LcdWriteData(0xD5);
LcdWriteData(0x00);
LcdWriteData(0xDD);
LcdWriteData(0x00);
LcdWriteData(0xF3);
LcdWriteData(0x00);
LcdWriteReg(0xE4);
LcdWriteData(0x01);
LcdWriteData(0x00);
LcdWriteData(0x01);
LcdWriteData(0x00);
LcdWriteData(0x02);
LcdWriteData(0x00);
LcdWriteData(0x2A);
LcdWriteData(0x00);
LcdWriteData(0x3C);
LcdWriteData(0x00);
LcdWriteData(0x4B);
LcdWriteData(0x00);
LcdWriteData(0x5D);
LcdWriteData(0x00);
LcdWriteData(0x74);
LcdWriteData(0x00);
LcdWriteData(0x84);
LcdWriteData(0x00);
LcdWriteData(0x93);
LcdWriteData(0x00);
LcdWriteData(0xA2);
LcdWriteData(0x00);
LcdWriteData(0xB3);
LcdWriteData(0x00);
LcdWriteData(0xBE);
LcdWriteData(0x00);
LcdWriteData(0xC4);
LcdWriteData(0x00);
LcdWriteData(0xCD);
LcdWriteData(0x00);
LcdWriteData(0xD3);
LcdWriteData(0x00);
LcdWriteData(0xDD);
LcdWriteData(0x00);
LcdWriteData(0xF3);
LcdWriteData(0x00);
LcdWriteReg(0xE5);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x02);
LcdWriteData(0x00);
LcdWriteData(0x29);
LcdWriteData(0x00);
LcdWriteData(0x3C);
LcdWriteData(0x00);
LcdWriteData(0x4B);
LcdWriteData(0x00);
LcdWriteData(0x5D);
LcdWriteData(0x00);
LcdWriteData(0x74);
LcdWriteData(0x00);
LcdWriteData(0x84);
LcdWriteData(0x00);
LcdWriteData(0x93);
LcdWriteData(0x00);
LcdWriteData(0xA2);
LcdWriteData(0x00);
LcdWriteData(0xB3);
LcdWriteData(0x00);
LcdWriteData(0xBE);
LcdWriteData(0x00);
LcdWriteData(0xC4);
LcdWriteData(0x00);
LcdWriteData(0xCD);
LcdWriteData(0x00);
LcdWriteData(0xD3);
LcdWriteData(0x00);
LcdWriteData(0xDC);
LcdWriteData(0x00);
LcdWriteData(0xF3);
LcdWriteData(0x00);
LcdWriteReg(0xE6);
LcdWriteData(0x11);
LcdWriteData(0x00);
LcdWriteData(0x34);
LcdWriteData(0x00);
LcdWriteData(0x56);
LcdWriteData(0x00);
LcdWriteData(0x76);
LcdWriteData(0x00);
LcdWriteData(0x77);
LcdWriteData(0x00);
LcdWriteData(0x66);
LcdWriteData(0x00);
LcdWriteData(0x88);
LcdWriteData(0x00);
LcdWriteData(0x99);
LcdWriteData(0x00);
LcdWriteData(0xBB);
LcdWriteData(0x00);
LcdWriteData(0x99);
LcdWriteData(0x00);
LcdWriteData(0x66);
LcdWriteData(0x00);
LcdWriteData(0x55);
LcdWriteData(0x00);
LcdWriteData(0x55);
LcdWriteData(0x00);
LcdWriteData(0x45);
LcdWriteData(0x00);
LcdWriteData(0x43);
LcdWriteData(0x00);
LcdWriteData(0x44);
LcdWriteData(0x00);
LcdWriteReg(0xE7);
LcdWriteData(0x32);
LcdWriteData(0x00);
LcdWriteData(0x55);
LcdWriteData(0x00);
LcdWriteData(0x76);
LcdWriteData(0x00);
LcdWriteData(0x66);
LcdWriteData(0x00);
LcdWriteData(0x67);
LcdWriteData(0x00);
LcdWriteData(0x67);
LcdWriteData(0x00);
LcdWriteData(0x87);
LcdWriteData(0x00);
LcdWriteData(0x99);
LcdWriteData(0x00);
LcdWriteData(0xBB);
LcdWriteData(0x00);
LcdWriteData(0x99);
LcdWriteData(0x00);
LcdWriteData(0x77);
LcdWriteData(0x00);
LcdWriteData(0x44);
LcdWriteData(0x00);
LcdWriteData(0x56);
LcdWriteData(0x00);
LcdWriteData(0x23);
LcdWriteData(0x00);
LcdWriteData(0x33);
LcdWriteData(0x00);
LcdWriteData(0x45);
LcdWriteData(0x00);
LcdWriteReg(0xE8);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x99);
LcdWriteData(0x00);
LcdWriteData(0x87);
LcdWriteData(0x00);
LcdWriteData(0x88);
LcdWriteData(0x00);
LcdWriteData(0x77);
LcdWriteData(0x00);
LcdWriteData(0x66);
LcdWriteData(0x00);
LcdWriteData(0x88);
LcdWriteData(0x00);
LcdWriteData(0xAA);
LcdWriteData(0x00);
LcdWriteData(0xBB);
LcdWriteData(0x00);
LcdWriteData(0x99);
LcdWriteData(0x00);
LcdWriteData(0x66);
LcdWriteData(0x00);
LcdWriteData(0x55);
LcdWriteData(0x00);
LcdWriteData(0x55);
LcdWriteData(0x00);
LcdWriteData(0x44);
LcdWriteData(0x00);
LcdWriteData(0x44);
LcdWriteData(0x00);
LcdWriteData(0x55);
LcdWriteData(0x00);
LcdWriteReg(0xE9);
LcdWriteData(0xAA);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteReg(0x00);
LcdWriteData(0xAA);
LcdWriteReg(0xCF);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteReg(0xF0);
LcdWriteData(0x00);
LcdWriteData(0x50);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteData(0x00);
LcdWriteReg(0xF3);
LcdWriteData(0x00);
LcdWriteReg(0xF9);
LcdWriteData(0x06);
LcdWriteData(0x10);
LcdWriteData(0x29);
LcdWriteData(0x00);
LcdWriteReg(0x3A);
LcdWriteData(0x55); //66
LcdWriteReg(0x11);
DelayMs(100);
LcdWriteReg(0x29);
LcdWriteReg(0x35);
LcdWriteData(0x00);
LcdWriteReg(0x51);
LcdWriteData(0xFF);
LcdWriteReg(0x53);
LcdWriteData(0x2C);
LcdWriteReg(0x55);
LcdWriteData(0x82);
LcdWriteReg(0x2c);
lcddev.width=320;
lcddev.height=480;
LCD_LED=1; //点亮背光
}
|
|