ButterflyMP3

LCD_functions.c

Go to the documentation of this file.
00001 //*****************************************************************************
00002 //
00003 //  File........: LCD_functions.c
00004 //
00005 //  Author(s)...: ATMEL Norway
00006 //
00007 //  Target(s)...: ATmega169
00008 //
00009 //  Compiler....: AVR-GCC 3.3.1; avr-libc 1.0
00010 //
00011 //  Description.: Additional LCD functions, scrolling text and write data
00012 //
00013 //  Revisions...: 1.0
00014 //
00015 //  YYYYMMDD - VER. - COMMENT                                       - SIGN.
00016 //
00017 //  20021015 - 1.0  - Created                                       - LHM
00018 //  20030116 - 2.0  - Code adapted to AVR Butterflyup               - KS
00019 //  20031009          port to avr-gcc/avr-libc                      - M.Thomas
00020 //
00021 //*****************************************************************************
00022 
00023 //  Include files
00024 #include <avr/io.h>
00025 #include <avr/pgmspace.h>
00026 #include <inttypes.h>
00027 #include "LCD_driver.h"
00028 #include "LCD_functions.h"
00029 //#include "BCD.h"
00030 // mt only for KEY_* and ST_OPTIONS_DISPLAY* definitions:
00031 #include "main.h"
00032 
00033 
00034 #define FALSE   0
00035 #define TRUE    (!FALSE)
00036 
00037 // mt char CONTRAST = LCD_INITIAL_CONTRAST;
00038 uint8_t CONTRAST = LCD_INITIAL_CONTRAST;
00039 
00040 // Start-up delay before scrolling a string over the LCD. "LCD_driver.c"
00041 extern char gLCD_Start_Scroll_Timer;
00042 
00043 /****************************************************************************
00044 *
00045 *       Function name : LCD_puts_f
00046 *
00047 *       Returns :               None
00048 *
00049 *       Parameters :    pFlashStr: Pointer to the string in flash
00050 *                   scrollmode: Not in use
00051 *
00052 *       Purpose :               Writes a string stored in flash to the LCD
00053 *
00054 *****************************************************************************/
00055 
00056 // mt void LCD_puts_f(char __flash *pFlashStr, char scrollmode)
00057 void LCD_puts_f(const char *pFlashStr, char scrollmode)
00058 {
00059     // char i;
00060         uint8_t i;
00061 
00062     while (gLCD_Update_Required);      // Wait for access to buffer
00063         
00064     // mt: for (i = 0; pFlashStr[i] && i < TEXTBUFFER_SIZE; i++)
00065         for (i = 0; pgm_read_byte(&pFlashStr[i]) && i < TEXTBUFFER_SIZE; i++)
00066     {
00067         // mt: gTextBuffer[i] = pFlashStr[i];
00068                 gTextBuffer[i] = pgm_read_byte(&pFlashStr[i]);
00069     }
00070 
00071     gTextBuffer[i] = '\0';
00072 
00073     if (i > 6)
00074     {
00075         gScrollMode = 1;        // Scroll if text is longer than display size
00076         gScroll = 0;
00077         gLCD_Start_Scroll_Timer = 3;    //Start-up delay before scrolling the text
00078     }
00079     else
00080     {
00081         gScrollMode = 0;        
00082         gScroll = 0;
00083     }
00084 
00085     gLCD_Update_Required = 1;
00086         gShowFilename =FALSE; 
00087 }
00088 
00089 
00090 /****************************************************************************
00091 *
00092 *       Function name : LCD_puts
00093 *
00094 *       Returns :               None
00095 *
00096 *       Parameters :    pStr: Pointer to the string
00097 *                   scrollmode: Not in use
00098 *
00099 *       Purpose :               Writes a string to the LCD
00100 *
00101 *****************************************************************************/
00102 void LCD_puts(char *pStr, char scrollmode)
00103 {
00104         uint8_t i; // char i;
00105         
00106         while (gLCD_Update_Required);      // Wait for access to buffer
00107 
00108     for (i = 0; pStr[i] && i < TEXTBUFFER_SIZE; i++)
00109     {
00110         gTextBuffer[i] = pStr[i];
00111     }
00112 
00113     gTextBuffer[i] = '\0';
00114 
00115     if ((i > 6))
00116     {
00117         gScrollMode = 1;        // Scroll if text is longer than display size
00118         gScroll = 0;
00119         gLCD_Start_Scroll_Timer = 3;    //Start-up delay before scrolling the text
00120     }
00121     else
00122     {
00123         gScrollMode = 0;        
00124         gScroll = 0;
00125     }
00126 
00127     gLCD_Update_Required = 1;
00128         gShowFilename =FALSE; 
00129 }
00130 
00131 
00132 /****************************************************************************
00133 *
00134 *       Function name : LCD_putc
00135 *
00136 *       Returns :               None
00137 *
00138 *       Parameters :    digit: Which digit to write on the LCD
00139 *                   character: Character to write
00140 *
00141 *       Purpose :               Writes a character to the LCD
00142 *
00143 *****************************************************************************/
00144 // mt void LCD_putc(char digit, char character)
00145 void LCD_putc(uint8_t digit, char character)
00146 {
00147     if (digit < TEXTBUFFER_SIZE)
00148         gTextBuffer[digit] = character;
00149 }
00150 
00151 
00152 /****************************************************************************
00153 *
00154 *       Function name : LCD_Clear
00155 *
00156 *       Returns :               None
00157 *
00158 *       Parameters :    None
00159 *
00160 *       Purpose :               Clear the LCD
00161 *
00162 *****************************************************************************/
00163 void LCD_Clear(void)
00164 {
00165     uint8_t i; // char i;
00166            
00167     for (i=0; i<TEXTBUFFER_SIZE; i++)
00168         gTextBuffer[i] = ' ';
00169 }
00170 
00171 
00172 /****************************************************************************
00173 *
00174 *       Function name : LCD_Colon
00175 *
00176 *       Returns :               None
00177 *
00178 *       Parameters :    show: Enables the colon if TRUE, disable if FALSE
00179 *
00180 *       Purpose :               Enable/disable colons on the LCD
00181 *
00182 *****************************************************************************/
00183 void LCD_Colon(char show)
00184 {
00185     gColon = show;
00186 }
00187 
00188 
00189 /****************************************************************************
00190 *
00191 *       Function name : LCD_UpdateRequired
00192 *
00193 *       Returns :               None
00194 *
00195 *       Parameters :    update: TRUE/FALSE
00196 *                   scrollmode: not in use
00197 *
00198 *       Purpose :               Tells the LCD that there is new data to be presented
00199 *
00200 *****************************************************************************/
00201 void LCD_UpdateRequired(char update, char scrollmode)
00202 {
00203 
00204     while (gLCD_Update_Required);
00205     
00206     gScrollMode = scrollmode;
00207     gScroll = 0;
00208 
00209     gLCD_Update_Required = update;
00210 }
00211 
00212 
00213 /****************************************************************************
00214 *
00215 *       Function name : LCD_FlashReset
00216 *
00217 *       Returns :               None
00218 *
00219 *       Parameters :    None
00220 *
00221 *       Purpose :               This function resets the blinking cycle of a flashing digit
00222 *
00223 *****************************************************************************/
00224 void LCD_FlashReset(void)
00225 {
00226     gFlashTimer = 0;
00227 }
00228 
00229 
00230 
00231 /****************************************************************************
00232 *
00233 *       Function name : SetContrast
00234 *
00235 *   Returns :       char ST_state (to the state-machine)
00236 *
00237 *   Parameters :    char input (from joystick)
00238 *
00239 *       Purpose :               Adjust the LCD contrast
00240 *
00241 *****************************************************************************/
00242 /*
00243 char SetContrast(char input)
00244 {
00245     static char enter = 1;
00246     char CH, CL;
00247 
00248     if (enter)
00249     {
00250         LCD_Clear();
00251         enter = 0;
00252     }
00253 
00254     CH = CHAR2BCD2(CONTRAST);
00255     CL = (CH & 0x0F) + '0';
00256     CH = (CH >> 4) + '0';
00257 
00258     LCD_putc(0, 'C');
00259     LCD_putc(1, 'T');
00260     LCD_putc(2, 'R');
00261     LCD_putc(3, ' ');
00262     LCD_putc(4, CH);
00263     LCD_putc(5, CL);
00264 
00265     LCD_UpdateRequired(TRUE, 0);
00266 
00267     if (input == KEY_PLUS)
00268         CONTRAST++;
00269     else if (input == KEY_MINUS)
00270         CONTRAST--;
00271 
00272     if (CONTRAST == 255)
00273         CONTRAST = 0;
00274     if (CONTRAST > 15)
00275         CONTRAST = 15;
00276 
00277     LCD_CONTRAST_LEVEL(CONTRAST);
00278 
00279 
00280     if (input == KEY_ENTER)
00281     {
00282         enter = 1;
00283         return ST_OPTIONS_DISPLAY_CONTRAST;
00284     }
00285 
00286     return ST_OPTIONS_DISPLAY_CONTRAST_FUNC;
00287 }
00288 
00289 */
00290 
00291 
00292 
00293 
 All Files Functions Variables Typedefs Enumerations Enumerator Defines