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

📄 ssd1289x16.c

📁 avr LCM SSD1289 color Graphical LCD Display Driver and graphic library
💻 C
📖 第 1 页 / 共 2 页
字号:
										 // D1 0x0002 = display on
										 // D0 0x0000 = internal display halt
										 // D0 0x0001 = internal display operate


	LCD_WrCmd(0x000B);LCD_WrDat(0x5312); // Frame cycle control
	LCD_WrCmd(0x000F);LCD_WrDat(0x0000); // Gate Scan Position 
	LCD_WaitMs(20);
	// Vertical Scroll Control
	LCD_WrCmd(0x0041);LCD_WrDat(0x0000); // Vertical Scroll Control
	LCD_WrCmd(0x0042);LCD_WrDat(0x0000); // Vertical Scroll Control

	// 1st Screen driving position
	LCD_WrCmd(0x0048);LCD_WrDat(0x0000); // Start position. 0
	LCD_WrCmd(0x0049);LCD_WrDat(0x013F); // End position.   319

	// Source RAM address
	LCD_WrCmd(0x0044);LCD_WrDat(0xEF00); //Horizontal RAM address position start/end setup 
										 //dec 239 
										 //dec 0, i.e. horizontal ranges from 0 -> 239 
										 //POR value is 0xEF00 anyway. This address must be set before RAM write 

	LCD_WrCmd(0x0045);LCD_WrDat(0x0000); //Vertical RAM address start position setting 
										 //0x0000 = dec 0
	LCD_WrCmd(0x0046);LCD_WrDat(0x013F); //Vertical RAM address end position setting (0x013F = dec 319)

		// 2nd Screen driving position
//		LCD_WrCmd(0x004A);LCD_WrDat(0x0000); // Start position. 0
//		LCD_WrCmd(0x004B);LCD_WrDat(0x0000); // End position.   0
	LCD_WaitMs(20); 
	//gamma control 
	LCD_WrCmd(0x0030);LCD_WrDat(0x0707);
	LCD_WrCmd(0x0031);LCD_WrDat(0x0704);
	LCD_WrCmd(0x0032);LCD_WrDat(0x0204);
	LCD_WrCmd(0x0033);LCD_WrDat(0x0201);
	LCD_WrCmd(0x0034);LCD_WrDat(0x0203);
	LCD_WrCmd(0x0035);LCD_WrDat(0x0204);
	LCD_WrCmd(0x0036);LCD_WrDat(0x0204);
	LCD_WrCmd(0x0037);LCD_WrDat(0x0502);
	LCD_WrCmd(0x003A);LCD_WrDat(0x0302);
	LCD_WrCmd(0x003B);LCD_WrDat(0x0500);

	LCD_WaitMs(20);
}    

/*********************************************************************
* Function    : void LCD_SetCursor(unsigned int x, unsigned int y)
* Description : set start address of lcd ram
* Input       : x,y - pixel coordinates
* Return      : none
* Note        : set start address change
********************************************************************/
void LCD_SetCursor(unsigned int x, unsigned int y)
{
#ifdef Horizontal
	LCD_SetReg(0x4E,x); // initial settings for the GDDRAM X address in the address counter (AC).
	LCD_SetReg(0x4F,y); // initial settings for the GDDRAM Y address in the address counter (AC).
#else
	LCD_SetReg(0x4E,y); // initial settings for the GDDRAM X address in the address counter (AC).
	LCD_SetReg(0x4F,x); // initial settings for the GDDRAM Y address in the address counter (AC).
#endif
    LCD_WrCmd(0x22); 
}

/*********************************************************************
* Function    : void LCD_SetArea(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2)
* Description : set paint area
* Input       : x1,y1,x2,y2 - pixel coordinates
* Return      : none
* Note        : Side Effects: paint area change
********************************************************************/
void LCD_SetArea(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2)
{
#ifdef Horizontal
    LCD_WrCmd(0x44); LCD_WrDat((x2 << 8) | x1);    // Source RAM address window 
    LCD_WrCmd(0x45); LCD_WrDat(y1);    // Gate RAM address window 
    LCD_WrCmd(0x46); LCD_WrDat(y2);    // Gate RAM address window 
#else
    LCD_WrCmd(0x44); LCD_WrDat((y2 << 8) | y1);    // Source RAM address window 
    LCD_WrCmd(0x45); LCD_WrDat(x1);    // Gate RAM address window 
    LCD_WrCmd(0x46); LCD_WrDat(x2);    // Gate RAM address window 
#endif
	LCD_SetCursor(x1, y1);;
}

/*********************************************************************
* Function    : void LCD_PutPixel(unsigned int x, unsigned int y)
* Description : puts pixel
* Input       : x,y - pixel coordinates
* Output      : none
* Note        : none
********************************************************************/
void LCD_PutPixel(unsigned int x, unsigned int y)
{
    LCD_SetCursor(x,y);
	LCD_WrDat(_color);
}

/*********************************************************************
* Function    : void LCD_Bar(unsigned int left, unsigned int top, unsigned int right, unsigned int bottom)
* Description : draws rectangle filled with current color
* Input       : left,top - top left corner coordinates,
*             : right,bottom - bottom right corner coordinates
* Output      : none
* Note        :
*  CGRAM map
*  00000...000EF line0
*  00100...001EF line1
*  00200...002EF line2 
*	....
*  13F00...13FEF line320
*  yyyxx...yyyxx
*  address x = x
*  address y = y << 8
*  new line y = y + 0x100
********************************************************************/
void LCD_Bar(unsigned int left, unsigned int top, unsigned int right, unsigned int bottom, unsigned int color)
{
	register unsigned int x,y;

	LCD_SetArea(left, top, right, bottom);
    for(y=top; y<=bottom; y++)
	{
        for(x=left; x<=right; x++)
		{
			LCD_WrDat(color);
        }
    }
	LCD_SetArea(0, 0, GetMaxX(), GetMaxY());
}

/*********************************************************************
* Function    : void LCD_Clear(unsigned int color)
* Description : fill display with color
* Input       : color - paint color
* Output      : none
* Note        : none
********************************************************************/
void LCD_Clear(unsigned int color)
{
//	LCD_WrCmd(0x0007);LCD_WrDat(0x0221); // Display Control: display off
	LCD_Bar(0, 0, GetMaxX(), GetMaxY(), color);
//	LCD_WrCmd(0x0007);LCD_WrDat(0x0233); // Display Control: display on
}

/*********************************************************************
* Function    : void DrawSymbol(unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned char t, unsigned char *pImage)
* Description : display image array to lcd
* Input       : x,y    - pixel coordinates
*             : w      - width 
*             : h      - height
*             : t      - compress type(0 = none(RGB565), 1 = compress(RGB5<compress bit>55)
*			  : pImage - FLASH array of image
* Output      : none
* Note        : none
********************************************************************/
void LCD_DrawSymbol(unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned char t, const unsigned char *pImage)
{
	unsigned char colorMsb;
	unsigned char colorLsb;
	unsigned char colorDup = 0;
	unsigned int color=0;
	unsigned int x1,y1;

	// set draw area
	LCD_SetArea(x,y,x+w-1,y+h-1);
	for (y1 = 0; y1<h ; y1++)
	{
		for (x1 = 0; x1<w ; x1++)
		{
			if (!colorDup)
			{
				colorMsb = pgm_read_byte(pImage++);
				colorLsb = pgm_read_byte(pImage++);
				if (t == 0x01)
				{
					colorDup = colorLsb & 0x20;			// get duplicate flag
					colorLsb = colorLsb | 0x20;			// remove duplicate flag and add more white
				}
				if (colorDup)
					colorDup = pgm_read_byte(pImage++);	// get duplicate no
				color = ((uint16_t)colorMsb << 8) | colorLsb;		// merge color
				SetColor(color);						// set a pixel
			}
			else
			{
				colorDup--;
			}
			LCD_WrDat(color);
		}
	}
	LCD_SetArea(0, 0, GetMaxX(), GetMaxY());
}

/*********************************************************************
* Function    : void DrawImage(unsigned int x, unsigned int y, unsigned char *pImage)
* Description : display image array to lcd
* Input       : x,y    - pixel coordinates
*			  : pImage - FLASH array of image
* Output      : none
* Note        : ** modify image format here **
*   image format
*   <type 1 byte><width 2 byte><height 2 btye><image array n byte>
********************************************************************/
void LCD_DrawImage(unsigned int x, unsigned int y, const unsigned char *pImage)
{
	unsigned char t;
	unsigned int w, h;

	// get image information
	t = pgm_read_byte(pImage++);			// image type
	w = pgm_read_byte(pImage++);			// width
	w = (w << 8) | pgm_read_byte(pImage++);
	h = pgm_read_byte(pImage++);			// Height
	h = (h << 8) | pgm_read_byte(pImage++);

	LCD_DrawSymbol(x, y, w, h, t, pImage);
}

⌨️ 快捷键说明

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