Parallel Programming - Final version
[matches/honours.git] / research / TCS / apparatus / source_code / LCD_functions.c
1 //*****************************************************************************\r
2 //\r
3 //  File........: LCD_functions.c\r
4 //\r
5 //  Author(s)...: ATMEL Norway\r
6 //\r
7 //  Target(s)...: ATmega169\r
8 //\r
9 //  Compiler....: AVR-GCC 4.1.1; avr-libc 1.4.5\r
10 //\r
11 //  Description.: Additional LCD functions, scrolling text and write data\r
12 //\r
13 //  Revisions...: 1.0\r
14 //\r
15 //  YYYYMMDD - VER. - COMMENT                                       - SIGN.\r
16 //\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
23 \r
24 //  Include files\r
25 #include <stdint.h>\r
26 #include <avr/io.h>\r
27 #include <avr/pgmspace.h>\r
28 #include "LCD_Driver.h"\r
29 #include "LCD_functions.h"\r
30 \r
31 // mt only for KEY_* and ST_OPTIONS_DISPLAY* definitions:\r
32 #include "main.h"\r
33 \r
34 \r
35 \r
36 #define FALSE   0\r
37 #define TRUE    (!FALSE)\r
38 \r
39 // mt char CONTRAST = LCD_INITIAL_CONTRAST;\r
40 uint8_t CONTRAST = LCD_INITIAL_CONTRAST;\r
41 \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
44 \r
45 /****************************************************************************\r
46 *\r
47 *       Function name : LCD_puts\r
48 *\r
49 *       Returns :               None\r
50 *\r
51 *       Parameters :    pStr: Pointer to the string\r
52 *                   scrollmode: Not in use\r
53 *\r
54 *       Purpose :               Writes a string to the LCD\r
55 *\r
56 *****************************************************************************/\r
57 void LCD_puts(char *pStr)\r
58 {\r
59     uint8_t i; // char i;\r
60 \r
61     while (gLCD_Update_Required);      // Wait for access to buffer\r
62 \r
63     for (i = 0; pStr[i] && i < TEXTBUFFER_SIZE; i++)\r
64     {\r
65         gTextBuffer[i] = pStr[i];\r
66     }\r
67 \r
68     gTextBuffer[i] = '\0';\r
69 \r
70     if (i > 6)\r
71     {\r
72         gScrollMode = 1;        // Scroll if text is longer than display size\r
73         gScroll = 0;\r
74         gLCD_Start_Scroll_Timer = 3;    //Start-up delay before scrolling the text\r
75     }\r
76     else\r
77     {\r
78         gScrollMode = 0;        \r
79         gScroll = 0;\r
80     }\r
81 \r
82     gLCD_Update_Required = 1;\r
83 }\r
84 \r
85 \r
86 \r
87 /****************************************************************************\r
88 *\r
89 *       Function name : LCD_Clear\r
90 *\r
91 *       Returns :               None\r
92 *\r
93 *       Parameters :    None\r
94 *\r
95 *       Purpose :               Clear the LCD\r
96 *\r
97 *****************************************************************************/\r
98 void LCD_Clear(void)\r
99 {\r
100     uint8_t i; // char i;\r
101 \r
102     for (i=0; i<TEXTBUFFER_SIZE; i++)\r
103         gTextBuffer[i] = ' ';\r
104 \r
105     gTextBuffer[0] = '\0'; // mt 5/2007\r
106 }\r
107 \r
108 \r
109 /****************************************************************************\r
110 *\r
111 *       Function name : LCD_Colon\r
112 *\r
113 *       Returns :               None\r
114 *\r
115 *       Parameters :    show: Enables the colon if TRUE, disable if FALSE\r
116 *\r
117 *       Purpose :               Enable/disable colons on the LCD\r
118 *\r
119 *****************************************************************************/\r
120 void LCD_Colon(char show)\r
121 {\r
122     gColon = show;\r
123 }\r
124 \r
125 \r
126 /****************************************************************************\r
127 *\r
128 *       Function name : LCD_UpdateRequired\r
129 *\r
130 *       Returns :               None\r
131 *\r
132 *       Parameters :    update: TRUE/FALSE\r
133 *                   scrollmode: not in use\r
134 *\r
135 *       Purpose :               Tells the LCD that there is new data to be presented\r
136 *\r
137 *****************************************************************************/\r
138 void LCD_UpdateRequired(char update, char scrollmode)\r
139 {\r
140 \r
141     while (gLCD_Update_Required);\r
142     \r
143     gScrollMode = scrollmode;\r
144     gScroll = 0;\r
145 \r
146     gLCD_Update_Required = update;\r
147 }\r
148 \r
149 \r
150 /****************************************************************************\r
151 *\r
152 *       Function name : LCD_FlashReset\r
153 *\r
154 *       Returns :               None\r
155 *\r
156 *       Parameters :    None\r
157 *\r
158 *       Purpose :               This function resets the blinking cycle of a flashing digit\r
159 *\r
160 *****************************************************************************/\r
161 void LCD_FlashReset(void)\r
162 {\r
163     gFlashTimer = 0;\r
164 }\r
165 \r
166 #include <stdarg.h>\r
167 #include "printf.h"\r
168 int LCD_printf(const char * format, ...)\r
169 {\r
170         char buffer[TEXTBUFFER_SIZE];\r
171         va_list args;\r
172         va_start(args, format);\r
173         int result = vsprintf(buffer, format, args);\r
174         LCD_puts(buffer);\r
175         return result;\r
176 }\r
177 \r
178 \r
179 \r
180 void LCD_putc(uint8_t digit, char character)\r
181 {\r
182     if (digit < TEXTBUFFER_SIZE)\r
183         gTextBuffer[digit] = character;\r
184 }\r
185 \r
186 void LCD_ShowTime(uint32 tmr)\r
187 {\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
194         \r
195         \r
196         uint8 digits[6];\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
203 \r
204         for (uint8 i = 0; i < 6; ++i)\r
205         {\r
206                 LCD_putc(i, '0' + digits[i]);\r
207         }\r
208         LCD_putc(6, '\0');\r
209 \r
210 \r
211         LCD_UpdateRequired(1, 0);\r
212 }\r

UCC git Repository :: git.ucc.asn.au