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

📄 drv_lcd.c

📁 一款SmartPhone的驱动代码
💻 C
字号:
#include "sysMCU.h"
#include "sysLCDC.h"

/*****************************50090 command and data **************************************/
const unsigned short DISCTL_DATA1[5]={
		0x00F8,0x0000,0x00F0,0x0000,0x0002
		};

const unsigned short DISCTL_DATA2[6]={
		0x00CF,0x0001,0x0006,0x0018,0x0004,0x0000
		};

const unsigned short GCP64[32]={
0x41, 0x00, 0x81, 0x02, 0x01, 0x01, 0x02, 0x04,
0x08, 0x08, 0x20, 0x81, 0x08, 0x42, 0x08, 0x89,
0x12, 0x25, 0x29, 0x55, 0x2a, 0xa9, 0x2a, 0xab,
0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
/*****************************50090 command and data **************************************/



signed short VRAM[LCDHEIGHT*LCDWIDTH];
//signed short * VRAM=0x280000;
signed short * pVRAM=VRAM;

unsigned char gCurrentConTrast = 0x0060;
#define		MAX_CONTRAST_VALUE		0x0070

void halDelayUS(void)	
{
	int i,j;
	for(i=0;i<180;i++)
	{
		for(j=0;j<200;j++)
			asm("nop");
	}	
}

void init_dlcd_hardware( void )
{

	unsigned short stride = 176*2;	
	unsigned short TempBuffer[0x8000];
	unsigned short current;

	unsigned long i,j=0;
	//turn on the backlight of the lcd,p35
 	*(volatile unsigned char *)IO_CFP3_ADDR &= 0xdf;
 	*(volatile unsigned char *)IO_IOC3_ADDR |= 0x20;
 	*(volatile unsigned char *)IO_P3D_ADDR |= 0x20;	

	halInitController(fINIT_NORMAL);					// initial the 137xx lcdc
	 	
 	//Reset the 50052
	*( volatile unsigned char * )0x402D4 &= 0xBF;		// set the P16 as IO port
	*( volatile unsigned char * )0x402D6 |= 0x40;		// set the P16 as output port
	*( volatile unsigned char * )0x402D5 &= 0xBF;		// set the P16 to 'L'
	*( volatile unsigned char * )0x402D5 |= 0x40;		// set the P16 to 'H'
	
	SetOutputPort(cl_PORT_ALL_OFF);				// Set All LCD port Close
	
	SetPanelIfType(cl_RGB_Serial);				// Select the Interface is RGB and Serial
	
	SetLcdPClkDivide(4);						// SCLK=SYSCLK/4=15/4=3.75MHz 
	SetRGBPanelClkPol(1);						// Interface signals will change at the falling edge of clock and the panel sample data at the rising edge of pixel clock
	SetRGBPanelDataWidth(RGB_PANEL_WIDTH_18);	// Data bus width is 18-bit
	SetRGBPanelType(0);							// Panel type is General TFT

	SetLcdHVTotal (208,250);					// LCD1 Horizontal Total 
	SetLcdHVDispPer(cl_LCD1,176,240);			// LCD1 Horizontal Display 
	SetLcdHVStartPos (14,1);					// LCD1 Horizontal Display Period start position
	SetLcdFpline(0,10,14);						// the FpLine signal (Polarity:Active high;Width:176 pixel;position:1 pixel)														 
	SetLcdFPFrame(0,1,0);						// the FpFrame signal attribute
	SetSerialLcdClkDivide(4);					// LCD1 serial Clock is sysclk/4
	SetLcdSif(cl_LCD1,0x0003);					// LCD1 serial port attribute

	InitLut(cl_LUT1, cl_LUT_NOBYPASS_16BPP_565LUT);

	SetLutBypassEnable(cl_LUT1, ON);
	SetLutBypassEnable(cl_LUT2, ON);

	SelectDispMode(cl_DISPLAY_MODE_NORMAL);
	
	SetDisplayMode(cl_MAIN_WINDOW, 16);
	SetDisplayMode(cl_PIP_WINDOW, 16);
	
	SetOutputPort(cl_PORT_LCD1);

	halDelayUS();
	
//  	initial the 50090 

	Write_lcd_com((unsigned short)DISCTL1);		// Display Control1
	Write_lcd_param(0x00F8);
	Write_lcd_param(0x0000);
	Write_lcd_param(0x00F0);
	Write_lcd_param(0x0000);
	Write_lcd_param(0x0002);
	halDelayUS();


	Write_lcd_com((unsigned short)DISCTL2);		// Display Control2
	Write_lcd_param(0x00CF);
	Write_lcd_param(0x0001);
	Write_lcd_param(0x0006);
	Write_lcd_param(0x0018);
	Write_lcd_param(0x0004);
	Write_lcd_param(0x0000);
	halDelayUS();

	Write_lcd_com((unsigned short)GCPSET);		// GRAYS SCALES
	Write_lcd_param_loop(32,GCP64);				
	halDelayUS();


	Write_lcd_com((unsigned short)SLPOUT);		// sleep out	
	halDelayUS();
	
	Write_lcd_com((unsigned short)DISON);		// Display On / Off	
	halDelayUS();	
	
	Write_lcd_com((unsigned short)VOLCTR);		// 
	Write_lcd_param(0x0080);
	halDelayUS();
	
	Write_lcd_com((unsigned short)VOLCTR);		// 
	Write_lcd_param(gCurrentConTrast);


	init_timer3_8bit();
	memset(VRAM,0xFFFF,LCDHEIGHT*LCDWIDTH);				// Clean the VRAM Buffer
	init_hsdma3(&VRAM[0]);
//	StartDMA(0,0,(LCDHEIGHT-1),(LCDWIDTH-1),&VRAM[0],MAIN_WINDOW_ADDRESS);
}

void fnIHL_DlcdShowCoordinate(long x,long y,short c)
{
	
	short Temp;
	for (Temp =0;Temp<10;Temp++)
	 	VRAM[(y-5+Temp)*LCDWIDTH+x] = c;
	for (Temp =0;Temp<10;Temp++)
	 	VRAM[y*LCDWIDTH+(x-5+Temp)] = c;

//	StartDMA(0,0,(LCDHEIGHT-1),(LCDWIDTH-1),&VRAM[0],MAIN_WINDOW_ADDRESS);	
}


unsigned char halGetContrast( void )
{
	return gCurrentConTrast; 
}

void halSetContrast( unsigned char contrast )
{
	Write_lcd_com((unsigned short)VOLCTR);		// 
	Write_lcd_param(0x0080);
	halDelayUS();
	
	Write_lcd_com((unsigned short)VOLCTR);		// 
	Write_lcd_param(contrast);

	gCurrentConTrast = contrast;

	return;
}

// change the contrast
// flag = 0--------decrease
// flag !=0--------increase
unsigned char halChangeContrast( unsigned char flag )
{
	if( flag )		// increase
	{
		if( gCurrentConTrast < MAX_CONTRAST_VALUE )
		{
			Write_lcd_com((unsigned short)VOLCTR);		// 
			Write_lcd_param(0x009f);
			gCurrentConTrast ++;
		}
	}
	else		// decrease
	{
		if( gCurrentConTrast )
		{
			Write_lcd_com((unsigned short)VOLCTR);		// 
			Write_lcd_param(0x009e);
			gCurrentConTrast --;
		}
	}
	return gCurrentConTrast;
}

⌨️ 快捷键说明

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