Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1920 - 1
/*****************************************************************************
2
 *   Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net                  *
3
 *   - original LCD control by Thomas "thkais" Kaiser                        *
4
 *   - special number formating routines taken from C-OSD                    *
5
 *      from Claas Anders "CaScAdE" Rathje                                   *
6
 *   - some extension, ellipse and circ_line by Peter "woggle" Mack          *
7
 * Thanks to Oliver Schwaneberg for adding several functions to this library!*
8
 *                                                                           *
9
 * Author:  Jan Michel (jan at mueschelsoft dot de)                          *
10
 * License: GNU General Public License, version 3                            *
11
 * Version: v0.93 September 2010                                             *
12
 *                                                                           *
13
 *   This program is free software; you can redistribute it and/or modify    *
14
 *   it under the terms of the GNU General Public License as published by    *
15
 *   the Free Software Foundation; either version 2 of the License.          *
16
 *                                                                           *
17
 *   This program is distributed in the hope that it will be useful,         *
18
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
19
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
20
 *   GNU General Public License for more details.                            *
21
 *                                                                           *
22
 *   You should have received a copy of the GNU General Public License       *
23
 *   along with this program; if not, write to the                           *
24
 *   Free Software Foundation, Inc.,                                         *
25
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.               *
26
 *                                                                           *
27
 *****************************************************************************/
28
 
29
#ifndef _LCD_H
30
#define _LCD_H
31
 
32
#define MNORMAL         0       //
33
#define MINVERS         2
34
#define MBIG            3
35
#define MBIGINVERS      4
36
 
37
 
38
//------------------------------------------------------------------------------------
39
// X-tended
40
void lcdx_putc( uint8_t x, uint8_t y, uint8_t c, uint8_t mode, int8_t xoffs, int8_t yoffs );
41
void lcdx_print (uint8_t *text, uint8_t mode, int8_t xoffs, int8_t yoffs);
42
void lcdx_print_at (uint8_t x, uint8_t y, uint8_t *text, uint8_t mode, int8_t xoffs, int8_t yoffs);
43
void lcdx_printp (const char *text, uint8_t mode, int8_t xoffs, int8_t yoffs);
44
void lcdx_printp_at (uint8_t x, uint8_t y, const char *text, uint8_t mode, int8_t xoffs, int8_t yoffs);
45
 
46
void writex_ndigit_number_s (uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad, uint8_t mode, int8_t xoffs, int8_t yoffs);
47
void writex_ndigit_number_s_10th (uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad, uint8_t mode, int8_t xoffs, int8_t yoffs);
48
 
49
void writex_ndigit_number_u (uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad, uint8_t mode, int8_t xoffs, int8_t yoffs);
50
void writex_ndigit_number_u_10th (uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad, uint8_t mode, int8_t xoffs, int8_t yoffs);
51
void writex_ndigit_number_u_100th (uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad, int8_t xoffs, int8_t yoffs);
52
 
53
void lcdx_puts_at(uint8_t x, uint8_t y, const char *s, uint8_t mode, int8_t xoffs, int8_t yoffs);
54
void writex_time (uint8_t x, uint8_t y, uint16_t seconds, uint8_t mode, int8_t xoffs, int8_t yoffs);
55
 
56
 
57
/*
58
 
59
//-----------------------------------------------------------------------------
60
// Command Codes
61
//-----------------------------------------------------------------------------
62
//1: Display on/off
63
#define LCD_DISPLAY_ON                  0xAF  //switch display on
64
#define LCD_DISPLAY_OFF                 0xAE  //switch display off
65
 
66
//2: display start line set (lower 6 bits select first line on lcd from 64 lines in memory)
67
#define LCD_START_LINE                  0x40
68
 
69
//3: Page address set (lower 4 bits select one of 8 pages)
70
#define LCD_PAGE_ADDRESS                0xB0
71
 
72
//4: column address (lower 4 bits are upper / lower nibble of column address)
73
#define LCD_COL_ADDRESS_MSB             0x10
74
#define LCD_COL_ADDRESS_LSB             0x00  //second part of column address
75
 
76
//8: select orientation (black side of the display should be further away from viewer)
77
#define LCD_BOTTOMVIEW                  0xA1  //6 o'clock view
78
#define LCD_TOPVIEW                             0xA0  //12 o'clock view
79
 
80
//9: select normal (white background, black pixels) or reverse (black background, white pixels) mode
81
#define LCD_DISPLAY_POSITIVE    0xA6  //not inverted mode
82
#define LCD_DISPLAY_INVERTED    0xA7  //inverted display
83
 
84
//10: show memory content or switch all pixels on
85
#define LCD_SHOW_NORMAL                 0xA4  //show dram content
86
#define LCD_SHOW_ALL_POINTS             0xA5  //show all points
87
 
88
//11: lcd bias set
89
#define LCD_BIAS_1_9                    0xA2
90
#define LCD_BIAS_1_7                    0xA3
91
 
92
//14: Reset Controller
93
#define LCD_RESET_CMD                   0xE2
94
 
95
//15: output mode select (turns display upside-down)
96
#define LCD_SCAN_DIR_NORMAL             0xC0  //normal scan direction
97
#define LCD_SCAN_DIR_REVERSE    0xC8  //reversed scan direction
98
 
99
//16: power control set (lower 3 bits select operating mode)
100
//Bit 0: Voltage follower on/off - Bit 1: Voltage regulator on/off - Bit 2: Booster circuit on/off
101
#define LCD_POWER_CONTROL               0x28  //base command
102
#define LCD_POWER_LOW_POWER             0x2F
103
#define LCD_POWER_WIDE_RANGE    0x2F
104
#define LCD_POWER_LOW_VOLTAGE   0x2B
105
 
106
//17: voltage regulator resistor ratio set (lower 3 bits select ratio)
107
//selects lcd voltage - 000 is low (~ -2V), 111 is high (~ - 10V), also depending on volume mode. Datasheet suggests 011
108
#define LCD_VOLTAGE                             0x20
109
 
110
//18: Volume mode set (2-byte command, lower 6 bits in second word select value, datasheet suggests 0x1F)
111
#define LCD_VOLUME_MODE_1               0x81
112
#define LCD_VOLUME_MODE_2               0x00
113
 
114
//#if DISPLAY_TYPE == 128 || DISPLAY_TYPE == 132
115
//19: static indicator (2-byte command), first on/off, then blinking mode
116
#define LCD_INDICATOR_ON                0xAD  //static indicator on
117
#define LCD_INDICATOR_OFF               0xAC  //static indicator off
118
#define LCD_INDICATOR_MODE_OFF  0x00
119
#define LCD_INDICATOR_MODE_1HZ  0x01
120
#define LCD_INDICATOR_MODE_2HZ  0x10
121
#define LCD_INDICATOR_MODE_ON   0x11
122
 
123
//20: booster ratio set (2-byte command)
124
#define LCD_BOOSTER_SET                 0xF8  //set booster ratio
125
#define LCD_BOOSTER_234                 0x00  //2x-4x
126
#define LCD_BOOSTER_5                   0x01  //5x
127
#define LCD_BOOSTER_6                   0x03  //6x
128
//#endif
129
 
130
//22: NOP command
131
#define LCD_NOP                                 0xE3
132
 
133
//#if DISPLAY_TYPE == 102
134
////25: advanced program control
135
//#define LCD_ADV_PROG_CTRL             0xFA
136
//#define LCD_ADV_PROG_CTRL2    0x10
137
//#endif
138
 
139
//-----------------------------------------------------------------------------
140
// Makros to execute commands
141
//-----------------------------------------------------------------------------
142
 
143
#define LCD_SWITCH_ON()                                 lcd_command(LCD_DISPLAY_ON)
144
#define LCD_SWITCH_OFF()                                lcd_command(LCD_DISPLAY_OFF)
145
#define LCD_SET_FIRST_LINE(i)                   lcd_command(LCD_START_LINE | ((i) & 0x3F))
146
#define LCD_SET_PAGE_ADDR(i)                    lcd_command(LCD_PAGE_ADDRESS | ((i) & 0x0F))
147
#define LCD_SET_COLUMN_ADDR(i)                  lcd_command(LCD_COL_ADDRESS_MSB | ((i>>4) & 0x0F)); \
148
                                                                                lcd_command(LCD_COL_ADDRESS_LSB | ((i) & 0x0F))
149
#define LCD_GOTO_ADDRESS(page,col);             lcd_command(LCD_PAGE_ADDRESS | ((page) & 0x0F)); \
150
                                                                                lcd_command(LCD_COL_ADDRESS_MSB | ((col>>4) & 0x0F)); \
151
                                                                                lcd_command(LCD_COL_ADDRESS_LSB | ((col) & 0x0F));
152
 
153
#define LCD_SET_BOTTOM_VIEW()                   lcd_command(LCD_BOTTOMVIEW)
154
#define LCD_SET_TOP_VIEW()                              lcd_command(LCD_TOPVIEW)
155
#define LCD_SET_MODE_POSITIVE()                 lcd_command(LCD_DISPLAY_POSITIVE)
156
#define LCD_SET_MODE_INVERTED()                 lcd_command(LCD_DISPLAY_INVERTED)
157
#define LCD_SHOW_ALL_PIXELS_ON()                lcd_command(LCD_SHOW_ALL_POINTS)
158
#define LCD_SHOW_ALL_PIXELS_OFF()               lcd_command(LCD_SHOW_NORMAL)
159
#define LCD_SET_BIAS_RATIO_1_7()                lcd_command(LCD_BIAS_1_7)
160
#define LCD_SET_BIAS_RATIO_1_9()                lcd_command(LCD_BIAS_1_9)
161
#define LCD_SEND_RESET()                                lcd_command(LCD_RESET_CMD)
162
#define LCD_ORIENTATION_NORMAL()                lcd_command(LCD_SCAN_DIR_NORMAL)
163
#define LCD_ORIENTATION_UPSIDEDOWN()    lcd_command(LCD_SCAN_DIR_REVERSE)
164
#define LCD_SET_POWER_CONTROL(i)                lcd_command(LCD_POWER_CONTROL | ((i) & 0x07))
165
#define LCD_SET_LOW_POWER()                             lcd_command(LCD_POWER_LOW_POWER)
166
#define LCD_SET_WIDE_RANGE()                    lcd_command(LCD_POWER_WIDE_RANGE)
167
#define LCD_SET_LOW_VOLTAGE()                   lcd_command(LCD_POWER_LOW_VOLTAGE)
168
#define LCD_SET_BIAS_VOLTAGE(i)                 lcd_command(LCD_VOLTAGE | ((i) & 0x07))
169
#define LCD_SET_VOLUME_MODE(i)                  lcd_command(LCD_VOLUME_MODE_1); \
170
                                                                                lcd_command(LCD_VOLUME_MODE_2 | ((i) & 0x3F))
171
 
172
//#if DISPLAY_TYPE == 128 || DISPLAY_TYPE == 132
173
#define LCD_SET_INDICATOR_OFF()                 lcd_command(LCD_INDICATOR_OFF); \
174
                                                                                lcd_command(LCD_INDICATOR_MODE_OFF)
175
#define LCD_SET_INDICATOR_STATIC()              lcd_command(LCD_INDICATOR_ON); \
176
                                                                                lcd_command(LCD_INDICATOR_MODE_ON)
177
#define LCD_SET_INDICATOR_1HZ()                 lcd_command(LCD_INDICATOR_ON); \
178
                                                                                lcd_command(LCD_INDICATOR_MODE_1HZ)
179
#define LCD_SET_INDICATOR_2HZ()                 lcd_command(LCD_INDICATOR_ON); \
180
                                                                                lcd_command(LCD_INDICATOR_MODE_2HZ)
181
#define LCD_SET_INDICATOR(i,j)                  lcd_command(LCD_INDICATOR_OFF | ((i) & 1)); \
182
                                                                                lcd_command(((j) & 2))
183
#define LCD_SLEEP_MODE                                  lcd_command(LCD_INDICATOR_OFF); \
184
                                                                                lcd_command(LCD_DISPLAY_OFF); \
185
                                                                                lcd_command(LCD_SHOW_ALL_POINTS)
186
//#endif
187
 
188
//#if DISPLAY_TYPE == 102
189
//#define LCD_TEMPCOMP_HIGH                             0x80
190
//#define LCD_COLWRAP                                   0x02
191
//#define LCD_PAGEWRAP                                  0x01
192
//#define LCD_SET_ADV_PROG_CTRL(i)              lcd_command(LCD_ADV_PROG_CTRL);
193
//                                                                              lcd_command(LCD_ADV_PROG_CTRL2 & i)
194
//#endif
195
 
196
*/
197
 
198
 
199
 
200
extern volatile uint8_t LCD_ORIENTATION;
201
 
202
//#define LCD_LINES               8
203
//#define LCD_COLS                21
204
 
205
extern uint8_t lcd_xpos;
206
extern uint8_t lcd_ypos;
207
 
208
void lcd_command(uint8_t cmd);
209
void send_byte (uint8_t data);
210
void LCD_Init (uint8_t LCD_Mode);
211
void new_line (void);
212
void lcd_puts_at(uint8_t x, uint8_t y,const char *s, uint8_t mode );
213
void lcd_putc (uint8_t x, uint8_t y, uint8_t c, uint8_t mode);
214
void send_byte (uint8_t data);
215
void lcd_print (uint8_t *text, uint8_t mode);
216
void lcd_print_at (uint8_t x, uint8_t y, uint8_t *text, uint8_t mode);
217
 
218
void lcd_printp (const char *text, uint8_t mode);
219
void lcd_printp_at (uint8_t x, uint8_t y, const char *text, uint8_t mode);
220
void lcd_printpns (const char *text, uint8_t mode);
221
void lcd_printpns_at (uint8_t x, uint8_t y, const char *text, uint8_t mode);
222
void lcd_cls (void);
223
void lcd_cls_line (uint8_t x, uint8_t y, uint8_t w);
224
 
225
void print_display (uint8_t *text);
226
void print_display_at (uint8_t x, uint8_t y, uint8_t *text);
227
void copy_line (uint8_t y);
228
void paste_line (uint8_t y);
229
 
230
void lcd_plot (uint8_t x, uint8_t y, uint8_t mode);
231
void lcd_line (unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, uint8_t mode);
232
void lcd_rect (uint8_t x1, uint8_t y1, uint8_t widthx, uint8_t widthy, uint8_t mode);
233
void lcd_frect (uint8_t x1, uint8_t y1, uint8_t widthx, uint8_t widthy, uint8_t mode);
234
void lcd_circle (int16_t x0, int16_t y0, int16_t radius, uint8_t mode);
235
void lcd_fcircle (int16_t x0, int16_t y0, int16_t radius, uint8_t mode);
236
void lcd_circ_line (uint8_t x, uint8_t y, uint8_t r, uint16_t deg, uint8_t mode);
237
 
238
void lcd_ellipse (int16_t x0, int16_t y0, int16_t rx, int16_t ry, uint8_t mode);
239
void lcd_ellipse_line (uint8_t x, uint8_t y, uint8_t rx, uint8_t ry, uint16_t deg, uint8_t mode);
240
 
241
void lcd_ecircle (int16_t x0, int16_t y0, int16_t radius, uint8_t mode);
242
void lcd_ecirc_line (uint8_t x, uint8_t y, uint8_t r, uint16_t deg, uint8_t mode);
243
 
244
void lcd_view_font (uint8_t page);
245
void lcd_print_hex_at (uint8_t x, uint8_t y, uint8_t h, uint8_t mode);
246
 
247
void lcd_write_number_u (uint8_t number);
248
void lcd_write_number_u_at (uint8_t x, uint8_t y, uint8_t number);
249
void lcd_print_hex (uint8_t h, uint8_t mode);
250
/**
251
 * Write only some digits of a unsigned <number> at <x>/<y>
252
 * <length> represents the length to rightbound the number
253
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of   7
254
 */
255
void write_ndigit_number_u (uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad,uint8_t mode);
256
 
257
/**
258
 * Write only some digits of a signed <number> at <x>/<y>
259
 * <length> represents the length to rightbound the number
260
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of   7
261
 */
262
 
263
void write_ndigit_number_s (uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad, uint8_t mode);
264
 
265
/**
266
 * Write only some digits of a unsigned <number> at <x>/<y> as /10th of the value
267
 * <length> represents the length to rightbound the number
268
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 00.7 instead of   .7
269
 */
270
void write_ndigit_number_u_10th (uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad, uint8_t mode);
271
 
272
/**
273
 * Write only some digits of a unsigned <number> at <x>/<y> as /100th of the value
274
 * <length> represents the length to rightbound the number
275
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 00.7 instead of   .7
276
 */
277
void write_ndigit_number_u_100th (uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad);
278
 
279
/**
280
 * Write only some digits of a signed <number> at <x>/<y> as /10th of the value
281
 * <length> represents the length to rightbound the number
282
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 00.7 instead of   .7
283
 */
284
void write_ndigit_number_s_10th (uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad, uint8_t mode);
285
 
286
/**
287
 *  write <seconds> as human readable time at <x>/<y>
288
 */
289
void write_time (uint8_t x, uint8_t y, uint16_t seconds);
290
 
291
/**
292
 * wirte a <position> at <x>/<y> assuming it is a gps position for long-/latitude
293
 */
294
void write_gps_pos (uint8_t x, uint8_t y, int32_t position);
295
 
296
//------------------------------------------------------------------------------------
297
// Show PKT Baudrate at given position
298
//
299
 
300
void show_baudrate (uint8_t x, uint8_t y, uint8_t Baudrate, uint8_t mode);
301
 
302
 
303
#endif