📄 lcd_functions.c
字号:
//*****************************************************************************
//
// File........: LCD_functions.c
//
// Author(s)...: ATMEL Norway
//
// Target(s)...: ATmega169
//
// Compiler....: IAR EWAAVR 2.27b
//
// Description.: Additional LCD functions, scrolling text and write data
//
// Revisions...: 1.0
//
// YYYYMMDD - VER. - COMMENT - SIGN.
//
// 20021015 - 1.0 - Created - LHM
//
//*****************************************************************************
// Include files
#include "Main.h"
#include "Lcd_functions.h"
#include "Lcd_driver.h"
// Extern global variables
// From LCD_driver.c
extern unsigned char LCD_displayData[];
// From UART.c
extern unsigned char TransmitBuffer[50];
// From Buttons.c
extern unsigned char LCD_Menu1;
extern unsigned char LCD_Menu2;
extern unsigned char LCD_Menu3;
// Local global variables
unsigned char String_cnt; // used as a counter to keep track of which characters to display on the LCD when scrolling a string
unsigned char Clear_cnt; // used as a counter when the LCD shall "fade" out after a scrolling string
unsigned char *String; // pointer to the string that is to be displayed on the LCD
unsigned char NumberOfScroll; // variable that holds the number of times a string should be scrolled on the LCD
unsigned char Colon = FALSE; // variable to indicate whether to set or clear the colons
// table used in the "void LCDsetupData(void)" to load a string to be displayed on the LCD
unsigned char *String_Table[6] = {"Clock", "Date", "Setpoint", "Temperature", "Offset", "Contrast"};
// table used in the "void LCDwriteData(void)" to set up which digits on the LCD to blink
__flash unsigned char BlinkTable[3][6] =
// Digit2 Digit3 Digit4 Digit5 Digit6 Digit7
// ----------------------------------------------
{{ 1, 1, 0, 0, 0, 0 },
{ 0, 0, 1, 1, 0, 0 },
{ 0, 0, 0, 0, 1, 1 }};
// table used in the "void LCDwriteData(void)" to set up the rigth values from the transmit buffer
__flash unsigned char DataTable[5][6] =
// Menu Digit2 Digit3 Digit4 Digit5 Digit6 Digit7
// ----------------------------------------------
// CLOCK HOUR HOUR MINUTE MINUTE SECOND SECOND
{{ 7, 8, 10, 11, 13, 14 },
// TEMPERATURE DAY DAY MONTH MONTH YEAR_LO YEAR_LO
{ 16, 17, 19, 20, 25, 26 },
// SET POINT space space SETPO. SETPO. --- ---
{ 6, 6, 28, 29, 0, 0 },
// TEMPERATURE TEMP_LO TEMP_LO TEMP_HI TEMP_HI --- ---
{ 31, 32, 34, 35, 0, 0 },
// OFFSET space --- OFFSET OFFSET --- ---
{ 6, 0, 37, 38, 0, 0 }};
/******************************************************************************************
*
* Function name : LCD_update
*
* Returns : None
*
* Parameters : None
*
* Purpose : Checks if the LCD is ready for new data
*
******************************************************************************************/
void LCD_update(void)
{
if( LCD_status.updateComplete ) // if the LCD is ready for new data
{
if( NumberOfScroll ) //if there is a text to be scrolled
{
LCD_status.updateRequired = FALSE; // block LCD updating while updating the LCD_displaydata
LCD_AllSegments(FALSE); // disable all segments
LCDscrollMsg(); // call the scroll function
LCD_status.updateComplete = FALSE; // indicate that new data are not presented on the LCD
LCD_status.updateRequired = TRUE; // enable LCD_displayData to be lacthed to the LCD data Regs
}
else //else write the data from the Transmit Buffer
{
if( LCD_Menu1-1 < 5 ) // if not the CONTRAST is to be displayed
{
LCD_status.updateRequired = FALSE; // block LCD updating while updating the LCD_displaydata
LCD_SET_COLON(Colon); // set/clear colons depending on the varibale Colon (TRUE/FALSE)
LCDwriteData(); // call the write data funciton
LCD_status.updateComplete = FALSE; // indicate that new data are not presented on the LCD
LCD_status.updateRequired = TRUE; // enable LCD_displayData to be lacthed to the LCD data Regs
}
else // else set all the segments
LCD_AllSegments(TRUE);
}
}
}
/******************************************************************************************
*
* Function name : LCDwriteData
*
* Returns : None
*
* Parameters : None
*
* Purpose : Writes date from the Transmit Buffer to the LCD_displayData
*
******************************************************************************************/
void LCDwriteData(void)
{
unsigned char LCD_digit_cnt = 8; // counter to LCD Segments
if( ( LCD_Menu1 > 2 ) && ( LCD_Menu1 < 6 ) ) // if Set Point, Temperature or Offset is to be displayed
{ // set the "degree Celsius".
LCD_WriteDigit( 'C' , 7 ); // write ".C" to the last digits
LCD_WriteDigit( '.' , 6 );
LCD_digit_cnt = 6; // decrease the number of digits to write
}
while( LCD_digit_cnt > 2 ) // while there are number of digits left to wrtie
{
LCD_digit_cnt--; // decrease the number of digits to write
if( LCD_Menu1 > 3 ) // if displaying the temperature or offset
LCD_status.blinkLCD = FALSE; // turn off the possibility to blink
if( LCD_status.blinkLCD && ( LCD_Menu1 == 3 ) && LCD_Menu2 ) // if the Set Point is displayed and Menu2 is active
{
LCD_WriteDigit( ' ', LCD_digit_cnt ); // blink all the digits when Menu2 and LCD_status.blinkLCd is active
}
else if( LCD_status.blinkLCD && ( BlinkTable[LCD_Menu2-1][LCD_digit_cnt - 2] ) && LCD_Menu2) // if LCD_status.blinkLCd and Menu2 is active
{
LCD_WriteDigit( ' ', LCD_digit_cnt ); // blink the digit that is to be written according to BlinkTable[]
}
else
{
if( !(DataTable[LCD_Menu1-1][LCD_digit_cnt - 2]) ) // if the DataTable contains 0
{
if(TCCR1A & 0x80) // check the TCCR1A register to find out if the Heater or Cooler pin is active
LCD_WriteDigit( '-' , LCD_digit_cnt ); // if the Heater pin is active, write '-'
else
LCD_WriteDigit( '+' , LCD_digit_cnt ); // if the Cooler pin is active, write '+'
}
else // write data from the transmitbuffer
LCD_WriteDigit( TransmitBuffer[DataTable[LCD_Menu1-1][LCD_digit_cnt - 2]] , LCD_digit_cnt );
}
}
}
/******************************************************************************************
*
* Function name : LCDsetupData
*
* Returns : None
*
* Parameters : None
*
* Purpose : Set up the text to be displayed (if any)
*
******************************************************************************************/
void LCDsetupData(void)
{
if( !LCD_Menu1 ) // if LCD_Menu1 is not active
{
String_cnt = 0; // set String_cnt to point a the first character
String = "STK502 example application for ATmega169";
NumberOfScroll = 0xFF; // enable infnite scrolling
}
else if( !LCD_Menu2 ) // if LCD_Menu2 is not active
{
NumberOfScroll = 1; // scroll the new text only once
String = String_Table[LCD_Menu1-1]; // load the new text to be scrolled
String_cnt = 0; // set String_cnt to point a the first character
Colon = TRUE; // enable the colons
if( LCD_Menu1 == 3 | LCD_Menu1 == 5 ) // if displaying the Set point or the offset
Colon = FALSE;
}
else if( !LCD_Menu3 ) // if LCD_Menu3 is not active
{
Colon = TRUE; // enable the colons
}
else // if LCD_Menu3 is active
{
Colon = FALSE; // disable the colons
}
}
/******************************************************************************************
*
* Function name : LCDscrollMsg
*
* Returns : None
*
* Parameters : None
*
* Purpose : Make a text-string scroll over the LCD-display. The text-string will
* scroll one step to the left each time this funciton is executed.
*
******************************************************************************************/
void LCDscrollMsg(void)
{
unsigned char LCD_digit_cnt; // keeps track of which of the six LCD-digits to write
unsigned char Temp; // local storage for the global String_cnt
if(*(String + String_cnt)) // until the string ends
{
LCD_digit_cnt = 8; // start with writing to the last digit
Temp = String_cnt; // store the global String_cnt to the local Temp
while(LCD_digit_cnt > 2) // while the all digits on LCD has been written once
{
LCD_digit_cnt--; // decrease the digit counter
if(Temp != 0xFF) // if the Temp is not 0xFF, not end of the string
LCD_WriteDigit(*(String + Temp--), LCD_digit_cnt); //write a character and decrease the Temp
else // else it is the end of the string
LCD_WriteDigit( ' ', LCD_digit_cnt ); // fill the digit with a ASCII-space
}
String_cnt++; // increment the global string counter
Clear_cnt = (String_cnt + 6); // set the
}
else if(Clear_cnt - String_cnt) // else when the whole string has been displayed, make the string fade out
{ // by filling the display with ASCII-space ' '(0x20)
Clear_cnt--; // decrease number of characters left to fade out
LCD_digit_cnt = 8;
Temp = 1;
while(LCD_digit_cnt > 2) // while the all digits on LCD has been written once
{
LCD_digit_cnt--; // decrease the digit counter
if( (LCD_digit_cnt - 2) >= (Clear_cnt - String_cnt)) // if the digit counter is greater or equal to the number characters that are cleared (' ') minus
{ // the number of characters left in the string
LCD_WriteDigit( ' ' , LCD_digit_cnt ); // write a ASCII-space this LCD-digit
}
else
{
LCD_WriteDigit( *(String + (String_cnt - Temp)) , LCD_digit_cnt ); // write the remaining charaters in the string
Temp++; // increment the temporary string counter
}
}
}
else // when the whole string has been scrolled one time
{
String_cnt = 0; // clear the global string counter
if(NumberOfScroll != 0xFF) // if not infinite scrolling is enabled
NumberOfScroll--; // drecrease the number of times to scroll the string
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -