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

📄 lcd_pg320240.c

📁 how to use display powertip PG 320x240
💻 C
字号:
//-----------------------------------------------------------------------------
//    Project Name:   Demo board for graphic LCD PG240128 with touchscreen
//    Description:    Demo Board - main file
//    Processor:      uPD78F0034AY
//    Revision:       1.0
//    Date:           20.12.2003
//    Compiler:       C crosscompiler IAR 2.22
//   
//-----------------------------------------------------------------------------

#include "common.h"
#include "ports.h"
#include "lcd_pg320240.h"
unsigned char Color_4BPP[16*3] =
{
	0x00, 0x00, 0x00,// BLACK 
	0x01, 0x01, 0x01,// BLUE 
	0x02, 0x02, 0x02,// GREEN
	0x03, 0x03, 0x03,// CYAN 
	0x04, 0x04, 0x04,// RED 
	0x05, 0x05, 0x05,// PURPLE 
	0x06, 0x06, 0x06,// YELLOW 
	0x07, 0x07, 0x07,// WHITE 
	0x08, 0x08, 0x08,// BLACK
	0x09, 0x09, 0x09,// LT BLUE
	0x0A, 0x0A, 0x0A,// LT GREEN
	0x0B, 0x0B, 0x0B,// LT CYAN
	0x0C, 0x0C, 0x0C,// LT RED
	0x0D, 0x0D, 0x0D,		// LT PURPLE
	0x0E, 0x0E, 0x0E,		// LT YELLOW
	0x0F, 0x0F, 0x0F		// LT WHITE
};
/*
unsigned char Color_4BPP[16*3] =
{
	0x00, 0x00, 0x00,// BLACK 
	0x05, 0x05, 0x05,// BLUE 
	0x0A, 0x0A, 0x0A,// GREEN
	0x0F, 0x0F, 0x0F,// CYAN 
	0x04, 0x04, 0x04,// RED 
	0x05, 0x05, 0x05,// PURPLE 
	0x06, 0x06, 0x06,// YELLOW 
	0x07, 0x07, 0x07,// WHITE 
	0x08, 0x08, 0x08,// BLACK
	0x09, 0x09, 0x09,// LT BLUE
	0x0A, 0x0A, 0x0A,// LT GREEN
	0x0B, 0x0B, 0x0B,// LT CYAN
	0x0C, 0x0C, 0x0C,// LT RED
	0x0D, 0x0D, 0x0D,		// LT PURPLE
	0x0E, 0x0E, 0x0E,		// LT YELLOW
	0x0F, 0x0F, 0x0F		// LT WHITE
};

*/ 
void wr_data(unsigned char Data)
{
	DATA &=0xFF00;
    _nop();
    _nop();
    DATA |= Data; 
}

// write data to LCD
void lcd_write_data(unsigned char Data)
{
	wr_data(Data);
	WRITE = 0;
	while(!WAIT);
	WRITE = 1;
}
//-----------------------------------------------------------------------------
// 
void lcd_write_address(unsigned int Address)
{
    wr_data(Address & 0x00FF);
    ABL = 1;
   	ABL = 0;
	wr_data((Address>>8) & 0x00FF);
    ABH = 1;
	ABH = 0;
}

unsigned char reverseLSB_MSB( unsigned char RevData)
{
	unsigned char Revers = 0;
	unsigned char i;
	for(i=0;i<8;i++)
	{
		Revers = Revers << 1;
		Revers |= (RevData & 0x01);
		RevData = RevData >> 1;
	}
	return(Revers);
}

//-----------------------------------------------------------------------------
void lcd_set_reg (unsigned int Address, unsigned char Data)
{
	Address += REG_OFFSET;
    CS = 0;
	lcd_write_address(Address);
	lcd_write_data(Data);
	CS = 1;
}
//*****************************************************************************
unsigned char lcd_read_reg(unsigned int Address,unsigned char Reg)
{
	unsigned int Data;
    CS = 0;
	READ 	= 1;
    WRITE 	= 1;
   // AB16 = 0;
    if (Reg) Address += REG_OFFSET;
	lcd_write_address(Address);
  //  AB16 = 1;
    SETDATAINPUT;
	READ 	= 0;
    while(!WAIT);
	Data 	= DATA;
    READ 	= 1;
    SETDATAOUTPUT;
    CS = 1;
   //	Data =  reverseLSB_MSB(Data); 
    return(Data);    
}
//-----------------------------------------------------------------------------
void lcd_write (unsigned int Address, unsigned char Data)
{
  	CS = 0;
  	lcd_write_address(Address);
	lcd_write_data(Data);
    CS = 1;
}

// initializing of display
void lcd_init (void)
{
	int i;   
    /* Initialize the chip. Each register is individually programmed to make comments clearer.*/
	lcd_set_reg(0x01, 0x00); 	//Register 01h: Mode Register 0 - Mono, 4-bit format 2
	lcd_set_reg(0x02, 0xB0); 	//Register 02h: Mode Register 1 - 4BPP, High Performance, CLKi/2
//	lcd_set_reg(0x02, 0x60); 	//Register 02h: Mode Register 1 - 2BPP, High Performance, CLKi/2

	lcd_set_reg(0x03, 0x03);	//Register 03h: Mode Register 2 - Normal power mode
    lcd_set_reg(0x04, 0x27);	//Register 04h: Horizontal Panel Size - 320 pixels - (320/8)-1 = 39 = 27h
	lcd_set_reg(0x05, 0xEF);	//Register 05h: Vertical Panel Size LSB - 240 pixels
	lcd_set_reg(0x06, 0x00);	//Register 06h: Vertical Panel Size MSB - (240 - 1) = 239 = EFh
	lcd_set_reg(0x07, 0x1E);	//Register 07h - FPLINE Start Position - not used by STN
	/* Register 08h - Horizontal Non-Display Period HNDP and VNDP are calculated to achieve the
	** desired frame rate according to:
	** 						PCLK
	** Frame Rate = ---------------------------
	** 				(HDP + HNDP) * (VDP + VNDP)
	*/
	lcd_set_reg(0x08, 0x00);
	lcd_set_reg(0x09, 0x00);	//Register 09h - FPFRAME Start Position - not used by STN

	/*  Register 0Ah - Vertical Non-Display Register Calculated in conjunction with register 08h (HNDP) to
	achieve the desired frame rate. */
  //	lcd_set_reg(0x0A, 0x3B);
	lcd_set_reg(0x0A, 0x26);
	lcd_set_reg(0x0B, 0x00);	//Register 0Bh - MOD Rate - not used by this panel
	lcd_set_reg(0x0C, 0x00);	//Register 0Ch - Screen 1 Start Word Address LSB
	lcd_set_reg(0x0D, 0x00);	//Register 0Dh - Screen 1 Start Word Address MS. Start address should be set to 0B
	lcd_set_reg(0x0F, 0x00);	//Register 0Fh - Screen 2 Start Word Address LSB
	lcd_set_reg(0x10, 0x00);	//Register 10h - Screen 2 Start Word Address MSB. Set this start address to 0 too
	lcd_set_reg(0x12, 0x00);	//Register 12h - Memory Address Offset. Used for setting memory to a width greater than the display size.
							//Usually set to 0 during initialization and programmed to desired value later.
	/* This register is used for split screen operation and should be set to 0 during initialization.
	Set to maximum (i.e. 0x3FF). */
	lcd_set_reg(0x13, 0xFF);	//Register 13h - Screen 1 Vertical Size LSB
	lcd_set_reg(0x14, 0x03);	//Register 14h - Screen 1 Vertical Size MSB

	/* Look-Up Table In this example the LUT will be programmed in the register sequence.
		In practice the LUT would probably be done after the other registers.*/
	lcd_set_reg(0x15, 0x00);	//Register 15h - Look-Up Table Address. Set to 0x20 to start Gray sequencing at the first LUT entry.
	lcd_set_reg(0x16, 0x00);	//Register 16h - Look-Up Table Bank Select.Set all the banks to 0.
	// At 4BPP this makes no difference however it will affect appearance at other color depths.
   	for (i = 0; i < 16; i++) { lcd_set_reg(0x17, i);lcd_set_reg(0x17, i);lcd_set_reg(0x17, i);}
	   	//Register 17h - Look-Up Table Data. Write 16 RGB triplets to setup the LUT for 4BPP operation.
		//The LUT is 16 elements deep, 4BPP uses all the idices.
	lcd_set_reg(0x18, 0x00);	//Register 18h - GPIO Configuration - set to 0 - '0' configures the GPIO pins for input (power on default)
	lcd_set_reg(0x19, 0x00);	//Register 19h - GPIO Status - set to 0

	lcd_set_reg(0x1A, 0x00);	//Register 1Ah - Scratch Pad - set to 0
	lcd_set_reg(0x1B, 0x00);	//Register 1Bh - SwivelView Mode - set to 0 - disable SwivelView mode
	lcd_set_reg(0x1C, 0xA0);	//Register 1Ch - Line Byte Count - set to 0 - Not used by landscape mode
	lcd_set_reg(0x1F, 0x00);	//Register 1Fh - TestMode - set to 0
}

void lcd_clear(void)
{
	unsigned int i;
    /* Clear the display, and all of video memory, by writing 40960 bytes of 0.
 	This is done because an image in display memory is not rotated with
 	the switch to SwivelView mode we are about to make.*/
	for (i=0;i < 38400;i++) lcd_write(i,0x00);
}

⌨️ 快捷键说明

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