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

📄 tft_hx8345.c

📁 ARMSTM32 lcd驱动程序集锦
💻 C
📖 第 1 页 / 共 3 页
字号:

	HX8345_sendcommand1(0x0030, 0x0000);
	HX8345_sendcommand1(0x0031, 0x0205); 
	HX8345_sendcommand1(0x0032, 0x0000); 
	HX8345_sendcommand1(0x0033, 0x0203); 
	HX8345_sendcommand1(0x0034, 0x0707); 
	HX8345_sendcommand1(0x0035, 0x0205); 
	HX8345_sendcommand1(0x0036, 0x0705); 
	HX8345_sendcommand1(0x0037, 0x0302); 
	HX8345_sendcommand1(0x003a, 0x0800);
	
    HX8345_sendcommand1(0x003b, 0x0004);
    HX8345_sendcommand1(0x0000, 0x0001);
    HX8345_sendcommand1(0x000d, 0x0000);
	Delayms(50);
	HX8345_sendcommand1(0x000e, 0x0000);
	Delayms(50);
	HX8345_sendcommand1(0x0007, 0x0000);
	Delayms(50);
	HX8345_sendcommand1(0x000c, 0x0000);
	Delayms(50);
	
	HX8345_sendcommand1(0x000d, 0x0003);
	Delayms(50);
	HX8345_sendcommand1(0x000e, 0x1118);
	Delayms(50);
	
	//HX8345_sendcommand1(0x000d, 0x0012);
	HX8345_sendcommand1(0x000d, 0x0013);//0011
	
	Delayms(50);
	HX8345_sendcommand1(0x0003, 0x0010);    
	Delayms(50);
	HX8345_sendcommand1(0x0009, 0x0000);
	Delayms(50);

	HX8345_sendcommand1(0x0003, 0x0208);  //0x0508//0208//0410
	Delayms(50);

    HX8345_sendcommand1(0x000e, 0x3118);  //0x3119//341c//0x3219//3118//3319
	Delayms(10);
	
	HX8345_sendcommand1(0x0007, 0x0005);
	Delayms(50);
	HX8345_sendcommand1(0x0007, 0x0025);
	Delayms(50);
	HX8345_sendcommand1(0x0007, 0x0027);
	Delayms(50);
	HX8345_sendcommand1(0x0007, 0x0037);
	Delayms(50);

	#else

	 HX8345_sendcommand1(0x0000, 0x0001);
     HX8345_sendcommand1(0x0001, 0x0113);  //0013
     HX8345_sendcommand1(0x0002, 0x0700); //0700
     HX8345_sendcommand1(0x0005, 0x0030); //0030
     HX8345_sendcommand1(0x0006, 0x0000);
     HX8345_sendcommand1(0x0008, 0x0202);
     HX8345_sendcommand1(0x000a, 0x0000);
     HX8345_sendcommand1(0x000b, 0x1800);   //1800  0d00
     HX8345_sendcommand1(0x000f, 0x0000);  //000f
     HX8345_sendcommand1(0x0010, 0x0000);
     HX8345_sendcommand1(0x0011, 0x0000);
     HX8345_sendcommand1(0x0014, 0x9f00);
     HX8345_sendcommand1(0x0015, 0x9f00);
     HX8345_sendcommand1(0x0016, 0x7f00);
     HX8345_sendcommand1(0x0017, 0x9f00);
     HX8345_sendcommand1(0x0020, 0x0000);
     HX8345_sendcommand1(0x0021, 0x0000);
     HX8345_sendcommand1(0x0023, 0x0000);
     HX8345_sendcommand1(0x0024, 0x0000);
     HX8345_sendcommand1(0x0025, 0x0000);
     HX8345_sendcommand1(0x0026, 0x0000);
     Delayms(50);
     
     HX8345_sendcommand1(0x0030, 0x0000);
     HX8345_sendcommand1(0x0031, 0x0407);
     HX8345_sendcommand1(0x0032, 0x0004);
     HX8345_sendcommand1(0x0033, 0x0402);
     HX8345_sendcommand1(0x0034, 0x0307);
     HX8345_sendcommand1(0x0035, 0x0003);
     HX8345_sendcommand1(0x0036, 0x0707);
     HX8345_sendcommand1(0x0037, 0x0304);
     HX8345_sendcommand1(0x003a, 0x0000);
     HX8345_sendcommand1(0x003b, 0x0d00);  //frame f 0e00
     
     HX8345_sendcommand1(0x000d, 0x0000);
     Delayms(50);
     HX8345_sendcommand1(0x000e, 0x0000);
     Delayms(50);
     HX8345_sendcommand1(0x0007, 0x0000);
     Delayms(50);
     HX8345_sendcommand1(0x000c, 0x0000);
     Delayms(50);
     HX8345_sendcommand1(0x0009, 0x0008);
     Delayms(50);
     HX8345_sendcommand1(0x000d, 0x0003);
     Delayms(50);
     HX8345_sendcommand1(0x000e, 0x1017);
     Delayms(50);
     HX8345_sendcommand1(0x000d, 0x0011);
     Delayms(50);
     HX8345_sendcommand1(0x0003, 0x0010);    
     Delayms(50);
     HX8345_sendcommand1(0x0009, 0x0000);
     Delayms(50);
     HX8345_sendcommand1(0x0003, 0x0208); //0410
     Delayms(50);
     HX8345_sendcommand1(0x000e, 0x3118);//3317 341b 391e
     Delayms(50);
     HX8345_sendcommand1(0x0009, 0x0002);
     Delayms(50);
     HX8345_sendcommand1(0x0007, 0x0005);
     Delayms(50);
     HX8345_sendcommand1(0x0007, 0x0025);
     Delayms(50);
     HX8345_sendcommand1(0x0007, 0x0027);
     Delayms(50);
     HX8345_sendcommand1(0x0007, 0x0037);
     Delayms(50);
   
     
    HX8345_SEND_COMMAND(0x0022);
    Delayms(100);
	#endif

    break;
	}
	

	

}	
}

/******************************************************************************/
//  Description:   Clear color LCD with one color
//	Global resource dependence: 
//  Author:         louis.wei
//	Note:
//  modify:  jim.cui	2005.0728  use dma to transport data  
/******************************************************************************/
LOCAL void HX8345_Clear(
						uint32 color	//color to fill the whole lcd.
						)
{
	uint32 i;
	uint16 *buf_ptr = (uint16 *)LCD_GetLCDBuffer();

	uint16  fill_color = color;
	
	for(i=0; i<(HX8345_HEIGHT ); i++)
	{

            dma_request(0, (uint32)&fill_color, (uint32)(buf_ptr + i * HX8345_WIDTH), HX8345_WIDTH, 
                                     1, 1);
		
	}

	HX8345_Invalidate();
}

/******************************************************************************/
//  Description:   Set the windows address to display, in this windows
//                 color is  refreshed.
//	Global resource dependence: 
//  Author:         Jim.zhang
//	Note:
/******************************************************************************/
__inline void HX8345_set_display_window(
	uint8 left, 	// start Horizon address
	uint8 top, 		// start Vertical address
	uint8 right, 	// end Horizon address
	uint8 bottom	// end Vertical address
	)
{
	uint16 addr1,addr2;
	addr1 = (((right&0xff)<<8)|(left&0xff));
	addr2 = (((bottom&0xff)<<8)|(top&0xff));
	
	HX8345_SEND_COMMAND(0x0016);
	HX8345_SEND_DATA(addr1);

	HX8345_SEND_COMMAND(0x0017);
	HX8345_SEND_DATA(addr2);

	
}


/******************************************************************************/
//  Description:  Set start RAM address which is write to AC(Address
//                Counter) register.
//  Input:
//      left: start Horizon address of AC
//      top: start Vertical address of AC.
//  Return:
//      None.
//	Note:           
/******************************************************************************/
__inline void HX8345_set_start_address(
	uint8 left, 
	uint8 top
	)
{
	uint16 addr;
	addr = (((top&0xff)<<8)|(left&0xff));
	HX8345_SEND_COMMAND(0x0021);
	HX8345_SEND_DATA(addr);
}

/******************************************************************************/
//  Description:   invalidate a rectang of in LCD
//	Global resource dependence: 
//  Author:         Jim.zhang
//	Note:
//  modify:  jim.cui  2005.0728  use  dma to transport data  
/******************************************************************************/
LOCAL ERR_LCD_E HX8345_Invalidate(void)
{
	uint16 i,j;
	//uint16 address = 0;
	uint16 *buf_ptr = (uint16 *)LCD_GetLCDBuffer();
	
#ifdef LCD_USE_DMA	
	//uint32  dummy_before,dummy_after;

	HX8345_set_display_window(0, 0, HX8345_WIDTH-1, HX8345_HEIGHT-1);
	HX8345_set_start_address(0, 0);
	HX8345_SEND_COMMAND(0x0022); 
/*
	address = (uint16) ( (((HX8345_WIDTH - 1 + OFFSET_X) & 0xFF ) << 8 ) | (OFFSET_X));
	HX8345_sendcommand1(0x44, address);		// set horizon address
	address = (uint16) ( ((HX8345_HEIGHT-1) & 0xFF) << 8 );

	HX8345_sendcommand1(0x45, address);	// set vertical address
	HX8345_sendcommand1(0x0021, OFFSET_X);	
*/
	//HX8345_SEND_COMMAND(0x0017); 			// send data.

	//dummy_before =  1 % 4;		// Inserted numbers befor every arrow.
	//dummy_after =  3 - (HX8345_WIDTH % 4);	// Inserted numbers after every arrow.
        
	for(j=0; j<(HX8345_HEIGHT ); j++)
	{

            dma_request(0, (uint32)(buf_ptr + j * HX8345_WIDTH), 0x58020000, HX8345_WIDTH, 
                                     1, 0);
		
	}

#else
	SCI_TRACE_LOW("tft_HX8345.c HX8345_Invalidate line%d", __LINE__);
	
	HX8345_set_display_window(0, 0, HX8345_WIDTH-1, HX8345_HEIGHT-1);
	HX8345_set_start_address(0, 0);
/*
	address = (uint16) ( (((HX8345_WIDTH - 1 + OFFSET_X) & 0xFF ) << 8 ) | (OFFSET_X));
	HX8345_sendcommand1(0x44, address);		// set horizon address
	address = (uint16) ( ((HX8345_HEIGHT-1) & 0xFF) << 8 );

	HX8345_sendcommand1(0x45, address);	// set vertical address
	HX8345_sendcommand1(0x0021, OFFSET_X);	
*/
	//HX8345_SEND_COMMAND(0x0017); 			// send data.
	
	for(i=0; i<(HX8345_WIDTH * HX8345_HEIGHT); i++)
		HX8345_SEND_DATA( *buf_ptr++ );
		
#endif
		
	return ERR_LCD_NONE;
}

/*****************************************************************************/
//  Description:    Get the lcd base information..
//	Global resource dependence: 
//  Author:         louis.wei
//	Note:
/*****************************************************************************/
LOCAL  ERR_LCD_E   HX8345_GetInfo(
								   LCD_INFO_T *lcd_info_ptr	//lcd information struct pointer
								   )
{
	if ( PNULL == lcd_info_ptr )
	{
		return ERR_LCD_POINTER_NULL;	
	}
	
	lcd_info_ptr->r_bitmask			= 0xf800;
	lcd_info_ptr->g_bitmask			= 0x07e0;
	lcd_info_ptr->b_bitmask			= 0x001f;
	lcd_info_ptr->bits_per_pixel	= 16;
	lcd_info_ptr->contrast_min		= 0x00;
	lcd_info_ptr->contrast_max   	= 63;
	lcd_info_ptr->contrast_defaut	= 0x0A;
	
	lcd_info_ptr->lcd_width		= HX8345_WIDTH;
	lcd_info_ptr->lcd_height	= HX8345_HEIGHT;
	lcd_info_ptr->lcdbuff_ptr	= (void *)LCD_GetLCDBuffer();
		
	return ERR_LCD_NONE;
}

/******************************************************************************/
//  Description:   Copy a retangle data from clcd_buffer to display RAM.
//                     then the rectangle display is to be refreshed
//	Global resource dependence: 
//  Author:         Jim.zhang
//	Note:       
//     To improve speed, lcd is operate in HIGH SPEED RAM WRITE MODE(4
//     uint16 are write continuously always.) So, some dummy uint16 
//     should be inserted to satisfy this mode.   Please refer to spec.
//  modify:  jim.cui  2005.0728  use  dma to transport data  
/******************************************************************************/

LOCAL ERR_LCD_E HX8345_InvalidateRect(
	uint16 left, 	//the left value of the rectangel
	uint16 top, 	//top of the rectangle
	uint16 right, 	//right of the rectangle
	uint16 bottom	//bottom of the rectangle
	)
{
	uint32 i, j;
	uint32 dummy_before, dummy_after;
	uint32 row, column,rect_width;
	uint16 *buf_ptr = (uint16 *)LCD_GetLCDBuffer();

	SCI_TRACE_LOW("0000000000000000000000000000000000000000000000");
	
	//****************************************************
	//**********解决进入摄像模式的问题*******************
    if (LCD_GetRefreshFlag() != TRUE )
		{
		      SCI_TRACE_LOW(" LCD_GetRefreshFlag");
			return ERR_LCD_OPERATE_FAIL ;
		}
	//*****************************************************
	SCI_TRACE_LOW("the  LCD_GetRefreshFlag is ------%x",LCD_GetRefreshFlag);

	//SCI_TRACE_LOW("tft_HX8345.c HX8345_InvalidateRect line%d: left = %d, top = %d, right = %d, bottom = %d", __LINE__, left, top, right,bottom);
  	left 	= (left >= HX8345_WIDTH)    ? HX8345_WIDTH-1 : left;
	right 	= (right >= HX8345_WIDTH)   ? HX8345_WIDTH-1 : right;
	top 	= (top >= HX8345_HEIGHT)    ? HX8345_HEIGHT-1 : top;
	bottom 	= (bottom >= HX8345_HEIGHT) ? HX8345_HEIGHT-1 : bottom;

	if ( ( right < left ) || ( bottom < top ) )
	{
		return ERR_LCD_PARAMETER_WRONG;
	}
 
 	 	
	HX8345_set_display_window(left, top, right, bottom);
	
	// In High Speed RAM Write Mode. Maybe some dummy data are insterted.
	//dummy_before =  (left) % 4;		// Inserted numbers befor every arrow.
	//dummy_after =  3 - (right % 4);	// Inserted numbers after every arrow.
	
#ifdef LCD_USE_DMA 		
	HX8345_set_start_address(left, top);
    HX8345_SEND_COMMAND(0x0022); 

	
       rect_width = right-left+1;
       
	for (j = top; j <= bottom; j++)
	{	

            dma_request(0, (uint32)(buf_ptr + j * HX8345_WIDTH+left), 0x58020000, rect_width, 
                    1, 0);	
	
	}
#else

	row = bottom - top;
	column = right - left;

	HX8345_set_start_address(left - dummy_before, top);

	HX8345_SEND_COMMAND(0x0022); 			// send data.

	for (i = 0; i <= row; i++)
	{	
		for(j = 0; j<dummy_before; j++) // Insert dummy write befor real write.
			HX8345_SEND_DATA(0x00);
			
		for (j = 0; j <= column; j++)	// real write 
			HX8345_SEND_DATA( *(buf_ptr + (top+i)*HX8345_WIDTH + left+j) );
	
		for(j=0; j<dummy_after; j++)	// Insert dummy write after real write.
			HX8345_SEND_DATA(0x00);
	}			
#endif
	
	return ERR_LCD_NONE;
}

/******************************************************************************/
//  Description:  for mp4 display
//	Global resource dependence: 
//  Author:  juan.zhang

/******************************************************************************/
LOCAL ERR_LCD_E HX8345_InvalidateRectImage(
	uint16 left, 	//the left value of the rectangel
	uint16 top, 	//top of the rectangle
	uint16 right, 	//right of the rectangle
	uint16 bottom,	//bottom of the rectangle
	uint16 *buf_ptr,
	uint8  is_invert//ignore
	)
{
	uint32 i, j;
	uint32 dummy_before, dummy_after;
	uint32 row, column,rect_width;

  	left 	= (left >= MP4_MAX_WIDTH)    ? MP4_MAX_WIDTH-1 : left;
	right 	= (right >= MP4_MAX_WIDTH)   ? MP4_MAX_WIDTH-1 : right;
	top 	= (top >= MP4_MAX_HEIGHT)    ? MP4_MAX_HEIGHT-1 : top;
	bottom 	= (bottom >= MP4_MAX_HEIGHT) ? MP4_MAX_HEIGHT-1 : bottom;

	left = 0;
	right = 127;
	top = 0;
	bottom = 159;	//175;	

	
    //****************************************************
	//**********解决进入摄像模式的问题*******************
    if (LCD_GetRefreshFlag() != TRUE )
		{
		      SCI_TRACE_LOW(" LCD_GetRefreshFlag");
			return ERR_LCD_OPERATE_FAIL ;
		}
	//*****************************************************

   

	if ( ( right < left ) || ( bottom < top ) )
	{
		return ERR_LCD_PARAMETER_WRONG;
	}

⌨️ 快捷键说明

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