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

📄 hdc1600.c

📁 HDC1600 LCD driver interfacing withPIC18f4550 src-draw picture,circle
💻 C
📖 第 1 页 / 共 2 页
字号:
*********************************************************************************************************
*/
void cDispSwitch(BOOLEAN sw)
{
	(sw==ENABLE)? cDispWrCmd(DISPLAY_ON):cDispWrCmd(DISPLAY_OFF);
}

/*
*********************************************************************************************************
*                         	CLEAR DISPLAY BY WRITING PURE COLOR TO THE WHOLE SCREEN
*
* Description : This function writes a fixed int to all pixels making use of the automatic
*				address increment feature for X and Y address counters
*				
* Arguments   : 'color' is in 16-bit, [R4R3R2R1R0][G5G4G3G2G1G0][B4B3B2B1B0] 
*						Writing color=0xFFFF equivalent to white color
*						color=0x0000 eq. black
*						color=0xF800 eq. red
*						color=0x07E0 eq. green
*						color=0x001F eq. blue
*				
* Returns     : none
*********************************************************************************************************
*/
void cDispClr(INT16U color)
{
	INT8U x,y,hiByte,lowByte;

	hiByte  = color>>8;
	lowByte = (INT8U)color;

		for(x=0;x<MAX_ROW_PIXEL;x++)
		{
			for(y=0;y<MAX_COL_PIXEL;y++)
			{
			cDispWrDat(hiByte);
			cDispWrDat(lowByte);
			}
		}
}


/*
*********************************************************************************************************
*                         				SET PIXEL AT x, y POSITION
*
* Description : This function sets a pixel with (INT16U)color at a position defined by (x,y) following 
*				Cartesian coordinate system. Coordinates (0,0) at the top left corner, 
*				coordinates (127,159) at the lower right corner of the LCD screen, w/ module viewed from
*				frontal up direction on PIC18LF-4550-STK1 Rev3b with LCD controller HDC1600
*
* Arguments   : 'x'    		0....MAX_COL_PIXEL-1 is the matrix position in x-axis (left ->right)
*				'y'    		0....MAX_ROW_PIXEL-1 is the matrix position in y-axis (up -> down)
*				'color'  	sets 16-bit color
* Returns     : none
* Notes		  : Should apply the local function cDispRstArea() to reset display area 128*160
*********************************************************************************************************
*/
void cDispSetPixel(INT8U x, INT8U y, INT16U color)
{
	INT8U hiByte, lowByte;
	x = MAX_COL_PIXEL-1-x;
	y = MAX_ROW_PIXEL-1-y;

	hiByte  = color>>8;
	lowByte = (INT8U)color;

	cDispWrCmd(X_ADDRESS_AREA_SET);		//X-address area set in the 160 pixel direction (y-axis)
	cDispWrCmd(y);						//offset for scan COM from 0~159
	cDispWrCmd(y++);
	cDispWrCmd(Y_ADDRESS_AREA_SET);		//Y-address area set in the 128 pixel direction (x-axis)
	cDispWrCmd(x);						//offset for scan SEG from 0~127
	cDispWrCmd(x++);

	cDispWrDat(hiByte);
	cDispWrDat(lowByte);	

	cDispRstArea();
}

/*
*********************************************************************************************************
*               		CONVERT A STRING FROM ROM TO PIXEL DATA AND DISPLAY AT x,y
*
* Description : This function outputs a string in graphic mode (pixel-by-pixel) at a position defined 
*				by (x,y) following Cartesian coordinate system with variable font spacing defined by 
*				fontSpace. Character wrapping is allowed. String from ROM so const rom keyword used
*				*** REQUIRE AT LEAST ONE FONT SET (sysfont.h) included under this file ****
*				Cartesian coordinates as (0,0) at the top left hand corner, (127,159) at the 
*				lower right hand corner, as seen from frontal up view of the PIC18-LF4550-STK1 board
*
* Arguments   : 'x'    		0....MAX_COL_PIXEL-1 is matrix position in horizontal direction (x-axis).
*							
*				'y'    		0....MAX_ROW_PIXEL-1 is matrix position in vertical direction (y-axis).
*
*				'*pStr'		pointer to an ASCII string in ROM (flash), null terminated
*				'fontSpace' font spacing from 1 to 127
*				'color'		16-bit color possible
* Returns     : none
* Notes		  : Microchip C18 complier dependent as const rom keyword involved.
* Example 	  : ....
*				....
*				main()
*				{ 
*					cDispPixStrAt(0,20,"Hello!",1,RGB(31,0,0)); 	//Display the ASCII string "Hello!"
*																	//at (x,y)=(0,20), font space = 1
*																	//color in red
*				}
*********************************************************************************************************
*/
void cDisprStrAt(INT8U x, INT8U y, const rom char *pStr, INT8U fontSpace, INT16U color)
{
	INT8U pixelByte,bit_idx, i;				//loop counters 
	INT8U c,fwidth, fheight;				//character, font width & height store

	while (*pStr)
	{
		c = *pStr++ - 32;
				
		fwidth = SYS_FNT[c].fontWidth;
		fheight = 8;

		if((x+fwidth)>MAX_COL_PIXEL) 		//character wrapping here				
		{
			x=0;
			y+=fheight;
		}

		if((y+fheight)>MAX_ROW_PIXEL)		//check for y boundary				
		{
			y=0;
		}

		for(i=0;i<fheight;i++)
		{
			pixelByte = SYS_FNT[c].fontBody[i];
			for(bit_idx=0; bit_idx<fwidth; bit_idx++)
				{
						if((pixelByte)&(0x80>>bit_idx))
							cDispSetPixel(x+bit_idx, y+i, color);
				}
		}
		
		x = x+fwidth+fontSpace;
	}	

	cDispRstArea();							//reset the display area for 128*160 after DispSetPixel()
}

/*
*********************************************************************************************************
*                 CONVERT A STRING FROM DATA MEMORY (RAM) TO PIXEL DATA AND DISPLAY AT x,y
*
* Description : This function outputs a string in RAM in graphic mode (pixel-by-pixel) at a position
*				(x,y) following Cartesian coordinate system with variable font spacing def by fontSpace.
*				Character wrapping is allowed.
*				*** REQUIRE AT LEAST ONE FONT SET (sysfont.h) included under this file ****
*				Cartesian coordinates as (0,0) at the top left hand corner, (127,159) at the 
*				lower right hand corner, as seen from frontal up view of the PIC18-LF4550-STK1 board
*
* Arguments   : 'x'    		0....MAX_COL_PIXEL-1 is matrix position in horizontal direction (x-axis).
*							
*				'y'    		0....MAX_ROW_PIXEL-1 is matrix position in vertical direction (y-axis).
*
*				'*pStr'		pointer to an ASCII string in RAM, null terminated
*				'fontSpace' font spacing from 1 to 127
*				'color'		16-bit color possible
* Returns     : none
* Notes		  : 
* Example 	  : ....
*				char s[20];
*				main() 
*				{ 
*					cDispPixStrAt(0,20,s,1,RGB(31,0,0)); 	//Display the ASCII string in s[20]
*															//at (x,y)=(0,20), font space = 1
*															//color in red
*				}
*********************************************************************************************************
*/
void cDispStrAt(INT8U x, INT8U y, char *pStr, INT8U fontSpace, INT16U color)
{
	INT8U pixelByte,bit_idx, i;				//loop counters 
	INT8U c,fwidth, fheight;				//character, font width & height store

	while (*pStr)
	{
		c = *pStr++ - 32;
				
		fwidth = SYS_FNT[c].fontWidth;
		fheight = 8;

		if((x+fwidth)>MAX_COL_PIXEL) 		//character wrapping here				
		{
			x=0;
			y+=fheight;
		}

		if((y+fheight)>MAX_ROW_PIXEL)		//check for y boundary				
		{
			y=0;
		}

		for(i=0;i<fheight;i++)
		{
			pixelByte = SYS_FNT[c].fontBody[i];
			for(bit_idx=0; bit_idx<fwidth; bit_idx++)
				{
						if((pixelByte)&(0x80>>bit_idx))
							cDispSetPixel(x+bit_idx, y+i, color);
				}
		}
		
		x = x+fwidth+fontSpace;
	}	

	cDispRstArea();							//reset the display area for 128*160 after DispSetPixel()
}

/*
*********************************************************************************************************
*                         				WRITE A PATTERN AT X, Y COORDINATES
*
* Description : This function writes a particular pattern of size patWidth and patHeight at a position 
*				defined by (x,y) following Cartesian coordinate system. 
*				Pattern defined in ROM (flash)
*				Cartesian coordinates as (0,0) at the top left hand corner, (127,159) at the 
*				lower right hand corner, as seen from frontal up view of the PIC18-LF4550-STK1 board
* Arguments   : 'x'    		0....MAX_COL_PIXEL-1 is matrix position in horizontal direction (x-axis)
*				'y'    		0....MAX_ROW_PIXEL-1 is matrix position in vertical direction (y-axis)
*				'*pPat'		pointer to pattern structure in const rom (FLASH)
*				'color'  	color in 16-bit mode
* Returns     :	none
* Notes		  : Microchip C18 complier dependent as const rom keyword involved
*********************************************************************************************************
*/
void cDisprPatAt(INT8U x, INT8U y, const rom INT16U *pPat)
{
 	INT16U   col, row, pWidth, pHeight, pixel;

	pWidth  = pPat[0];
	pHeight = pPat[1];

	for(row=0;row<pHeight;row++)
		{	
			for(col=0;col<pWidth;col++)
			{
				pixel = pPat[col+row*pWidth+2];
				cDispSetPixel(col+x,row+y,pixel);
			}
		}	
	cDispRstArea();							//reset the display area for 128*160 after DispSetPixel()
}

/*
*********************************************************************************************************
*                  		ADJUST BRIGHTNESS & CONSTRAST IN NORMAL DISPLAY MODE
*
* Description : This function updates the brightness & contrast control value in normal display mode
* Arguments   : (INT8U) 'brightness'	0...255
*				(INT8U) 'contrast'  	0...63
* Returns     :	none
* Notes		  : 
*********************************************************************************************************
*/
void cDispSetQuali(INT8U brightness, INT8U contrast)
{
	//brightness control in normal display mode
	cDispWrCmd(CONTRAST_CONTROL1);	
	cDispWrCmd(brightness);
	//contrast control in normal display mode	
	cDispWrCmd(CONTRAST_CONTROL3);	
	cDispWrCmd(contrast);
		
}

/*
*********************************************************************************************************
*                         			LOW LEVEL PORT INITIALIZATION
*
* Description : This function performs low level port initialization
* Arguments   : none
* Returns     : none
* Notes		  : Hardware specific
*********************************************************************************************************
*/
void cDispInitPort(void)
{	
	cDISP_CS		= HIGH;			//de-select the color LCD to start with
	cDISP_A0		= HIGH;
	cDISP_WR		= HIGH;
	cDISP_RD		= HIGH;
	cDISP_DATA		= 0x00;
	cDISP_BL		= HIGH;			//backlight = OFF to start

	TRIS_cDISP_CS 	= OUTPUT;
	TRIS_cDISP_A0	= OUTPUT;
	TRIS_cDISP_WR	= OUTPUT;
	TRIS_cDISP_RD	= OUTPUT;
	TRIS_cDISP_DATA	= OUTPUT;
	TRIS_cDISP_BL	= OUTPUT;
}

/*
*********************************************************************************************************
*                         				LOW LEVEL COMMAND WRITE TO LCD
*
* Description : This function performs low level command write to LCD
* Arguments   : (INT8U) 'cmd' 	is the command written to the LCD module
* Returns     : none
* Notes		  : Hardware specific. Delay required for individual Fosc
*********************************************************************************************************
*/
void cDispWrCmd(INT8U cmd)
{
	cDISP_A0 	= LOW;			//A0 LOW for command
	cDISP_CS 	= LOW;	
	cDISP_DATA 	= cmd;	
	cDISP_WR 	= LOW;
	cDISP_WR 	= HIGH;															
	cDISP_CS 	= HIGH;
}
/*
*********************************************************************************************************
*                         				LOW LEVEL DATA WRITE TO LCD
*
* Description : This function performs low level display data write to LCD
* Arguments   : (INT8U) 'dat' 	is the data written to the LCD module
* Returns     : none
* Notes		  : Hardware specific. Delay required for individual Fosc
*********************************************************************************************************
*/
void cDispWrDat(INT8U dat)
{
	cDISP_A0 	= HIGH;		//A0 HIGH for data
	cDISP_CS 	= LOW;	
	cDISP_DATA 	= dat;	
	cDISP_WR 	= LOW;
	cDISP_WR 	= HIGH;															
	cDISP_CS 	= HIGH;
}

/*
*********************************************************************************************************
*                         					cDispBackLite
*
* Description : This function control the LCD backlight ENABLE -OR- DISABLE
* Arguments   : 'BOOLEAN' ctrl 		ENABLE 	for backlight ON
*									DISABLE	for backlight OFF
*			
* Returns     : none
* Notes		  : Hardware specific.
*********************************************************************************************************
*/
void cDispBackLite(BOOLEAN ctrl)
{
	(ctrl==ENABLE)?(cDISP_BL=LOW):(cDISP_BL=HIGH);
}



⌨️ 快捷键说明

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