#include "ili9325.h"
#include "systick.h"
/* lcd引脚初始化
数据线:
DB0--PD14 DB1--PD15 DB2--PD0 DB3--PD1
DB4--PE7 DB5--PE8 DB6--PE9 DB7--PE10
DB10--PE11 DB11--PE12 DB12--PE13 DB13--PE14
DB14--PE15 DB15--PD8 DB16--PD9 DB17--PD10
控制线:
RW--PD5
RD--PD4
CS--PD7
RS(D/C)--PD11
RES--PE1:
lcd_k--PB12*/
void LCD_Port_Init()
{
RCC->APB2ENR |= 1<<5; //使能GPIOD
RCC->APB2ENR |= 1<<6; //使能GPIOE
RCC->APB2ENR |= 1<<3; //使能GPIOB
// 数据线:配置成通用推挽输出,最大速度:50MHZ
GPIOD->CRL &= ~(0XFF);
GPIOD->CRL |= (0X33); //PD0,PD1
GPIOD->CRH &= (0XFFF);
GPIOD->CRH |= (0X333); //PD8/9/10
GPIOD->CRH &= ~(0XFFul<<24);
GPIOD->CRH |= (0X33ul<<24); //PD14/15
GPIOE->CRL &= ~(0XFul<<28);
GPIOE->CRL |= (0X3ul<<28); //PE7
GPIOE->CRH &= ~(0XFFFFFFFF);
GPIOE->CRH |= (0X33333333); PE8/9/10/11/12/13/14/15
// 控制线:配置成通用推挽输出,最大速度:50MHz
GPIOD->CRL &= ~(0XFF<<16);
GPIOD->CRL |= (0X33<<16); //PD4,PD5--RW/RD
GPIOD->ODR |= (1<<4);
GPIOD->ODR |= (1<<5);
GPIOD->CRL &= (0XFUL<<28);
GPIOD->CRL |= (0X3UL<<28); //PD7--CS
GPIOD->ODR |= 1<<7;
GPIOD->CRH &= ~(0XF<<12);
GPIOD->CRH |= (0X3<<12); //PD11--RS
GPIOD->ODR |= 1<<11;
GPIOE->CRL &= ~(0XF<<4);
GPIOE->CRL |= (0X3<<4); //PE1--RES
GPIOE->ODR |= (1<<1);
GPIOB->CRH &= ~(0XF<<16);
GPIOB->CRH |= (0X3<<16); //PB12 --LCD_K
GPIOB->ODR |= (1<<12); //关闭背光
}
//lcd写寄存器命令
void LCD_WR_CMD(uint16_t common)
{
GPIOD->ODR &= ~(1 << 7); //CS拉低
GPIOD->ODR &= ~(1 << 11); //(RS)D/C拉低
GPIOD->ODR |= 1 << 4; //RD拉高
GPIOD->ODR &= ~(1 << 5); //拉低 RW--PD5
if(common&0x01) GPIOD->BSRR |= (1<<14); else GPIOD->BRR |= (1<<14); //DB0
if(common&0x02) GPIOD->BSRR |= (1<<15); else GPIOD->BRR |= (1<<15);
if(common&0x04) GPIOD->BSRR |= (1<<0); else GPIOD->BRR |= (1<<0);
if(common&0x08) GPIOD->BSRR |= (1<<1); else GPIOD->BRR |= (1<<1);
if(common&0x10) GPIOE->BSRR |= (1<<7); else GPIOE->BRR |= (1<<7);
if(common&0x20) GPIOE->BSRR |= (1<<8); else GPIOE->BRR |= (1<<8);
if(common&0x40) GPIOE->BSRR |= (1<<9); else GPIOE->BRR |= (1<<9);
if(common&0x80) GPIOE->BSRR |= (1<<10); else GPIOE->BRR |= (1<<10);
if(common&0x0100) GPIOE->BSRR |= (1<<11); else GPIOE->BRR |= (1<<11);
if(common&0x0200) GPIOE->BSRR |= (1<<12); else GPIOE->BRR |= (1<<12);
if(common&0x0400) GPIOE->BSRR |= (1<<13); else GPIOE->BRR |= (1<<13);
if(common&0x0800) GPIOE->BSRR |= (1<<14); else GPIOE->BRR |= (1<<14);
if(common&0x1000) GPIOE->BSRR |= (1<<15); else GPIOE->BRR |= (1<<15);
if(common&0x2000) GPIOD->BSRR |= (1<<8); else GPIOD->BRR |= (1<<8);
if(common&0x4000) GPIOD->BSRR |= (1<<9); else GPIOD->BRR |= (1<<9);
if(common&0x8000) GPIOD->BSRR |= (1<<10); else GPIOD->BRR |= (1<<10); //DB15
GPIOD->ODR |= 1 << 5; //WR拉高
GPIOD->ODR |= 1 << 7; //拉高CS
}
//lcd写寄存器数据
void LCD_WR_Data(uint16_t data)
{
GPIOD->ODR &= ~(1 << 7); //CS拉低
GPIOD->ODR |= (1 << 11); //D/C拉高
GPIOD->ODR &= ~(1 << 5); //WR拉低
GPIOD->ODR |= 1 << 4; //RD拉高
if(data&0x01) GPIOD->BSRR |= (1<<14); else GPIOD->BRR |= (1<<14); //DB0
if(data&0x02) GPIOD->BSRR |= (1<<15); else GPIOD->BRR |= (1<<15);
if(data&0x04) GPIOD->BSRR |= (1<<0); else GPIOD->BRR |= (1<<0);
if(data&0x08) GPIOD->BSRR |= (1<<1); else GPIOD->BRR |= (1<<1);
if(data&0x10) GPIOE->BSRR |= (1<<7); else GPIOE->BRR |= (1<<7);
if(data&0x20) GPIOE->BSRR |= (1<<8); else GPIOE->BRR |= (1<<8);
if(data&0x40) GPIOE->BSRR |= (1<<9); else GPIOE->BRR |= (1<<9);
if(data&0x80) GPIOE->BSRR |= (1<<10); else GPIOE->BRR |= (1<<10);
if(data&0x0100) GPIOE->BSRR |= (1<<11); else GPIOE->BRR |= (1<<11);
if(data&0x0200) GPIOE->BSRR |= (1<<12); else GPIOE->BRR |= (1<<12);
if(data&0x0400) GPIOE->BSRR |= (1<<13); else GPIOE->BRR |= (1<<13);
if(data&0x0800) GPIOE->BSRR |= (1<<14); else GPIOE->BRR |= (1<<14);
if(data&0x1000) GPIOE->BSRR |= (1<<15); else GPIOE->BRR |= (1<<15);
if(data&0x2000) GPIOD->BSRR |= (1<<8); else GPIOD->BRR |= (1<<8);
if(data&0x4000) GPIOD->BSRR |= (1<<9); else GPIOD->BRR |= (1<<9);
if(data&0x8000) GPIOD->BSRR |= (1<<10); else GPIOD->BRR |= (1<<10);//DB15
GPIOD->ODR |= 1 << 5; //WR拉高
GPIOD->ODR |= 1 << 7; //拉高CS
}
//清屏
void LCD_Clear(uint16_t SX, uint16_t SY, uint16_t EX, uint16_t EY, uint16_t Color)
{
uint16_t i,j;
LCD_WR_CMD(0x0050);LCD_WR_Data(SX); //起始X坐标
LCD_WR_CMD(0x0051);LCD_WR_Data(EX); //终点x坐标
LCD_WR_CMD(0x0052);LCD_WR_Data(SY); //起始y坐标
LCD_WR_CMD(0x0053);LCD_WR_Data(EY); //终点y坐标
LCD_WR_CMD(0x0020);LCD_WR_Data(0X0000);
LCD_WR_CMD(0x0021);LCD_WR_Data(0X0000);
LCD_WR_CMD(0x0022);
for(i=0; i<320; i++)
{
for(j=0; j<240; j++)
{
//LCD_WR_CMD(0x0022);
LCD_WR_Data(Color);
}
}
}
//lcd初始化
void LCD_Init()
{
LCD_Port_Init();
Delay_ms(200);
GPIOE->ODR &= ~(1<<1); //RES拉低
Delay_ms(100);
GPIOE->ODR |= (1<<1); //RES 拉高
Delay_ms(100);
//
LCD_WR_CMD(0x00E5); LCD_WR_Data(0x78f0);
LCD_WR_CMD(0x00E3); LCD_WR_Data(0x3008);
LCD_WR_CMD(0x00E7); LCD_WR_Data(0x0010);
LCD_WR_CMD(0x00EF); LCD_WR_Data(0x1231);
//LCD_WR_CMD(0x0000); //Æô¶¯Õðµ´
LCD_WR_CMD(0x0001); LCD_WR_Data(0x0100);
LCD_WR_CMD(0x0002); LCD_WR_Data(0x0700);
LCD_WR_CMD(0x0003); LCD_WR_Data(0x1030);
LCD_WR_CMD(0x0004); LCD_WR_Data(0x0000);
LCD_WR_CMD(0x0008); LCD_WR_Data(0x0202);
LCD_WR_CMD(0x0009); LCD_WR_Data(0x0000);
LCD_WR_CMD(0x000A); LCD_WR_Data(0x0000);
LCD_WR_CMD(0x000C); LCD_WR_Data(0x0011);
LCD_WR_CMD(0x000D); LCD_WR_Data(0x0000);
LCD_WR_CMD(0x000F); LCD_WR_Data(0x0000);
//--***********ÉϵçʱÐò ***********--//
LCD_WR_CMD(0x0010); LCD_WR_Data(0x0000);
LCD_WR_CMD(0x0011); LCD_WR_Data(0x0007);
LCD_WR_CMD(0x0012); LCD_WR_Data(0x0000);
LCD_WR_CMD(0x0013); LCD_WR_Data(0x0000);
Delay_ms(300);
LCD_WR_CMD(0x0010); LCD_WR_Data(0x1690);
LCD_WR_CMD(0x0011); LCD_WR_Data(0x0227);
Delay_ms(200); // Delay 50ms
LCD_WR_CMD(0x0012); LCD_WR_Data(0x009D);
Delay_ms(200); // Delay 50ms
LCD_WR_CMD(0x0013); LCD_WR_Data(0x1900);
LCD_WR_CMD(0x0029); LCD_WR_Data(0x0025);
LCD_WR_CMD(0x002B); LCD_WR_Data(0x000D);
Delay_ms(200); // Delay 50ms
LCD_WR_CMD(0x0020); LCD_WR_Data(0x0000);
LCD_WR_CMD(0x0021); LCD_WR_Data(0x0000);
Delay_ms(100);
// ----------- µ÷ÕûÙ¤ÂíÇúÏß ----------//
LCD_WR_CMD(0x0030); LCD_WR_Data(0x0007);
LCD_WR_CMD(0x0031); LCD_WR_Data(0x0303); //0303
LCD_WR_CMD(0x0032); LCD_WR_Data(0x0003); //0003
LCD_WR_CMD(0x0035); LCD_WR_Data(0x0206); //0206
LCD_WR_CMD(0x0036); LCD_WR_Data(0x0008); //0008
LCD_WR_CMD(0x0037); LCD_WR_Data(0x0406); //0406
LCD_WR_CMD(0x0038); LCD_WR_Data(0x0304); //0304
LCD_WR_CMD(0x0039); LCD_WR_Data(0x0007); //0007
LCD_WR_CMD(0x003C); LCD_WR_Data(0x0602); //0602
LCD_WR_CMD(0x003D); LCD_WR_Data(0x0008);
//------------------ Set GRAM area ---------------//
LCD_WR_CMD(0x0050); LCD_WR_Data(0x0000);
LCD_WR_CMD(0x0051); LCD_WR_Data(0x00ee);
LCD_WR_CMD(0x0052); LCD_WR_Data(0x0000);
LCD_WR_CMD(0x0053); LCD_WR_Data(0x013f);
LCD_WR_CMD(0x0060); LCD_WR_Data(0xA700);
LCD_WR_CMD(0x0061); LCD_WR_Data(0x0001);
LCD_WR_CMD(0x006A); LCD_WR_Data(0x0000);
//-------------- ²¿·ÖÏÔʾ¿ØÖÆ ---------//
LCD_WR_CMD(0x0080); LCD_WR_Data(0x0000);
LCD_WR_CMD(0x0081); LCD_WR_Data(0x0000);
LCD_WR_CMD(0x0082); LCD_WR_Data(0x0000);
LCD_WR_CMD(0x0083); LCD_WR_Data(0x0000);
LCD_WR_CMD(0x0084); LCD_WR_Data(0x0000);
LCD_WR_CMD(0x0085); LCD_WR_Data(0x0000);
//-------------- ¿ØÖÆÃæ°å -------------------//
LCD_WR_CMD(0x0090); LCD_WR_Data(0x0010);
LCD_WR_CMD(0x0092); LCD_WR_Data(0x0000);
//LCD_WR_CMD(0x0093); LCD_WR_Data(0x0133);
//LCD_WR_CMD(0x0095); LCD_WR_Data(0x0110);
//LCD_WR_CMD(0x0097); LCD_WR_Data(0x0000);
//LCD_WR_CMD(0x0098); LCD_WR_Data(0x0000);
LCD_WR_CMD(0x0007); LCD_WR_Data(0x0133); //开lcd显示
GPIOB->ODR |= (1 << 12); //开lcd背光
}
|