00001 /* This file has been prepared for Doxygen automatic documentation generation.*/ 00024 // Include files 00025 #include "Main.h" 00026 #include "Lcd_functions.h" 00027 #include "Lcd_driver.h" 00028 00029 // Extern global variables 00030 // From LCD_driver.c 00031 extern unsigned char LCD_displayData[]; 00032 // From UART.c 00033 extern unsigned char TransmitBuffer[50]; 00034 // From Buttons.c 00035 extern unsigned char LCD_Menu1; 00036 extern unsigned char LCD_Menu2; 00037 extern unsigned char LCD_Menu3; 00038 00039 // Local global variables 00040 unsigned char String_cnt; // used as a counter to keep track of which characters to display on the LCD when scrolling a string 00041 unsigned char Clear_cnt; // used as a counter when the LCD shall "fade" out after a scrolling string 00042 unsigned char *String; // pointer to the string that is to be displayed on the LCD 00043 unsigned char NumberOfScroll; // variable that holds the number of times a string should be scrolled on the LCD 00044 unsigned char Colon = FALSE; // variable to indicate whether to set or clear the colons 00045 00046 // table used in the "void LCDsetupData(void)" to load a string to be displayed on the LCD 00047 unsigned char *String_Table[6] = {"Clock", "Date", "Setpoint", "Temperature", "Offset", "Contrast"}; 00048 00049 // table used in the "void LCDwriteData(void)" to set up which digits on the LCD to blink 00050 __flash unsigned char BlinkTable[3][6] = 00051 // Digit2 Digit3 Digit4 Digit5 Digit6 Digit7 00052 // ---------------------------------------------- 00053 {{ 1, 1, 0, 0, 0, 0 }, 00054 { 0, 0, 1, 1, 0, 0 }, 00055 { 0, 0, 0, 0, 1, 1 }}; 00056 00057 // table used in the "void LCDwriteData(void)" to set up the rigth values from the transmit buffer 00058 __flash unsigned char DataTable[5][6] = 00059 // Menu Digit2 Digit3 Digit4 Digit5 Digit6 Digit7 00060 // ---------------------------------------------- 00061 // CLOCK HOUR HOUR MINUTE MINUTE SECOND SECOND 00062 {{ 7, 8, 10, 11, 13, 14 }, 00063 // TEMPERATURE DAY DAY MONTH MONTH YEAR_LO YEAR_LO 00064 { 16, 17, 19, 20, 25, 26 }, 00065 // SET POINT space space SETPO. SETPO. --- --- 00066 { 6, 6, 28, 29, 0, 0 }, 00067 // TEMPERATURE TEMP_LO TEMP_LO TEMP_HI TEMP_HI --- --- 00068 { 31, 32, 34, 35, 0, 0 }, 00069 // OFFSET space --- OFFSET OFFSET --- --- 00070 { 6, 0, 37, 38, 0, 0 }}; 00071 00072 00075 void LCD_update(void) 00076 { 00077 if( LCD_status.updateComplete ) // if the LCD is ready for new data 00078 { 00079 if( NumberOfScroll ) //if there is a text to be scrolled 00080 { 00081 LCD_status.updateRequired = FALSE; // block LCD updating while updating the LCD_displaydata 00082 LCD_AllSegments(FALSE); // disable all segments 00083 LCDscrollMsg(); // call the scroll function 00084 LCD_status.updateComplete = FALSE; // indicate that new data are not presented on the LCD 00085 LCD_status.updateRequired = TRUE; // enable LCD_displayData to be lacthed to the LCD data Regs 00086 } 00087 else //else write the data from the Transmit Buffer 00088 { 00089 if( LCD_Menu1-1 < 5 ) // if not the CONTRAST is to be displayed 00090 { 00091 LCD_status.updateRequired = FALSE; // block LCD updating while updating the LCD_displaydata 00092 LCD_SET_COLON(Colon); // set/clear colons depending on the varibale Colon (TRUE/FALSE) 00093 LCDwriteData(); // call the write data funciton 00094 LCD_status.updateComplete = FALSE; // indicate that new data are not presented on the LCD 00095 LCD_status.updateRequired = TRUE; // enable LCD_displayData to be lacthed to the LCD data Regs 00096 } 00097 else // else set all the segments 00098 LCD_AllSegments(TRUE); 00099 } 00100 } 00101 } 00102 00103 00106 void LCDwriteData(void) 00107 { 00108 unsigned char LCD_digit_cnt = 8; // counter to LCD Segments 00109 00110 if( ( LCD_Menu1 > 2 ) && ( LCD_Menu1 < 6 ) ) // if Set Point, Temperature or Offset is to be displayed 00111 { // set the "degree Celsius". 00112 LCD_WriteDigit( 'C' , 7 ); // write ".C" to the last digits 00113 LCD_WriteDigit( '.' , 6 ); 00114 00115 LCD_digit_cnt = 6; // decrease the number of digits to write 00116 } 00117 00118 while( LCD_digit_cnt > 2 ) // while there are number of digits left to wrtie 00119 { 00120 LCD_digit_cnt--; // decrease the number of digits to write 00121 00122 if( LCD_Menu1 > 3 ) // if displaying the temperature or offset 00123 LCD_status.blinkLCD = FALSE; // turn off the possibility to blink 00124 00125 if( LCD_status.blinkLCD && ( LCD_Menu1 == 3 ) && LCD_Menu2 ) // if the Set Point is displayed and Menu2 is active 00126 { 00127 LCD_WriteDigit( ' ', LCD_digit_cnt ); // blink all the digits when Menu2 and LCD_status.blinkLCd is active 00128 } 00129 else if( LCD_status.blinkLCD && ( BlinkTable[LCD_Menu2-1][LCD_digit_cnt - 2] ) && LCD_Menu2) // if LCD_status.blinkLCd and Menu2 is active 00130 { 00131 LCD_WriteDigit( ' ', LCD_digit_cnt ); // blink the digit that is to be written according to BlinkTable[] 00132 } 00133 else 00134 { 00135 if( !(DataTable[LCD_Menu1-1][LCD_digit_cnt - 2]) ) // if the DataTable contains 0 00136 { 00137 if(TCCR1A & 0x80) // check the TCCR1A register to find out if the Heater or Cooler pin is active 00138 LCD_WriteDigit( '-' , LCD_digit_cnt ); // if the Heater pin is active, write '-' 00139 else 00140 LCD_WriteDigit( '+' , LCD_digit_cnt ); // if the Cooler pin is active, write '+' 00141 } 00142 else // write data from the transmitbuffer 00143 LCD_WriteDigit( TransmitBuffer[DataTable[LCD_Menu1-1][LCD_digit_cnt - 2]] , LCD_digit_cnt ); 00144 } 00145 } 00146 } 00147 00148 00151 void LCDsetupData(void) 00152 { 00153 if( !LCD_Menu1 ) // if LCD_Menu1 is not active 00154 { 00155 String_cnt = 0; // set String_cnt to point a the first character 00156 String = "STK502 example application for ATmega169"; 00157 NumberOfScroll = 0xFF; // enable infnite scrolling 00158 } 00159 else if( !LCD_Menu2 ) // if LCD_Menu2 is not active 00160 { 00161 NumberOfScroll = 1; // scroll the new text only once 00162 String = String_Table[LCD_Menu1-1]; // load the new text to be scrolled 00163 String_cnt = 0; // set String_cnt to point a the first character 00164 Colon = TRUE; // enable the colons 00165 00166 if( LCD_Menu1 == 3 | LCD_Menu1 == 5 ) // if displaying the Set point or the offset 00167 Colon = FALSE; 00168 } 00169 else if( !LCD_Menu3 ) // if LCD_Menu3 is not active 00170 { 00171 Colon = TRUE; // enable the colons 00172 } 00173 else // if LCD_Menu3 is active 00174 { 00175 Colon = FALSE; // disable the colons 00176 } 00177 } 00178 00179 00183 void LCDscrollMsg(void) 00184 { 00185 unsigned char LCD_digit_cnt; // keeps track of which of the six LCD-digits to write 00186 unsigned char Temp; // local storage for the global String_cnt 00187 00188 if(*(String + String_cnt)) // until the string ends 00189 { 00190 LCD_digit_cnt = 8; // start with writing to the last digit 00191 00192 Temp = String_cnt; // store the global String_cnt to the local Temp 00193 00194 while(LCD_digit_cnt > 2) // while the all digits on LCD has been written once 00195 { 00196 LCD_digit_cnt--; // decrease the digit counter 00197 00198 if(Temp != 0xFF) // if the Temp is not 0xFF, not end of the string 00199 LCD_WriteDigit(*(String + Temp--), LCD_digit_cnt); //write a character and decrease the Temp 00200 else // else it is the end of the string 00201 LCD_WriteDigit( ' ', LCD_digit_cnt ); // fill the digit with a ASCII-space 00202 } 00203 String_cnt++; // increment the global string counter 00204 Clear_cnt = (String_cnt + 6); // set the 00205 } 00206 else if(Clear_cnt - String_cnt) // else when the whole string has been displayed, make the string fade out 00207 { // by filling the display with ASCII-space ' '(0x20) 00208 Clear_cnt--; // decrease number of characters left to fade out 00209 00210 LCD_digit_cnt = 8; 00211 Temp = 1; 00212 00213 while(LCD_digit_cnt > 2) // while the all digits on LCD has been written once 00214 { 00215 LCD_digit_cnt--; // decrease the digit counter 00216 00217 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 00218 { // the number of characters left in the string 00219 LCD_WriteDigit( ' ' , LCD_digit_cnt ); // write a ASCII-space this LCD-digit 00220 } 00221 else 00222 { 00223 LCD_WriteDigit( *(String + (String_cnt - Temp)) , LCD_digit_cnt ); // write the remaining charaters in the string 00224 Temp++; // increment the temporary string counter 00225 } 00226 } 00227 } 00228 else // when the whole string has been scrolled one time 00229 { 00230 String_cnt = 0; // clear the global string counter 00231 00232 if(NumberOfScroll != 0xFF) // if not infinite scrolling is enabled 00233 NumberOfScroll--; // drecrease the number of times to scroll the string 00234 } 00235 }
1.4.5