00001
00027
00028 #include "defines.h"
00029 #include "LCD_driver.h"
00030
00031 union _LCD_status LCD_status = {0x01};
00032 unsigned char LCD_timer = LCD_TIMER_SEED;
00033
00034 unsigned char LCD_displayData[LCD_REGISTER_COUNT];
00035
00037 __flash unsigned int LCD_character_table[] =
00038 {
00039 0x0A51,
00040 0x2A80,
00041 0x0000,
00042 0x0A00,
00043 0x0000,
00044 0x0000,
00045 0x5559,
00046 0x0118,
00047 0x1e11,
00048 0x1b11,
00049 0x0b50,
00050 0x1b41,
00051 0x1f41,
00052 0x0111,
00053 0x1f51,
00054 0x1b51,
00055 0x0000,
00056 0x0000,
00057 0x0000,
00058 0x0000,
00059 0x0000,
00060 0x0000,
00061 0x0000,
00062 0x0f51,
00063 0x3991,
00064 0x1441,
00065 0x3191,
00066 0x1e41,
00067 0x0e41,
00068 0x1d41,
00069 0x0f50,
00070 0x2080,
00071 0x1510,
00072 0x8648,
00073 0x1440,
00074 0x0578,
00075 0x8570,
00076 0x1551,
00077 0x0e51,
00078 0x9551,
00079 0x8e51,
00080 0x9021,
00081 0x2081,
00082 0x1550,
00083 0x4448,
00084 0xc550,
00085 0xc028,
00086 0x2028,
00087 0x5009,
00088 0x0000,
00089 0x0000,
00090 0x0000,
00091 0x0000,
00092 0x0000
00093 };
00094
00095
00098 void LCD_Init (void)
00099 {
00100 LCD_AllSegments( FALSE );
00101 LCDCRA = (1<<LCDEN);
00102
00103 LCD_CONTRAST_LEVEL(LCD_INITIAL_CONTRAST);
00104
00105
00106 LCDCRB = (1<<LCDCS) | (1<<LCDMUX1) | (1<<LCDMUX0) | (1<<LCDPM2) | (1<<LCDPM1)| (1<<LCDPM0);
00107 LCDFRR = (1<<LCDPS0);
00108
00109 LCDCRA |= (1<<LCDIE);
00110 }
00111
00112
00119 void LCD_WriteDigit( unsigned char c, unsigned char digit )
00120 {
00121
00122 unsigned int seg;
00123 unsigned char i;
00124 unsigned char mask, nibble;
00125 unsigned char *ptr;
00126
00127
00128 seg = 0x0000;
00129 if ( (c >= '*') && (c <= 'z') )
00130 {
00131
00132
00133 if ( c >= 'a' ) c &= ~0x20;
00134 c -= '*';
00135 seg = LCD_character_table[c];
00136 }
00137 else
00138 {
00139 return;
00140 }
00141
00142
00143 mask = 0x0F;
00144 if ( digit & 0x01 )
00145 {
00146
00147 }
00148 else
00149 {
00150 mask = 0xF0;
00151 }
00152
00153 i = digit-2;
00154 if ( i >= 6 )
00155 return;
00156 i >>= 1;
00157 ptr = LCD_displayData + i;
00158
00159 i = 4;
00160 do
00161 {
00162 nibble = seg & 0x000F;
00163 seg >>= 4;
00164 if ( digit & 0x01 )
00165 nibble <<= 4;
00166 *ptr = (*ptr & mask) | nibble;
00167 ptr += 5;
00168 } while ( --i );
00169 }
00170
00171
00176 void LCD_AllSegments( unsigned char input )
00177 {
00178 unsigned char i;
00179 unsigned char *ptr;
00180
00181 if( input )
00182 input = 0xFF;
00183
00184
00185 ptr = LCD_displayData;
00186 i = 20;
00187 do
00188 {
00189 *ptr++ = input;
00190 } while ( --i );
00191 }
00192
00193
00196 #pragma vector = LCD_SOF_vect
00197 __interrupt void LCD_SOF_interrupt( void )
00198
00199
00200 {
00201 unsigned char i;
00202 unsigned char *src, *dest;
00203
00204 LCD_timer--;
00205 if( LCD_timer == 0 )
00206 {
00207 if( LCD_status.updateRequired == TRUE )
00208 {
00209 LCD_timer = LCD_TIMER_SEED;
00210 LCD_status.updateComplete = TRUE;
00211
00212
00213 i = 20;
00214 dest = &pLCDREG;
00215 src = LCD_displayData;
00216 do
00217 {
00218 *dest++ = *src++;
00219 } while ( --i );
00220 }
00221 else
00222 {
00223 LCD_timer = 1;
00224
00225
00226 LCD_status.updateComplete = FALSE;
00227
00228 }
00229 }
00230 }