1 //*****************************************************************************
\r
3 // File........: LCD_functions.c
\r
5 // Author(s)...: ATMEL Norway
\r
7 // Target(s)...: ATmega169
\r
9 // Compiler....: AVR-GCC 4.1.1; avr-libc 1.4.5
\r
11 // Description.: Additional LCD functions, scrolling text and write data
\r
13 // Revisions...: 1.0
\r
15 // YYYYMMDD - VER. - COMMENT - SIGN.
\r
17 // 20021015 - 1.0 - Created - LHM
\r
18 // 20030116 - 2.0 - Code adapted to AVR Butterflyup - KS
\r
19 // 20031009 port to avr-gcc/avr-libc - M.Thomas
\r
20 // 20070131 gLCD_Start_Scroll_Timer volatile - mt
\r
21 // 20070517 LCDClear, gTextBuffer[0] to 0-char - mt
\r
22 //*****************************************************************************
\r
27 #include <avr/pgmspace.h>
\r
28 #include "LCD_Driver.h"
\r
29 #include "LCD_functions.h"
\r
31 // mt only for KEY_* and ST_OPTIONS_DISPLAY* definitions:
\r
37 #define TRUE (!FALSE)
\r
39 // mt char CONTRAST = LCD_INITIAL_CONTRAST;
\r
40 uint8_t CONTRAST = LCD_INITIAL_CONTRAST;
\r
42 // Start-up delay before scrolling a string over the LCD. "LCD_driver.c"
\r
43 extern volatile char gLCD_Start_Scroll_Timer;
\r
45 /****************************************************************************
\r
47 * Function name : LCD_puts
\r
51 * Parameters : pStr: Pointer to the string
\r
52 * scrollmode: Not in use
\r
54 * Purpose : Writes a string to the LCD
\r
56 *****************************************************************************/
\r
57 void LCD_puts(char *pStr)
\r
59 uint8_t i; // char i;
\r
61 while (gLCD_Update_Required); // Wait for access to buffer
\r
63 for (i = 0; pStr[i] && i < TEXTBUFFER_SIZE; i++)
\r
65 gTextBuffer[i] = pStr[i];
\r
68 gTextBuffer[i] = '\0';
\r
72 gScrollMode = 1; // Scroll if text is longer than display size
\r
74 gLCD_Start_Scroll_Timer = 3; //Start-up delay before scrolling the text
\r
82 gLCD_Update_Required = 1;
\r
87 /****************************************************************************
\r
89 * Function name : LCD_Clear
\r
95 * Purpose : Clear the LCD
\r
97 *****************************************************************************/
\r
98 void LCD_Clear(void)
\r
100 uint8_t i; // char i;
\r
102 for (i=0; i<TEXTBUFFER_SIZE; i++)
\r
103 gTextBuffer[i] = ' ';
\r
105 gTextBuffer[0] = '\0'; // mt 5/2007
\r
109 /****************************************************************************
\r
111 * Function name : LCD_Colon
\r
115 * Parameters : show: Enables the colon if TRUE, disable if FALSE
\r
117 * Purpose : Enable/disable colons on the LCD
\r
119 *****************************************************************************/
\r
120 void LCD_Colon(char show)
\r
126 /****************************************************************************
\r
128 * Function name : LCD_UpdateRequired
\r
132 * Parameters : update: TRUE/FALSE
\r
133 * scrollmode: not in use
\r
135 * Purpose : Tells the LCD that there is new data to be presented
\r
137 *****************************************************************************/
\r
138 void LCD_UpdateRequired(char update, char scrollmode)
\r
141 while (gLCD_Update_Required);
\r
143 gScrollMode = scrollmode;
\r
146 gLCD_Update_Required = update;
\r
150 /****************************************************************************
\r
152 * Function name : LCD_FlashReset
\r
156 * Parameters : None
\r
158 * Purpose : This function resets the blinking cycle of a flashing digit
\r
160 *****************************************************************************/
\r
161 void LCD_FlashReset(void)
\r
166 #include <stdarg.h>
\r
167 #include "printf.h"
\r
168 int LCD_printf(const char * format, ...)
\r
170 char buffer[TEXTBUFFER_SIZE];
\r
172 va_start(args, format);
\r
173 int result = vsprintf(buffer, format, args);
\r
180 void LCD_putc(uint8_t digit, char character)
\r
182 if (digit < TEXTBUFFER_SIZE)
\r
183 gTextBuffer[digit] = character;
\r
186 void LCD_ShowTime(uint32 tmr)
\r
188 uint hours = tmr / 360000;
\r
189 tmr = tmr - hours*360000;
\r
190 uint minutes = tmr / 6000;
\r
191 tmr = tmr - minutes*6000;
\r
192 uint seconds = tmr / 100;
\r
193 tmr = tmr - seconds*100;
\r
197 digits[0] = hours/10;
\r
198 digits[1] = hours%10;
\r
199 digits[2] = minutes/10;
\r
200 digits[3] = minutes%10;
\r
201 digits[4] = seconds/10;
\r
202 digits[5] = seconds%10;
\r
204 for (uint8 i = 0; i < 6; ++i)
\r
206 LCD_putc(i, '0' + digits[i]);
\r
211 LCD_UpdateRequired(1, 0);
\r