LCD_driver.c

Go to the documentation of this file.
00001 /* This file has been prepared for Doxygen automatic documentation generation.*/
00024 // Include files.
00025 #include "Main.h"
00026 #include "LCD_driver.h"
00027 
00028 
00029 union _LCD_status LCD_status = {0x01};    //LCD_status = {0, 0, 0, 0, 0, 0, FALSE, TRUE};
00030 unsigned char LCD_timer = LCD_TIMER_SEED;
00031 
00032 unsigned char LCD_displayData[LCD_REGISTER_COUNT];              // LCD display buffer (for double buffering).
00033 
00034 // Look-up table used when converting ASCII to LCD display data (segment control)
00035 __flash unsigned int LCD_character_table[] = // Character definitions table.
00036 {
00037         0x0A51,         // '*' (?)
00038         0x2A80,         // '+'
00039         0x0000,         // ',' (Not defined)
00040         0x0A00,         // '-'
00041         0x0A51,         // '.' Used in the Application Note AVR064, to write "degree" in the display
00042         0x0000,         // '/' (Not defined)
00043         0x5559,         // '0'
00044         0x0118,         // '1'
00045         0x1e11,
00046         0x1b11,
00047         0x0b50,
00048         0x1b41,
00049         0x1f41,
00050         0x0111,
00051         0x1f51,
00052         0x1b51,         // '9'
00053         0x0000,         // ':' (Not defined)
00054         0x0000,         // ';' (Not defined)
00055         0x0000,         // '<' (Not defined)
00056         0x0000,         // '=' (Not defined)
00057         0x0000,         // '>' (Not defined)
00058         0x0000,         // '?' (Not defined)
00059         0x0000,         // '@' (Not defined)
00060         0x0f51,         // 'A' (+ 'a')
00061         0x3991,         // 'B' (+ 'b')
00062         0x1441,         // 'C' (+ 'c')
00063         0x3191,         // 'D' (+ 'd')
00064         0x1e41,
00065         0x0e41,
00066         0x1d41,
00067         0x0f50,
00068         0x2080,
00069         0x1510,
00070         0x8648,
00071         0x1440,
00072         0x0578,
00073         0x8570,
00074         0x1551,
00075         0x0e51,
00076         0x9551,
00077         0x8e51,
00078         0x9021,
00079         0x2081,
00080         0x1550,
00081         0x4448,
00082         0xc550,
00083         0xc028,
00084         0x2028,         // 'Y' (+ 'y')
00085         0x5009,         // 'Z' (+ 'z')
00086         0x0000,         // '[' (Not defined)
00087         0x0000,         // '\' (Not defined)
00088         0x0000,         // ']' (Not defined)
00089         0x0000,         // '^' (Not defined)
00090         0x0000          // '_' (Not defined)
00091 };
00092 
00093 
00096 void LCD_Init (void)
00097 {
00098         LCD_AllSegments( FALSE );       // Clear segment buffer.
00099         LCDCRA = (1<<LCDEN);            // Enable LCD.
00100 
00101     LCD_CONTRAST_LEVEL(LCD_INITIAL_CONTRAST);    //Set the LCD contrast level
00102 
00103         // Select asynchronous clock source, enable all COM pins and enable all segment pins.
00104         LCDCRB = (1<<LCDCS) | (1<<LCDMUX1) | (1<<LCDMUX0) | (1<<LCDPM2) | (1<<LCDPM1)| (1<<LCDPM0);
00105         LCDFRR = (1<<LCDPS0);                       // Set LCD prescaler to CLK(lcd)/64 = 64Hz.
00106 
00107         LCDCRA |= (1<<LCDIE);                       //Enable LCD_Start_frame interrupt
00108 }
00109 
00110 
00116 void LCD_WriteDigit( unsigned char c, unsigned char digit )
00117 {
00118 
00119         unsigned int seg;
00120         unsigned char i;
00121         unsigned char mask, nibble;
00122         unsigned char *ptr;
00123 
00124         //Lookup character table for segmet data
00125         seg = 0x0000;
00126         if ( (c >= '*') && (c <= 'z') )
00127         {
00128                 // c is in character_table.
00129                 // Convert to upper if necessarry.
00130                 if ( c >= 'a' ) c &= ~0x20;
00131                 c -= '*';
00132                 seg = LCD_character_table[c];
00133         }
00134 
00135         // Adjust mask according to digit
00136         mask = 0x0F;            // (1), 3, 5, 7
00137         if ( digit & 0x01 )
00138         {
00139         }
00140         else
00141         {
00142                 mask = 0xF0;            // (0), 2, 4, 6
00143         }
00144 
00145         i = digit-2;
00146         if ( i >= 6 )
00147                 return;
00148         i >>= 1;
00149         ptr = LCD_displayData + i;              // i = {0,0,1,1,2,2}
00150 
00151         i = 4;
00152         do
00153         {
00154                 nibble = seg & 0x000F;
00155                 seg >>= 4;
00156                 if ( digit & 0x01 )
00157                         nibble <<= 4;
00158                 *ptr = (*ptr & mask) | nibble;
00159                 ptr += 5;
00160         } while ( --i );
00161 }
00162 
00163 
00167 void LCD_AllSegments( unsigned char input )
00168 {
00169         unsigned char i;
00170         unsigned char *ptr;
00171 
00172         if( input )                                 // if input == TRUE
00173                 input = 0xFF;                   // set setgemts to 0xFF
00174                                                                 // (else set segments to 0x00)
00175         
00176         ptr = LCD_displayData;
00177         i = 20;
00178         do                                                      // Set all LCD segment register to the variable Segments
00179         {
00180                 *ptr++ = input;         // Set/clear the bits in all LCD registers
00181         } while ( --i );
00182 }
00183 
00184 
00187 #pragma vector = LCD_SOF_vect
00188 __interrupt void LCD_SOF_interrupt( void )
00189 {
00190         unsigned char i;
00191         unsigned char *src, *dest;
00192 
00193         LCD_timer--;
00194         if( LCD_timer == 0 )    // if time out
00195         {
00196             if( LCD_status.updateRequired == TRUE )
00197                 {
00198                         LCD_timer = LCD_TIMER_SEED;         // Reload the LCD_timer
00199                         LCD_status.updateComplete = TRUE;       // Set the LCD_ScrollReady to true.
00200                         LCD_status.blinkLCD = ~LCD_status.blinkLCD;             // Toggle LCD_Blink variable.
00201 
00202                         // Copy display data buffer to I/O segment registers.
00203                         i = 20;
00204                         dest = &pLCDREG;
00205                         src = LCD_displayData;
00206                         do
00207                         {
00208                                 *dest++ = *src++;
00209                         } while ( --i );
00210                 }
00211                 else
00212                 {
00213                   LCD_timer = 1;              //If LCD timer allows update of the LCD, but update is blocked
00214                                               // by LCD_status.updateRequired == FALSE the LCD_timer is preloaded
00215                                               // with smallest timer seed to ensure fastest LCD update.
00216           LCD_status.updateComplete = FALSE;  //Block for further access to the LCD_displayData until
00217                                               // LCD update has been performed.
00218                 }
00219         }
00220 }

Generated on Fri Feb 17 12:28:29 2006 for AVR064: A Temperature Monitoring System with LCD Output by  doxygen 1.4.5