Beispiel #1
0
/** Initialise the LCD
 *
 * Sets up the pins required to communicate with the LCD screen and then does
 * the actual chipset initialisation. The pin numbers to use are defined in
 * @ref hardware.h.
 */
void lcdInit() {
  LCD_SCK_SET_OUTPUT();
  LCD_MOSI_SET_OUTPUT();
  LCD_CD_SET_OUTPUT();

  LCD_SCK_LOW();
  LCD_MOSI_LOW();
  LCD_CD_LOW();

#if defined(LCD_USE_PROGRAM_RESET) 
  LCD_RESET_SET_OUTPUT();
  LCD_RESET_LOW();
  // Do a hard reset on the LCD
  waitReset();
  //PORTB |= (1 << LCD_RESET);
  LCD_RESET_HIGH();
#endif

  // Initialise the LCD
  lcdCommand(0x21);  // LCD Extended Commands.
  lcdCommand(0x80|LCD_CONTRAST_VALUE);  // Set LCD Vop (Contrast).
  lcdCommand(0x04);  // Set Temp coefficent.
  lcdCommand(0x14);  // LCD bias mode 1:48.
  lcdCommand(0x20);  // LCD Normal commands
  lcdCommand(0x08 | 0x04);  // Normal display, horizontal addressing
}
/**
  * @brief  Power on the LCD.
  * @param  None
  * @retval None
  */
void st7789v_Init(void)
{
  /* Initialize st7789v low level bus layer ----------------------------------*/
  LCD_IO_Init();
	HAL_GPIO_WritePin(GPIOA,GPIO_PIN_10,0x01);
	HAL_GPIO_WritePin(GPIOC,GPIO_PIN_6,0x01);
  LCD_RESET_HIGH();
  HAL_Delay(1);              //delay 1ms
  LCD_RESET_LOW();
  HAL_Delay(10);             //delay 10ms
  LCD_RESET_HIGH();
  HAL_Delay(120);
  
  /* Configure LCD */
  st7789v_WriteReg(0x11);
  HAL_Delay(120);
  st7789v_WriteReg(0x36); //Memory Data Access Control
  st7789v_WriteData(0x00); 

  st7789v_WriteReg(0x3a);//Interface Pixel Format
  st7789v_WriteData(0x05);//MCU-16bit  05
 
  st7789v_WriteReg(0x2a);
  st7789v_WriteData(0x00);
  st7789v_WriteData(0x00);
  st7789v_WriteData(0x00);
  st7789v_WriteData(0xef);
  
  st7789v_WriteReg(0x2b);
  st7789v_WriteData(0x00);
  st7789v_WriteData(0x00);
  st7789v_WriteData(0x00);
  st7789v_WriteData(0xef);
  
  /*frame rate setting*/
  st7789v_WriteReg(0xb2);//portch
  st7789v_WriteData(0x0c);//normal BP
  st7789v_WriteData(0x0c);//normal FP
  st7789v_WriteData(0x00);//enable seperate
  st7789v_WriteData(0x33);//idle, BP[7:4], FP[3:0]
  st7789v_WriteData(0x33);//partial, BP[7:4], FP[3:0]
  
  st7789v_WriteReg(0xb7); //gate control
  st7789v_WriteData(0x56);//VGH=14.06v,VGL=-11.38
  /*power setting*/
  st7789v_WriteReg(0xbb); //VCOMS Setting
  st7789v_WriteData(0x1e);
  
  st7789v_WriteReg(0xc0);
  st7789v_WriteData(0x2c);
  
  st7789v_WriteReg(0xc2);
  st7789v_WriteData(0x01);
  
  st7789v_WriteReg(0xc3); //VRH Set
  st7789v_WriteData(0x13); //4.5v
  
  st7789v_WriteReg(0xc4);
  st7789v_WriteData(0x20);
  
  st7789v_WriteReg(0xc6); //frame rate control in normal mode
  st7789v_WriteData(0x0f);
  
  st7789v_WriteReg(0xd0); // power control 1
  st7789v_WriteData(0xa4);//
  st7789v_WriteData(0xa1);//AVDD=6.8v, AVCL=-4.8v, VDS=2.3V
  
  //----GAMMA------------------------------------

  st7789v_WriteReg(0xe0);
  st7789v_WriteData(0xD0);
  st7789v_WriteData(0x03);
  st7789v_WriteData(0x08);
  st7789v_WriteData(0x0E);
  st7789v_WriteData(0x11);
  st7789v_WriteData(0x2B);
  st7789v_WriteData(0x3B);
  st7789v_WriteData(0x44);
  st7789v_WriteData(0x4C);
  st7789v_WriteData(0x2B);
  st7789v_WriteData(0x16);
  st7789v_WriteData(0x15);
  st7789v_WriteData(0x1E);
  st7789v_WriteData(0x21);

  st7789v_WriteReg(0xe1);
  st7789v_WriteData(0xD0);
  st7789v_WriteData(0x03);
  st7789v_WriteData(0x08);
  st7789v_WriteData(0x0E);
  st7789v_WriteData(0x11);
  st7789v_WriteData(0x2B);
  st7789v_WriteData(0x3B);
  st7789v_WriteData(0x54);
  st7789v_WriteData(0x4C);
  st7789v_WriteData(0x2B);
  st7789v_WriteData(0x16);
  st7789v_WriteData(0x15);
  st7789v_WriteData(0x1E);
  st7789v_WriteData(0x21);

  st7789v_WriteReg(0x29);	//Display ON 
  
	
//	g_LCD = st7789v_ReadID();
//	
//	while (1);
}