⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcdinit.c

📁 驱动IC为:s6e63d6x的OLED液晶(c0283qglc-t)
💻 C
字号:
void mdelay(int ms)
{
	U32 val = (PCLK>>3)/1000-1;
	
	rTCFG0 &= ~(0xff<<8);
	rTCFG0 |= 3<<8;			//prescaler = 3+1
	rTCFG1 &= ~(0xf<<12);
	rTCFG1 |= 0<<12;		//mux = 1/2

	rTCNTB3 = val;
	rTCMPB3 = val>>1;		// 50%
	rTCON &= ~(0xf<<16);
	rTCON |= 0xb<<16;		//interval, inv-off, update TCNTB3&TCMPB3, start timer 3
	rTCON &= ~(2<<16);		//clear manual update bit
	while(ms--) {
		while(rTCNTO3>=val>>1);
		while(rTCNTO3<val>>1);
	};

}

void InitSPI(void)  
{ 
  
  rGPDCON &= ~(3<<16);  
  rGPDCON |= (3 << 16); //GPD8,SPIMISO1
  
  rGPDCON &= ~(3<<18);  
  rGPDCON |= (3 << 18); //GPD9,SPIMOSI1
  
  rGPDCON &= ~(3<<20);  
  rGPDCON |= (3 << 20); //GPD10,SPICLK1
    
  rGPDUP &= ~(1<<8); //enable pullup for GPD8 
  rGPDUP &= ~(1<<9); //enable pullup for GPD9
  rGPDUP &= ~(1<<10); //enable pullup for GPD10
  
  // Config GPC6 is Master SPI CS                                     
  rGPCCON &= ~(3<<12);                           
  rGPCCON |=  (1<<12); //GPC6 as out
  
  // Initialize CS is high 
  rGPCUP  &= ~(1<<6); //enable pullup for GPC6         
  rGPCDAT |=  (1<<6); //CS,High   
  
  rSPPRE1 = 0x18;    
  rSPCON1 =0x18; 
  rSPPIN1=0x02;   //使用默认值   
} 

void SPI_Write(char *pBuffer, char dwNumBytes) 
{ 
  char *temp ; 
  char i ;  
  temp = pBuffer;  
  rGPCDAT &= ~(1<<6);// Set CS to low
  	for(i=0;i<dwNumBytes;i++)
	{
	  // Check the status of Transfer Ready flag(READY=1) ,and then write data to SPTDAT0 
	  while( (rSPSTA1 & 0x01) != 1 ); 
	  rSPTDAT1 = *temp; // Write Potentiometer value 
	  temp++;
	}
   while( (rSPSTA1 & 0x01) != 1 ); 
  
  //Delay(1);  
  rGPCDAT  |= (1<<6); // Set CS to high 
} 

void lcd_SpiSetREG(char RegAdd,int value)
{
	char temp[3];
	//Sets Index Register
	temp[0]=0x70;//Write_Command
	temp[1]=0x00;
	temp[2]=RegAdd;
	SPI_Write(temp,3);
	//Writes Instruction
	temp[0]=0x72;//Write_Data
	temp[1]=(value>>8)&0xff;
	temp[2]=(value)&0xff;
	SPI_Write(temp,3);
}

void lcd_SpiSetREG_Cmd(char RegAdd)
{
	char temp[3];
	//Sets Index Register
	temp[0]=0x70;//Write_Command
	temp[1]=0x00;
	temp[2]=RegAdd;
	SPI_Write(temp,3);
}

void lcd_SpiSetREG_Data(int value)
{
	char temp[3];
	//Writes Instruction
	temp[0]=0x72;//Write_Data
	temp[1]=(value>>8)&0xff;
	temp[2]=(value)&0xff;
	SPI_Write(temp,3);
}

void Lcd_Reset()
{
	//POWER ON
	//reset
	rGPCCON &= ~(3 << 10);					
	rGPCCON |=  (1 << 10);//GPC5 as OUT	
	//rGPCUP  &= ~(1 <<  5);//enable pullup for GPC5	
	rGPCDAT |= (1 << 5);//resetIO high
	mdelay(1);		
	rGPCDAT &= ~(1 << 5);//resetIO low	
	mdelay(10);	
	rGPCDAT |= (1 << 5);//resetIO high
	mdelay(50);
}
void Lcd_SpiInit()
{
	//150nits
	lcd_SpiSetREG(0x70, 0x2000);	
	lcd_SpiSetREG(0x71, 0x2180);	
	lcd_SpiSetREG(0x72, 0x2d80);	
	lcd_SpiSetREG(0x73, 0x1512);	
	lcd_SpiSetREG(0x74, 0x1c10);	
	lcd_SpiSetREG(0x75, 0x2216);
	lcd_SpiSetREG(0x76, 0x1813);	
	lcd_SpiSetREG(0x77, 0x2219);	
	lcd_SpiSetREG(0x78, 0x2014);

	lcd_SpiSetREG(0xF8, 0x000f);		//Power gen3,VGH4~VGH0
	lcd_SpiSetREG(0xF9, 0x000f);		//Power gen4,VGL4~VGL0
	
	lcd_SpiSetREG(0x02, 0x0190);		//RGB 16bit interface control	
	lcd_SpiSetREG(0x03, 0x0020);		//Entry mode	

	lcd_SpiSetREG(0x20, 0x00ef);
	lcd_SpiSetREG(0x21, 0x0000);
	
	lcd_SpiSetREG(0x10, 0x0000); 		//Stand by mode off
	
	lcd_SpiSetREG(0x05, 0x0001);		//Display control1, display on
	lcd_SpiSetREG_Cmd(0x22);		//This command is very important!
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -