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

📄 main_lcd_display.c

📁 unlinux下的LCD显示程序
💻 C
字号:
/***********************************************************************************
FILE NAME  		main_lcd_display.c
DESCRIPTION		Demonstration of SH7203 on-chip LCD controller.

Operation 	1. Build this application and download it to the target. Press 'Reset Go'. 
			2. The image data stored in the image.c file will be transferred to the TFT
			   LCD and the image will be displayed on the display. 

Copyright   : 2007 Renesas Technology Europe Ltd.
Copyright   : 2007 Renesas Technology Corporation.
All Rights Reserved
***********************************************************************************/

/***********************************************************************************
Revision History
DD.MM.YYYY OSO-UID Description
09.08.2007 RTE-VNA First Release.
***********************************************************************************/

/***********************************************************************************
User Includes
***********************************************************************************/
/*	Following header file provides access to intrinsic functions to control interrupt
	levels. */
#include <machine.h>
/*	Following header file provides a structure to access on-chip I/O registers. */
#include "iodefine.h"
/* Following header file provides common defines for widely used items. */
#include "rsk7203def.h"
/* Following header file provides prototypes for SPI related functions. */
#include "spi.h"
/* Following header file provides prototypes for the functions used in this file. */
#include "main_lcd_display.h"

/***********************************************************************************
Function prototypes
***********************************************************************************/
#pragma section FRAME_BUFFER
static unsigned long vfbuffer[XRES*YRES];
#pragma section

/***********************************************************************************
User Program Code
***********************************************************************************/
 
/***********************************************************************************
Function Name : main
Description   :	Configures the TFT LCD.
Parameters    : none
Return value  : none
***********************************************************************************/
void main(void)	
{
	unsigned long  x_data,y_data;
	unsigned short *ptr;

	/* Transfer the image	*/
	ptr = (unsigned short *)__sectop("BFRAME_BUFFER") + (XRES * YRES);
	for(y_data = YRES; y_data > 0; y_data--)
	{
		for (x_data = 0; x_data < XRES; x_data++)
		{
			*ptr = bitmap_data [x_data][y_data]; 
			ptr--;
		}
	}

	tft_lcd_setup();
	
	/* Initialise SH-7203 for SPI bus operation:  
	  NB: this disables use of the debug LCD module.	*/

	/* Configures the SPI */

	while(1)
	{
		/* The TFT LCD displayes the image.	*/
	}
}
/**********************************************************************************
End of function tft_test
***********************************************************************************/   

/**********************************************************************************
Function Name: 	tft_lcd_setup
Description:	Configures the SH7203 on-chip LCD controller
Parameters: 	none
Return value: 	none
***********************************************************************************/
void tft_lcd_setup(void)
{
	/* Power up LCDC display driver */
	CPG.STBCR4.BIT.MSTP41 = 0;

	/* Configure the port pins for LCD control	*/
	PORT.PFCRH2.WORD = 0x2222;
	PORT.PFCRH1.WORD = 0x2222;
	PORT.PFCRL4.WORD = 0x2222;
	PORT.PFCRL3.WORD = 0x2222;
	PORT.PFCRL2.WORD = 0x2222;
	PORT.PFCRL1.WORD = 0x2222;
	
	/* QVGA LCD(240*320) setting */
	LCDC.LDCNTR.WORD = 0x0000;
	
	/* LCD clock source	selected - 8.333 MHz  (Pclk / 4)*/
	LCDC.LDICKR.WORD = (0x0100 | 0x0002);
	
	/* LCD module type - TFT color 16bits */
	LCDC.LDMTR.WORD = 0xc02b;           
	
	/* LCD colour data format - 16 bit */
	LCDC.LDDFR.WORD = 0x002d;
	
	/* Scan mode register - image not rotated */
	LCDC.LDSMR.WORD = 0x0000;
	
	/* LCD start frame buffer for upper display */
	LCDC.LDSARU = (unsigned long)vfbuffer;
	
	/* LCD start frame buffer for lower display */
	LCDC.LDSARL = (unsigned long)vfbuffer;
	
	/* Memory image geometry: number of horizontal bytes (width * 16bits) 
	 (XRES) * bpp / 8
	 XRES - 1 | XRES + 3 	*/
	LCDC.LDLAOR = 1602;//XRES * BPP / 8 + 2; 
	LCDC.LDHCNR.WORD = ((110 << 8) | 112);//(XRES / 8 + 10) << 8 | XRES / 8 + 12;  

	/* Set horizontal sync width and sync position	*/
	LCDC.LDHSYNR.WORD = 0x0064;//0x0028;

	/* Set the Vertical Display Size 
	 YRES - 1 display OK	*/
	LCDC.LDVDLNR = 487;//YRES + 9; 
	/* Set the Total Vertical Line Size
	 YRES - 1	*/
	LCDC.LDVTLNR = 498;//YRES + 20; 
	/* Set the vertical sync width and position	*/
	LCDC.LDVSYNR.WORD =489;//0x014b;  

	/* Configure LCDC AC Modulation Signal Toggle Line Number Register	*/		
	LCDC.LDACLNR = 0x000c;

	/* Start the LCD Controller */
	LCDC.LDCNTR.WORD = 0x0003;
	while ( LCDC.LDPMMR.BIT.LPS != 0x0003 )
	{
	}
}
/**********************************************************************************
End of function tft_lcd_setup
***********************************************************************************/   

/**********************************************************************************
Function Name: 	qvga_lcdreg
Description:	Writes a command to SPI bus
Parameters: 	unsigned char reg - Register to be written
				unsigned char data - data to be written in the register
Return value: 	none
***********************************************************************************/
void qvga_lcdreg(unsigned char reg, unsigned char data)
{
	unsigned short regsel = 0x7000 | reg;
	unsigned short data2  = 0x7200 | (data & 0xff);
	
	spi_write(regsel);
	spi_write(data2);
}
/**********************************************************************************
End of function qvga_lcdreg
***********************************************************************************/   

/**********************************************************************************
Function Name: 	qvga_lcdreg_read
Description:	Reads a command from SPI bus
Parameters: 	unsigned char reg - Register to be read
Return value: 	unsigned short - data read from SPI bus
***********************************************************************************/
unsigned short qvga_lcdreg_read(unsigned char reg)
{
	unsigned short regsel = 0x7000 | reg;
	unsigned short data2  = 0x7300;
	
	spi_write(regsel);

	return spi_write(data2);
}
/**********************************************************************************
End of function qvga_lcdreg_read
***********************************************************************************/   

⌨️ 快捷键说明

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