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

📄 ssd1289x16.c

📁 avr LCM SSD1289 color Graphical LCD Display Driver and graphic library
💻 C
📖 第 1 页 / 共 2 页
字号:
/***********************************************************************************************
*	  			  SSD1289 color Graphical LCD Display Driver
* File name		: SSD1289x16.h
* Programmer 	: jaruwit supa
* Web presence  : www.thaibestlink.com
* Note			: SSD1289 16 bit interface
* Language		: avrGCC
* Hardware		: atmega16
* Date			: 01/05/2009
*************************************************************************************************
* DESCRIPTION
* ===========
* Display controller chip is ssd1289
* 16-bit data bus mode 8080
************************************************************************************************/

/* _____STANDARD INCLUDES____________________________________________________ */
#include <avr/io.h>    
#include <avr/pgmspace.h>    

/* _____PROJECT INCLUDES_____________________________________________________ */
#include "SSD1289x16.h"

/* _____LOCAL VARIABLES______________________________________________________ */
uint16_t _color = WHITE;

/* _____PRIVATE FUNCTIONS____________________________________________________ */

/******************************************************************************************************** 
* Function    : void LCD_WaitMs(unsigned int ms)
* Description : waits (pauses) for ms milliseconds (assumes internal clock at 8MHz)
* Input       : ms is wait milliseconds
* Returns     : none 
* Notes		  : none
*********************************************************************************************************/ 
void LCD_WaitMs(unsigned int ms)
{
	int i;

	while (ms-- > 0)
	{
		/* 8192 (8k) clock cycles for 1ms; each time through loop
		   is 5 cycles (for loop control + nop) */
		for (i = 0; i < 1638; ++i)
			asm volatile ("nop");
	}
}
                              
/******************************************************************************************************** 
* Function    : void LCD_WrCmd(unsigned char cmd) 
* Description : This function performs low level command write to LCD 
* Input       : cmd - is the command written to the LCD module 
* Returns     : none 
* Notes		  : Hardware specific. 
*********************************************************************************************************/ 
void LCD_WrCmd(unsigned char cmd) 
{ 
    LCD_CLR_CS();	// clear CS pin to ENABLE LCD

	LCD_CLR_RS();
	LCD_SET_DBL = cmd;
	LCD_SET_DBH = (cmd >> 8);
	LCD_CLR_WR();
	LCD_SET_WR();

    LCD_SET_CS();	// set CS pin to DISABLE LCD
} 

/******************************************************************************************************** 
* Function    : void LCD_WrDat(unsigned int val) 
* Description : This function performs low level display data write to LCD 
* Arguments   : val - is the data written to the LCD module 
* Returns     : none 
* Notes		  : Hardware specific. 
********************************************************************************************************/ 
void LCD_WrDat(unsigned int val) 
{ 
    LCD_CLR_CS();				// clear CS pin to ENABLE LCD 

	LCD_SET_RS();
	LCD_SET_DBL = val;
	LCD_SET_DBH = (val>>8);
	LCD_CLR_WR();
	LCD_SET_WR();

    LCD_SET_CS();	// set CS pin to DISABLE LCD 
} 
/*********************************************************************************************************
* Function:  void LCD_SetReg(unsigned char index, unsigned int val)
* Input       : index - register number
*             : val   - value to be set
* Returns     : none
* Notes		  : Hardware specific. 
**********************************************************************************************************/
void LCD_SetReg(unsigned char index, unsigned int val)
{
	LCD_WrCmd(index);
	LCD_WrDat(val);
}

/*********************************************************************************************************
* Function    : unsigned int LCD_GetReg(unsigned char index)
* Description : This function performs low level read data register from LCD 
* Input:      : index - register number
* Return      : register data
* Notes		  : none
**********************************************************************************************************/
unsigned int LCD_GetReg(unsigned char index)
{
	unsigned int ret;

    LCD_CLR_CS();	// clear  CS pin to ENABLE LCD 

	LCD_CLR_RS();
	LCD_SET_DBL = index;
	LCD_SET_DBH = (index >> 8);
	LCD_CLR_WR();
	LCD_SET_WR();

	LCD_INPUT();				// input mode
	LCD_CLR_RD();
	asm volatile ("nop");
	ret = LCD_GET_DBH();
	ret <<= 8;
	ret |= LCD_GET_DBL();
	LCD_SET_RD();
    LCD_SET_CS();	// set CS pin to DISABLE LCD 

	LCD_OUTPUT();				// output data
	return ret;	
}

/*********************************************************************************************************
* Function    : void LCD_InitPort(void)
* Description : This function init lcd io
* Input       : none
* Returns     : none
* Notes		  : none
**********************************************************************************************************/
void LCD_InitPort(void)
{
	LCD_SET_DBH = 0xFF;
	LCD_SET_DBL = 0xFF;
	LCD_OUTPUT();

	// set default
	LCD_SET_CS();
	LCD_SET_RS();
	LCD_SET_WR();
	LCD_SET_RD();

	LCD_CLR_RST();

	// init direction
	LCD_DIR_CS(1);
	LCD_DIR_RS(1);
	LCD_DIR_WR(1);
	LCD_DIR_RD(1);
	LCD_DIR_RST(1);

	// reset module
	LCD_WaitMs(20);
	LCD_SET_RST();
	LCD_WaitMs(20);
}

/* _____PUBLIC FUNCTIONS_____________________________________________________ */

/*********************************************************************************************************
* Function    : void LCD_Reset(void)
* Description : This function reset lcd module
* Input:      : none
* Returns     : none
* Notes		  : none
**********************************************************************************************************/
void LCD_Reset(void)
{
	unsigned int driver_code;
	LCD_InitPort();

	driver_code = LCD_GetReg(0x00);
	LCD_LO_DDR = 0xFF;
	LCD_HI_DDR = 0xFF;

	LCD_LO_PORT = driver_code;
	LCD_HI_PORT = driver_code>>8;
	while(1);

	LCD_WrCmd(0x0000);LCD_WrDat(0x0001); //Start Oscillation OSCEN=1
	LCD_WaitMs(15);
	LCD_WrCmd(0x0003);LCD_WrDat(0xAAAC); //Power Control (1)
	LCD_WrCmd(0x000C);LCD_WrDat(0x0002); //Power Control (2)
	LCD_WrCmd(0x000D);LCD_WrDat(0x000A); //Power Control (3)
	LCD_WrCmd(0x000E);LCD_WrDat(0x2C00); //Power Control (4)
	LCD_WrCmd(0x001E);LCD_WrDat(0x00B8); //Power Control (5)
	LCD_WaitMs(15);
	LCD_WrCmd(0x0001);LCD_WrDat(0x2B3F); //Driver Output Control RL=0, REV=1, BGR=1, TB=1 
//		LCD_WrCmd(0x0001);LCD_WrDat(0x6B3F); //Driver Output Control RL=1, REV=1, BGR=1, TB=1 
	LCD_WrCmd(0x0002);LCD_WrDat(0x0600);
	// Restore VSYNC mode from low power state 
	LCD_WrCmd(0x0010);LCD_WrDat(0x0000); //Sleep mode cancel
	LCD_WrCmd(0x0011);LCD_WrDat(0x6030); //Entry Mode
										// DFM   0x4000 = 262L color
										// DFM   0x6000 = 65K color
										// AM    0x0000 = horizontal display
										// AM    0x0008 = Vertical display
										// ID[0] 0x0000 = horizontal decrement
										// ID[0] 0x0010 = horizontal increment
										// ID[1] 0x0000 = Vertical decrement
										// ID[1] 0x0020 = Vertical decrement

	LCD_WaitMs(20);
	LCD_WrCmd(0x0005);LCD_WrDat(0x0000); // Compare register
	LCD_WrCmd(0x0006);LCD_WrDat(0x0000); // Compare register
	// Horizontal and Vertical porch are for DOTCLK mode operation
	LCD_WrCmd(0x0016);LCD_WrDat(0xEF1C); // Horizontal Porch 
	LCD_WrCmd(0x0017);LCD_WrDat(0x0003); // Vertical Porch
	// Display Control
	LCD_WrCmd(0x0007);LCD_WrDat(0x0233); // Display Control
										 // D1 0x0000 = display off

⌨️ 快捷键说明

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