Main Page | Data Structures | File List | Data Fields | Globals

ATAVRBFLY_FILES/LCD_driver.c

Go to the documentation of this file.
00001 // This file has been prepared for Doxygen automatic documentation generation. 00023 // Include files. 00024 #include"iom169.h" 00025 #include"LCD_driver.h" 00026 #include"types.h" 00027 00028 00029 // Variable from "button.c" to prevent button-bouncing 00030 extern unsigned char gButtonTimeout; 00031 00032 extern BOOL gAutoPressJoystick; 00033 00034 // Used to indicate when the LCD interrupt handler should update the LCD 00035 char gLCD_Update_Required = FALSE; 00036 00037 // LCD display buffer (for double buffering). 00038 char LCD_Data[LCD_REGISTER_COUNT]; 00039 00040 // Buffer that contains the text to be displayed 00041 // Note: Bit 7 indicates that this character is flashing 00042 char gTextBuffer[TEXTBUFFER_SIZE]; 00043 00044 // Only six letters can be shown on the LCD. 00045 // With the gScroll and gScrollMode variables, 00046 // one can select which part of the buffer to show 00047 signed char gScroll; 00048 char gScrollMode; 00049 00051 char gLCD_Start_Scroll_Timer = 0; 00052 00053 // The gFlashTimer is used to determine the on/off 00054 // timing of flashing characters 00055 char gFlashTimer = 0; 00056 00057 // Turns on/off the colons on the LCD 00058 char gColon = 0; 00059 00060 00061 // Look-up table used when converting ASCII to 00062 // LCD display data (segment control) 00063 __flash unsigned int LCD_character_table[] = 00064 { 00065 0x0A51, // '*' (?) 00066 0x2A80, // '+' 00067 0x0000, // ',' (Not defined) 00068 0x0A00, // '-' 00069 0x0A51, // '.' Degree sign 00070 0x0000, // '/' (Not defined) 00071 0x5559, // '0' 00072 0x0118, // '1' 00073 0x1e11, // '2 00074 0x1b11, // '3 00075 0x0b50, // '4 00076 0x1b41, // '5 00077 0x1f41, // '6 00078 0x0111, // '7 00079 0x1f51, // '8 00080 0x1b51, // '9' 00081 0x0000, // ':' (Not defined) 00082 0x0000, // ';' (Not defined) 00083 0x0000, // '<' (Not defined) 00084 0x0000, // '=' (Not defined) 00085 0x0000, // '>' (Not defined) 00086 0x0000, // '?' (Not defined) 00087 0x0000, // '@' (Not defined) 00088 0x0f51, // 'A' (+ 'a') 00089 0x3991, // 'B' (+ 'b') 00090 0x1441, // 'C' (+ 'c') 00091 0x3191, // 'D' (+ 'd') 00092 0x1e41, // 'E' (+ 'e') 00093 0x0e41, // 'F' (+ 'f') 00094 0x1d41, // 'G' (+ 'g') 00095 0x0f50, // 'H' (+ 'h') 00096 0x2080, // 'I' (+ 'i') 00097 0x1510, // 'J' (+ 'j') 00098 0x8648, // 'K' (+ 'k') 00099 0x1440, // 'L' (+ 'l') 00100 0x0578, // 'M' (+ 'm') 00101 0x8570, // 'N' (+ 'n') 00102 0x1551, // 'O' (+ 'o') 00103 0x0e51, // 'P' (+ 'p') 00104 0x9551, // 'Q' (+ 'q') 00105 0x8e51, // 'R' (+ 'r') 00106 0x9021, // 'S' (+ 's') 00107 0x2081, // 'T' (+ 't') 00108 0x1550, // 'U' (+ 'u') 00109 0x4448, // 'V' (+ 'v') 00110 0xc550, // 'W' (+ 'w') 00111 0xc028, // 'X' (+ 'x') 00112 0x2028, // 'Y' (+ 'y') 00113 0x5009, // 'Z' (+ 'z') 00114 0x0000, // '[' (Not defined) 00115 0x0000, // '\' (Not defined) 00116 0x0000, // ']' (Not defined) 00117 0x0000, // '^' (Not defined) 00118 0x0000 // '_' 00119 }; 00120 00121 00122 /***************************************************************************** 00123 * 00124 * Function name : LCD_Init 00125 * 00126 * Returns : None 00127 * 00128 * Parameters : None 00129 * 00130 * Purpose : Initialize LCD_displayData buffer. 00131 * Set up the LCD (timing, contrast, etc.) 00132 * 00133 *****************************************************************************/ 00134 void LCD_Init (void) 00135 { 00136 LCD_AllSegments(FALSE); // Clear segment buffer. 00137 00138 LCD_CONTRAST_LEVEL(LCD_INITIAL_CONTRAST); //Set the LCD contrast level 00139 00140 // Select asynchronous clock source, enable all COM pins and enable all 00141 // segment pins. 00142 LCDCRB = (1<<LCDCS) | (3<<LCDMUX0) | (7<<LCDPM0); 00143 00144 // Set LCD prescaler to give a framerate of 32,0 Hz 00145 LCDFRR = (0<<LCDPS0) | (7<<LCDCD0); 00146 00147 LCDCRA = (1<<LCDEN) | (1<<LCDAB); // Enable LCD and set low power waveform 00148 00149 //Enable LCD start of frame interrupt 00150 LCDCRA |= (1<<LCDIE); 00151 00152 gLCD_Update_Required = FALSE; 00153 00154 00155 } 00156 00157 00158 /***************************************************************************** 00159 * 00160 * Function name : LCD_WriteDigit(char c, char digit) 00161 * 00162 * Returns : None 00163 * 00164 * Parameters : Inputs 00165 * c: The symbol to be displayed in a LCD digit 00166 * digit: In which digit (0-5) the symbol should be displayed 00167 * Note: Digit 0 is the first used digit on the LCD, 00168 * i.e LCD digit 2 00169 * 00170 * Purpose : Stores LCD control data in the LCD_displayData buffer. 00171 * (The LCD_displayData is latched in the LCD_SOF interrupt.) 00172 * 00173 *****************************************************************************/ 00174 void LCD_WriteDigit(char c, char digit) 00175 { 00176 00177 unsigned int seg = 0x0000; // Holds the segment pattern 00178 char mask, nibble; 00179 char *ptr; 00180 char i; 00181 00182 00183 if (digit > 5) // Skip if digit is illegal 00184 return; 00185 00186 //Lookup character table for segmet data 00187 if ((c >= '*') && (c <= 'z')) 00188 { 00189 // c is a letter 00190 if (c >= 'a') // Convert to upper case 00191 c &= ~0x20; // if necessarry 00192 00193 c -= '*'; 00194 00195 seg = LCD_character_table[c]; 00196 } 00197 00198 // Adjust mask according to LCD segment mapping 00199 if (digit & 0x01) 00200 mask = 0x0F; // Digit 1, 3, 5 00201 else 00202 mask = 0xF0; // Digit 0, 2, 4 00203 00204 ptr = LCD_Data + (digit >> 1); // digit = {0,0,1,1,2,2} 00205 00206 for (i = 0; i < 4; i++) 00207 { 00208 nibble = seg & 0x000F; 00209 seg >>= 4; 00210 if (digit & 0x01) 00211 nibble <<= 4; 00212 *ptr = (*ptr & mask) | nibble; 00213 ptr += 5; 00214 } 00215 } 00216 00217 00218 00219 /***************************************************************************** 00220 * 00221 * Function name : LCD_AllSegments(unsigned char input) 00222 * 00223 * Returns : None 00224 * 00225 * Parameters : show - [TRUE;FALSE] 00226 * 00227 * Purpose : shows or hide all all LCD segments on the LCD 00228 * 00229 *****************************************************************************/ 00230 void LCD_AllSegments(char show) 00231 { 00232 unsigned char i; 00233 00234 if (show) 00235 show = 0xFF; 00236 00237 // Set/clear all bits in all LCD registers 00238 for (i=0; i < LCD_REGISTER_COUNT; i++) 00239 *(LCD_Data + i) = show; 00240 } 00241 00242 00243 /***************************************************************************** 00244 * 00245 * LCD Interrupt Routine 00246 * 00247 * Returns : None 00248 * 00249 * Parameters : None 00250 * 00251 * Purpose: Latch the LCD_displayData and Set LCD_status.updateComplete 00252 * 00253 *****************************************************************************/ 00254 #pragma vector = LCD_SOF_vect 00255 __interrupt void LCD_SOF_interrupt(void) 00256 { 00257 static char LCD_timer = LCD_TIMER_SEED; 00258 char c; 00259 char c_flash; 00260 char flash; 00261 00262 char EOL; 00263 unsigned char i; 00264 00265 00266 static char timeout_count; 00267 00268 00269 /**************** Button timeout for the button.c, START ****************/ 00270 if(!gButtonTimeout) 00271 { 00272 timeout_count++; 00273 00274 if(timeout_count > 3) 00275 { 00276 gButtonTimeout = TRUE; 00277 timeout_count = 0; 00278 } 00279 } 00280 /**************** Button timeout for the button.c, END ******************/ 00281 00282 /**************** Auto press joystick for the main.c, START *************/ 00283 /*if(gAutoPressJoystick == AUTO) 00284 { 00285 auto_joystick_count++; 00286 00287 if(auto_joystick_count > 16) 00288 { 00289 gAutoPressJoystick = TRUE; 00290 auto_joystick_count = 15; 00291 } 00292 } 00293 else 00294 auto_joystick_count = 0; 00295 */ 00296 /**************** Auto press joystick for the main.c, END ***************/ 00297 00298 LCD_timer--; // Decreased every LCD frame 00299 00300 if (gScrollMode) 00301 { 00302 // If we are in scroll mode, and the timer has expired, 00303 // we will update the LCD 00304 if (LCD_timer == 0) 00305 { 00306 if (gLCD_Start_Scroll_Timer == 0) 00307 { 00308 gLCD_Update_Required = TRUE; 00309 } 00310 else 00311 gLCD_Start_Scroll_Timer--; 00312 } 00313 } 00314 else 00315 { // if not scrolling, 00316 // disble LCD start of frame interrupt 00317 // cbi(LCDCRA, LCDIE); //DEBUG 00318 gScroll = 0; 00319 } 00320 00321 00322 EOL = FALSE; 00323 if (gLCD_Update_Required == TRUE) 00324 { 00325 // Duty cycle of flashing characters 00326 if (gFlashTimer < (LCD_FLASH_SEED >> 1)) 00327 flash = 0; 00328 else 00329 flash = 1; 00330 00331 // Repeat for the six LCD characters 00332 for (i = 0; i < 6; i++) 00333 { 00334 if ((gScroll+i) >= 0 && (!EOL)) 00335 { 00336 // We have some visible characters 00337 c = gTextBuffer[i + gScroll]; 00338 c_flash = c & 0x80 ? 1 : 0; 00339 c = c & 0x7F; 00340 00341 if (c == '\0') 00342 EOL = i+1; // End of character data 00343 } 00344 else 00345 c = ' '; 00346 00347 // Check if this character is flashing 00348 00349 if (c_flash && flash) 00350 LCD_WriteDigit(' ', i); 00351 else 00352 LCD_WriteDigit(c, i); 00353 } 00354 00355 // Copy the segment buffer to the real segments 00356 for (i = 0; i < LCD_REGISTER_COUNT; i++) 00357 *(pLCDREG + i) = *(LCD_Data+i); 00358 00359 // Handle colon 00360 if (gColon) 00361 *(pLCDREG + 8) = 0x01; 00362 else 00363 *(pLCDREG + 8) = 0x00; 00364 00365 // If the text scrolled off the display, 00366 // we have to start over again. 00367 if (EOL == 1) 00368 gScroll = -6; 00369 else 00370 gScroll++; 00371 00372 // No need to update anymore 00373 gLCD_Update_Required = FALSE; 00374 } 00375 00376 00377 // LCD_timer is used when scrolling text 00378 if (LCD_timer == 0) 00379 { 00380 /* if ((gScroll <= 0) || EOL) 00381 LCD_timer = LCD_TIMER_SEED/2; 00382 else*/ 00383 LCD_timer = LCD_TIMER_SEED; 00384 } 00385 00386 // gFlashTimer is used when flashing characters 00387 if (gFlashTimer == LCD_FLASH_SEED) 00388 gFlashTimer= 0; 00389 else 00390 gFlashTimer++; 00391 00392 }

Generated on Tue Nov 1 16:21:39 2005 for AVR323 Interfacing GSM modems by doxygen 1.3.7