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

📄 dog_glcd.c

📁 silicon wireless开发套件F920+Si4432原理图,源码
💻 C
字号:
/*
** ============================================================================
**
** FILE
**  dog_lcd.c
**
** DESCRIPTION
**  Main file for controlling the DOG LCD thorugh SPI interface.
**
** CREATED
**  Silicon Laboratories Hungary Ltd
**
** COPYRIGHT
**  Copyright 2008 Silicon Laboratories, Inc.  
**	http://www.silabs.com
**
** ============================================================================
*/

/*------------------------------------------------------------------------*/
/*						INCLUDE											  */
/*------------------------------------------------------------------------*/
#include "dog_glcd.h"



/*------------------------------------------------------------------------*/
/*						GLOBAL variables								  */
/*------------------------------------------------------------------------*/
extern code uint8 ascii_table5x7[][5];

idata uint8 CurrentLine, CurrentChPos, CurrentPage, CurrentColumn;
idata uint8 lcd_data[22];

#define LCD_BACKLIGHT_IS_USED


/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  +
  + FUNCTION NAME:  void LcdDelay_2ms(void)
  +
  + DESCRIPTION:    wait about 20ms, it uses only a for cycle
  +
  + RETURN:         None
  +
  + NOTES:          the delay depends on the clock of the MCU
  +
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void LcdDelay_2ms(void)
{
	UU16 Delay;

	Delay.U16 = 1400;
	StartTmr3(DELAY_2MS_DIV, Delay, FALSE);
	while( Tmr3Expired() == FALSE );
}

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  +
  + FUNCTION NAME:  void LcdInit(void)
  +
  + DESCRIPTION:    Initialize the LCD for 3.3V operation voltage and SPI comm.
  +
  + RETURN:         None
  +
  + NOTES:          it can be called only 40ms later than the VDD stabilized
  +
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void LcdInit(void)
{
	#ifdef LCD_BACKLIGHT_IS_USED
	 LCD_BL_PIN 	= 1;
	#endif
	LCD_NSEL_PIN 	= 1;
	LCD_A0_PIN 		= 0;
	//perform reset
	LCD_RESET_PIN 	= 0;
	LcdDelay_2ms();
	LCD_RESET_PIN 	= 1;
	LcdDelay_2ms();
	LcdDelay_2ms();
	LcdDelay_2ms();


	LCD_NSEL_PIN = 0;
	SpiWrite(0x40);			//display start line 0
	SpiWrite(0xA1);			//ADC reverse
	SpiWrite(0xC0);			//normal COM0~COM63
	SpiWrite(0xA6);			//display normal
	SpiWrite(0xA2);			//set bias 1/9 (Duty 1/65)
	SpiWrite(0x2F);			//booster, regulator and follower on
	SpiWrite(0xF8);			//set internal bosster to 4x
	SpiWrite(0x00);			
	SpiWrite(0x27);			//contrast set
	SpiWrite(0x81);			
	SpiWrite(0x16);			
	SpiWrite(0xAC);			//no indicator
	SpiWrite(0x00);			
	LCD_NSEL_PIN = 1;
	LcdOff();
	LcdClearDisplay();
	LcdOn();
}

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  +
  + FUNCTION NAME:  void LcdOn(void)
  +
  + DESCRIPTION:    turns on the LCD screen
  +
  + RETURN:         None
  +
  + NOTES:         
  +
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void LcdOn(void)
{
	LCD_NSEL_PIN = 0;
	SpiWrite( 0xAF );			
	LCD_NSEL_PIN = 1;	
}

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  +
  + FUNCTION NAME:  void LcdOff(void)
  +
  + DESCRIPTION:    turns off the LCD screen (the DDRAM content will be kept)
  +
  + RETURN:         None
  +
  + NOTES:         
  +
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void LcdOff(void)
{
	LCD_NSEL_PIN = 0;
	SpiWrite( 0xAE );			
	LCD_NSEL_PIN = 1;	
}

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  +
  + FUNCTION NAME:  void LcdSetPage(uint8 data_in)
  +
  + DESCRIPTION:    it sets the page address (0...7)
  +
  + INPUT:			page address (the LCD is separated to 8x8 rows
  +					and 8 row is calles as a page)
  +					page0 is the top 8 rows
  +
  + RETURN:         None
  +
  + NOTES:         
  +
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void LcdSetPage(uint8 data_in)
{
	LCD_NSEL_PIN = 0;
	SpiWrite( 0xB0 | data_in );			
	LCD_NSEL_PIN = 1;	
}

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  +
  + FUNCTION NAME:  void LcdSetColumn(uint8 data_in)
  +
  + DESCRIPTION:    it sets the column address (0...127)
  +
  + INPUT:			address of the column
  +
  + RETURN:         None
  +
  + NOTES:         
  +
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void LcdSetColumn(uint8 data_in)
{
	LCD_NSEL_PIN = 0;
	SpiWrite( 0x10 | ((data_in & 0x70) >> 4) );			
	SpiWrite( 0x00 | (data_in & 0x0F) );			
	LCD_NSEL_PIN = 1;	
}

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  +
  + FUNCTION NAME:  void LcdClearDisplay(void)
  +
  + DESCRIPTION:    it clears the display (the content of the DDRAM!)
  +
  + INPUT:			None
  +
  + RETURN:         None
  +
  + NOTES:         
  +
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void LcdClearDisplay(void)
{
	uint8 page;

	for(page=1;page<9;page++)
	{
		LcdClearLine(page);
	}	
}

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  +
  + FUNCTION NAME:  void LcdClearLine(uint8 page)
  +
  + DESCRIPTION:    it clears one line on the LCD
  +
  + INPUT:			None
  +
  + RETURN:         None
  +
  + NOTES:         
  +
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void LcdClearLine(uint8 line)
{
	uint8 column;

	if( (line < LCD_MIN_LINE) || (line > LCD_MAX_LINE) )
	{
		return;
	}
	//select the page
	LcdSetPage(line-1);
	//set to the first column
	LcdSetColumn(0);
	//set A0 to 1 -> access to the DDRAM
	LCD_A0_PIN 	 = 1;
	LCD_NSEL_PIN = 0;
	for(column=0;column<128;column++)
	{
		//clear the selected column
		SpiWrite(0x00);
	}
	LCD_A0_PIN 	 = 0;
	LCD_NSEL_PIN = 1;
}

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  +
  + FUNCTION NAME:  void LcdSetCharCursor(uint8 line, uint8 ch_pos)
  +
  + DESCRIPTION:    it sets the character position
  +
  + INPUT:			line   - number of the line (1...8
  +							 the LCD is divided to 8 lines
  +						     line1 is the top line
  +					ch_pos - character position
  +							 up to 21 character (1...21) could be in a line	
  +							 character 1 is the first on left hand side
  +
  + RETURN:         TRUE   - operation was successfull
  +					FALSE  - operation was ignored
  +
  + NOTES:          If the position is invalid, the function returns without
  +					changing the registers.
  +					The function sets the CurrentLine, CurrentChPos variables!
  +
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
uint8 LcdSetCharCursor(uint8 line, uint8 ch_pos)
{
	//check whether the line and ch_pos valid or not
	if( ((line < LCD_MIN_LINE) || (line > LCD_MAX_LINE)) || ((ch_pos < LCD_MIN_CHAR) || (ch_pos > LCD_MAX_CHAR)) ) 
	{
		return FALSE;
	}

	//set page address
	LcdSetPage(line-1);
	//set column address
	LcdSetColumn( ((ch_pos-1)*6) );
	CurrentLine = line;
	CurrentChPos = ch_pos;

	return TRUE;
}


/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  +
  + FUNCTION NAME:  void LcdPutInvCh(uint8 ch)
  +
  + DESCRIPTION:    it writes one character INVERTED to the next position
  +
  + INPUT:			ch	   - the character needs to be writen
  +
  + RETURN:         None
  +
  + NOTES:          if the position is invalid (the line is full) it writes 
  +					the character from the begining of the line.
  +					The function increments the CurrentChPos variable!
  +					If the character invalid, it prints a space char.
  +
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void LcdPutInvCh(uint8 ch)
{
	uint8 column, data_out, temp8;
	
	if( (ch > ASCII_5X7_MAX) || (ch < ASCII_5X7_MIN) )
	{
		data_out = ' ';
	}
	else
	{
		data_out = ch;
	}

	//write character
	LCD_A0_PIN 	 = 1;			//set A0 to 1 -> access to the DDRAM
	LCD_NSEL_PIN = 0;
	for(column=0;column<5;column++)
	{
		//write column data
		temp8 = ascii_table5x7[data_out - ASCII_5X7_MIN][column];
		temp8 ^= 0xFF;
		temp8 &= 0x7F;
		SpiWrite( temp8 );
	}
	//space between the characters
	SpiWrite(0x7F);
	LCD_A0_PIN 	 = 0;
	LCD_NSEL_PIN = 1;
	if(	++CurrentChPos > LCD_MAX_CHAR )
	{//end of the line -> set cursor to the beginning of the line
		CurrentChPos = 1;
		LcdSetColumn( 1 );
	}	
}

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  +
  + FUNCTION NAME:  void LcdPutChar(uint8 line, uint8 ch_pos, uint8 ch)
  +
  + DESCRIPTION:    it writes one character to the next position
  +
  + INPUT:			ch	   - the character needs to be writen
  +
  + RETURN:         None
  +
  + NOTES:          if the position is invalid (the line is full) it writes 
  +					the character from the begining of the line.
  +					The function increments the CurrentChPos variable!
  +					If the character invalid, it prints a space char.
  +
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void LcdPutCh(uint8 ch)
{
	uint8 column, data_out;
	
	if( (ch > ASCII_5X7_MAX) || (ch < ASCII_5X7_MIN) )
	{
		data_out = ' ';
	}
	else
	{
		data_out = ch;
	}

	//write character
	LCD_A0_PIN 	 = 1;			//set A0 to 1 -> access to the DDRAM
	LCD_NSEL_PIN = 0;
	for(column=0;column<5;column++)
	{
		//write column data
		SpiWrite(ascii_table5x7[data_out - ASCII_5X7_MIN][column]);
	}
	//space between the characters
	SpiWrite(0);
	LCD_A0_PIN 	 = 0;
	LCD_NSEL_PIN = 1;
	if(	++CurrentChPos > LCD_MAX_CHAR )
	{//end of the line -> set cursor to the beginning of the line
		CurrentChPos = 1;
		LcdSetColumn( 1 );
	}	
}

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  +
  + FUNCTION NAME:  void LcdPutChar(uint8 line, uint8 ch_pos, uint8 ch)
  +
  + DESCRIPTION:    it write one character to the requested position
  +
  + INPUT:			line   - number of the line (1...8
  +							 the LCD is divided to 8 lines
  +						     line1 is the top line
  +					ch_pos - character position
  +							 up to 21 character (1...21) could be in a line	
  +							 character 1 is the first on left hand side
  +                 ch	   - the character needs to be writen
  +
  + RETURN:         None
  +
  + NOTES:          If the position is invalid, the function returns without
  +					changing the registers.
  +					The function sets the CurrentLine, CurrentChPos variables!
  +
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void LcdPutChar(uint8 line, uint8 ch_pos, uint8 ch)
{
	if( LcdSetCharCursor(line, ch_pos) == FALSE )
	{
		return;
	}
	LcdPutCh(ch);
}

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  +
  + FUNCTION NAME:  void LcdWriteLine(uint8 line, uint8 * text)
  +
  + DESCRIPTION:    it writes one complete line
  +
  + INPUT:			line   - number of the line (1...8
  +							 the LCD is divided to 8 lines
  +						     line1 is the top line
  +					text   - address of the string needs to be written
  +
  + RETURN:         None
  +
  + NOTES:          If the line is invalid, the function returns without any changes.
  +					The function doesn't set the CurrentLine, CurrentChPos variables!
  +
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void LcdWriteLine(uint8 line, uint8 * text)
{
	uint8 i,column,temp8;

	if( (line < LCD_MIN_LINE) || (line > LCD_MAX_LINE) )
	{
		return;
	}
	//set page address
	LcdSetPage( line-1 );
	//set column address
	LcdSetColumn( 0 );
	for(i=0;i<21;i++)	
	{
		if( (text[i] > ASCII_5X7_MAX) || (text[i] < ASCII_5X7_MIN) )
		{
			temp8 = ' ';
		}
		else
		{
			temp8 = text[i];
		}

		;
		//write character
		LCD_A0_PIN 	 = 1;			//set A0 to 1 -> access to the DDRAM
		LCD_NSEL_PIN = 0;
		for(column=0;column<5;column++)
		{
			//write column data
			SpiWrite(ascii_table5x7[temp8 - ASCII_5X7_MIN][column]);
		}
		//space between the characters
		SpiWrite(0);
		LCD_A0_PIN 	 = 0;
		LCD_NSEL_PIN = 1;
	}	
}

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  +
  + FUNCTION NAME:  uint8 LcdSetPictureCursor(uint8 page, uint8 column)
  +
  + DESCRIPTION:    it sets the character position
  +
  + INPUT:			page   - number of the pages (1...8
  +							 the LCD is divided to 8 pages
  +						     page1 is the top page
  +					column - number of start column
  +							 column1 is the left one
  +
  + RETURN:         TRUE   - operation was successfull
  +					FALSE  - operation was ignored
  +
  + NOTES:          If the position is invalid, the function returns without
  +					changing the registers.
  +					The function sets the CurrentLine, CurrentChPos variables!
  +
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
uint8 LcdSetPictureCursor(uint8 page, uint8 column)
{
	//check whether the input parameters are correct or not
	if( ((page < LCD_MIN_LINE) || (page > LCD_MAX_LINE)) || ((column < LCD_MIN_COLUMN) || (column > LCD_MAX_COLUMN)) ) 
	{
		return FALSE;
	}

	//set page address
	LcdSetPage(page-1);
	//set column address
	LcdSetColumn( column-1 );
	CurrentPage = page;
	CurrentColumn = column;

	return TRUE;
}

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  +
  + FUNCTION NAME:  void LcdDrawPicture(const uint8 * picture)
  +
  + DESCRIPTION:    it draw a picture
  +
  + INPUT:			picture - address of the picture (must be stored in the 
  +							  FLASH
  +
  + RETURN:         None
  +
  + NOTES:          The uint8 LcdSetPictureCursor(uint8 page, uint8 column) function
  +					has to be called before calling this function!
  +					The function changes the CurrentPage and CurrentColumn variables!
  +
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void LcdDrawPicture(const  * picture)
{
uint8 p,pages,page,i,col;
uint16 j;

	p = picture[LCD_PIC_PAGE_NMBR];
	//check wheter there are enough column for the picture or not
	if( (LCD_MAX_COLUMN - CurrentColumn + 1) < picture[LCD_PIC_COLUMN_NMBR] )
	{//there are not enough space for the pic -> limit to the available space
		col = (LCD_MAX_COLUMN - CurrentColumn + 1);
	}
	else
	{
		col = picture[LCD_PIC_COLUMN_NMBR];
	}
	//check wheter there are enough pages for the picture or not
	if( (LCD_MAX_LINE - CurrentPage + 1) < picture[LCD_PIC_PAGE_NMBR] )
	{
		page = (LCD_MAX_LINE - CurrentPage + 1);
	}
	else
	{
		page = picture[LCD_PIC_PAGE_NMBR];
	}

	//draw the picture
	for(pages=0;pages<page;pages++)
	{
		LCD_A0_PIN 	 = 1;			//set A0 to 1 -> access to the DDRAM
		LCD_NSEL_PIN = 0;
		j = LCD_PIC_ADDRESS_OFFSET + pages;
		for(i=0;i<col;i++)
		{
			//write column data
			SpiWrite( picture[j] );
			j += p;
		}
		LCD_A0_PIN 	 = 0;
		LCD_NSEL_PIN = 1;
		//set next page
		LcdSetPictureCursor( ++CurrentPage,CurrentColumn );
	}
}

⌨️ 快捷键说明

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