Project

General

Profile

Statistics
| Revision:

root / branches / rbom / code / projects / colonet / utilities / robot_wireless_relay / lcd.c @ 1390

History | View | Annotate | Download (7.23 KB)

1 13 emarinel
/*
2

3
lcd-ar2.c - implementation for lcd functions
4

5
Author: CMU Robotics Club, Colony Project
6

7
This uses SPI.
8

9
lcd_init MUST be called before anything can be used.
10

11
*/
12
13
#include <avr/io.h>
14
#include <lcd.h>
15
#include <time.h>
16
17
#include "oled.h"
18
19
/*
20
FontLookup - a lookup table for all characters
21
*/
22
static const unsigned char FontLookup [][5] =
23
{
24
    { 0x00, 0x00, 0x00, 0x00, 0x00 },  // sp
25
    { 0x00, 0x00, 0x5f, 0x00, 0x00 },   // !
26
    { 0x00, 0x07, 0x00, 0x07, 0x00 },   // "
27
    { 0x14, 0x7f, 0x14, 0x7f, 0x14 },   // #
28
    { 0x24, 0x2a, 0x7f, 0x2a, 0x12 },   // $
29
        { 0x23, 0x13, 0x08, 0x64, 0x62 },   // %
30
    { 0x36, 0x49, 0x55, 0x22, 0x50 },   // &
31
    { 0x00, 0x05, 0x03, 0x00, 0x00 },   // '
32
    { 0x00, 0x1c, 0x22, 0x41, 0x00 },   // (
33
    { 0x00, 0x41, 0x22, 0x1c, 0x00 },   // )
34
    { 0x14, 0x08, 0x3E, 0x08, 0x14 },   // *
35
    { 0x08, 0x08, 0x3E, 0x08, 0x08 },   // +
36
    { 0x00, 0x00, 0x50, 0x30, 0x00 },   // ,
37
    { 0x10, 0x10, 0x10, 0x10, 0x10 },   // -
38
    { 0x00, 0x60, 0x60, 0x00, 0x00 },   // .
39
    { 0x20, 0x10, 0x08, 0x04, 0x02 },   // /
40
    { 0x3E, 0x51, 0x49, 0x45, 0x3E },   // 0
41
    { 0x00, 0x42, 0x7F, 0x40, 0x00 },   // 1
42
    { 0x42, 0x61, 0x51, 0x49, 0x46 },   // 2
43
    { 0x21, 0x41, 0x45, 0x4B, 0x31 },   // 3
44
    { 0x18, 0x14, 0x12, 0x7F, 0x10 },   // 4
45
    { 0x27, 0x45, 0x45, 0x45, 0x39 },   // 5
46
    { 0x3C, 0x4A, 0x49, 0x49, 0x30 },   // 6
47
    { 0x01, 0x71, 0x09, 0x05, 0x03 },   // 7
48
    { 0x36, 0x49, 0x49, 0x49, 0x36 },   // 8
49
    { 0x06, 0x49, 0x49, 0x29, 0x1E },   // 9
50
    { 0x00, 0x36, 0x36, 0x00, 0x00 },   // :
51
    { 0x00, 0x56, 0x36, 0x00, 0x00 },   // ;
52
    { 0x08, 0x14, 0x22, 0x41, 0x00 },   // <
53
    { 0x14, 0x14, 0x14, 0x14, 0x14 },   // =
54
    { 0x00, 0x41, 0x22, 0x14, 0x08 },   // >
55
    { 0x02, 0x01, 0x51, 0x09, 0x06 },   // ?
56
    { 0x32, 0x49, 0x59, 0x51, 0x3E },   // @
57
    { 0x7E, 0x11, 0x11, 0x11, 0x7E },   // A
58
    { 0x7F, 0x49, 0x49, 0x49, 0x36 },   // B
59
    { 0x3E, 0x41, 0x41, 0x41, 0x22 },   // C
60
    { 0x7F, 0x41, 0x41, 0x22, 0x1C },   // D
61
    { 0x7F, 0x49, 0x49, 0x49, 0x41 },   // E
62
    { 0x7F, 0x09, 0x09, 0x09, 0x01 },   // F
63
    { 0x3E, 0x41, 0x49, 0x49, 0x7A },   // G
64
    { 0x7F, 0x08, 0x08, 0x08, 0x7F },   // H
65
    { 0x00, 0x41, 0x7F, 0x41, 0x00 },   // I
66
    { 0x20, 0x40, 0x41, 0x3F, 0x01 },   // J
67
    { 0x7F, 0x08, 0x14, 0x22, 0x41 },   // K
68
    { 0x7F, 0x40, 0x40, 0x40, 0x40 },   // L
69
    { 0x7F, 0x02, 0x0C, 0x02, 0x7F },   // M
70
    { 0x7F, 0x04, 0x08, 0x10, 0x7F },   // N
71
    { 0x3E, 0x41, 0x41, 0x41, 0x3E },   // O
72
    { 0x7F, 0x09, 0x09, 0x09, 0x06 },   // P
73
    { 0x3E, 0x41, 0x51, 0x21, 0x5E },   // Q
74
    { 0x7F, 0x09, 0x19, 0x29, 0x46 },   // R
75
    { 0x46, 0x49, 0x49, 0x49, 0x31 },   // S
76
    { 0x01, 0x01, 0x7F, 0x01, 0x01 },   // T
77
    { 0x3F, 0x40, 0x40, 0x40, 0x3F },   // U
78
    { 0x1F, 0x20, 0x40, 0x20, 0x1F },   // V
79
    { 0x3F, 0x40, 0x38, 0x40, 0x3F },   // W
80
    { 0x63, 0x14, 0x08, 0x14, 0x63 },   // X
81
    { 0x07, 0x08, 0x70, 0x08, 0x07 },   // Y
82
    { 0x61, 0x51, 0x49, 0x45, 0x43 },   // Z
83
    { 0x00, 0x7F, 0x41, 0x41, 0x00 },   // [
84
    { 0x02, 0x04, 0x08, 0x10, 0x20 },   // backslash
85
    { 0x00, 0x41, 0x41, 0x7F, 0x00 },   // ]
86
    { 0x04, 0x02, 0x01, 0x02, 0x04 },   // ^
87
    { 0x40, 0x40, 0x40, 0x40, 0x40 },   // _
88
    { 0x00, 0x01, 0x02, 0x04, 0x00 },   // '
89
    { 0x20, 0x54, 0x54, 0x54, 0x78 },   // a
90
    { 0x7F, 0x48, 0x44, 0x44, 0x38 },   // b
91
    { 0x38, 0x44, 0x44, 0x44, 0x20 },   // c
92
    { 0x38, 0x44, 0x44, 0x48, 0x7F },   // d
93
    { 0x38, 0x54, 0x54, 0x54, 0x18 },   // e
94
    { 0x08, 0x7E, 0x09, 0x01, 0x02 },   // f
95
    { 0x0C, 0x52, 0x52, 0x52, 0x3E },   // g
96
    { 0x7F, 0x08, 0x04, 0x04, 0x78 },   // h
97
    { 0x00, 0x44, 0x7D, 0x40, 0x00 },   // i
98
    { 0x20, 0x40, 0x44, 0x3D, 0x00 },   // j
99
    { 0x7F, 0x10, 0x28, 0x44, 0x00 },   // k
100
    { 0x00, 0x41, 0x7F, 0x40, 0x00 },   // l
101
    { 0x7C, 0x04, 0x18, 0x04, 0x78 },   // m
102
    { 0x7C, 0x08, 0x04, 0x04, 0x78 },   // n
103
    { 0x38, 0x44, 0x44, 0x44, 0x38 },   // o
104
    { 0x7C, 0x14, 0x14, 0x14, 0x08 },   // p
105
    { 0x08, 0x14, 0x14, 0x18, 0x7C },   // q
106
    { 0x7C, 0x08, 0x04, 0x04, 0x08 },   // r
107
    { 0x48, 0x54, 0x54, 0x54, 0x20 },   // s
108
    { 0x04, 0x3F, 0x44, 0x40, 0x20 },   // t
109
    { 0x3C, 0x40, 0x40, 0x20, 0x7C },   // u
110
    { 0x1C, 0x20, 0x40, 0x20, 0x1C },   // v
111
    { 0x3C, 0x40, 0x30, 0x40, 0x3C },   // w
112
    { 0x44, 0x28, 0x10, 0x28, 0x44 },   // x
113
    { 0x0C, 0x50, 0x50, 0x50, 0x3C },   // y
114
    { 0x44, 0x64, 0x54, 0x4C, 0x44 },    // z
115
    { 0x00, 0x08, 0x36, 0x41, 0x41 },   // {
116
    { 0x00, 0x00, 0x7F, 0x00, 0x00 },   // |
117
    { 0x41, 0x41, 0x36, 0x08, 0x00 },   // }
118
    { 0x02, 0x01, 0x01, 0x02, 0x01 },   // ~
119
    { 0x55, 0x2A, 0x55, 0x2A, 0x55 },   // del
120
};
121
122
123
/*
124
initializes the LCD
125
*/
126
void lcd_init(void)
127
{
128
129
#ifdef FFPP
130
131
        OLED_init();
132
133
#else
134
135
        LCDDDR |= (D_C | SCE | SDI | SCK);
136
        LCDRESETDDR |= RST;
137
138
        LCDPORT &= ~(D_C | SCE | SDI | SCK);
139
140
  SPCR |= 0x50; //=0b01010000  no SPI int, SPI en, Master, sample on rising edge, fosc/2
141
        SPSR |= 0x01;       // a continuation of the above
142
143
        LCDRESETPORT |= RST;
144
        delay_ms(10);
145
        LCDRESETPORT &= (~RST);
146
        delay_ms(100);
147
        LCDRESETPORT |= RST;
148
149
    lcd_putbyte( 0x21 );  // LCD Extended Commands.
150
    lcd_putbyte( 0xC8 );  // Set LCD Vop (Contrast).
151
    lcd_putbyte( 0x06 );  // Set Temp coefficent.
152
    lcd_putbyte( 0x13 );  // LCD bias mode 1:48.
153
    lcd_putbyte( 0x20 );  // LCD Standard Commands, Horizontal addressing mode.
154
    lcd_putbyte( 0x0C );  // LCD in normal mode.
155
156
        LCDPORT |= D_C;                //put it in init instead of main
157
158
        lcd_clear_screen();
159
#endif
160
}
161
162
/*
163
clear the lcd screen
164
*/
165
void lcd_clear_screen( void ) {
166
167
#ifdef FFPP
168
        drawclear();
169
#else
170
        int i;
171
        for (i = 0; i < 504; i++)
172
                        lcd_putbyte(0x0);
173
174
        lcd_gotoxy(0,0);
175
#endif
176
177
}
178
179
180
/*
181
print a byte on the lcd screen
182
*/
183
void lcd_putbyte(unsigned char b)
184
{
185
186
#ifndef FFPP
187
        SPDR = b;
188
        while (!(SPSR & 0x80)); /* Wait until SPI transaction is complete */
189
#endif
190
191
}
192
193
/*
194
print a character on the lcd
195
*/
196
void lcd_putchar(char c)
197
{
198
199
#ifndef FFPP
200
        int i;
201
202
        for (i = 0; i < 5; i++)
203
                lcd_putbyte(FontLookup[c-32][i]);
204
        lcd_putbyte(0);
205
#endif
206
207
}
208
209
/*
210
print an entire string to the lcd
211
*/
212
void lcd_putstr(char *s)
213
{
214
        char *t = s;
215
        while (*t != 0)
216
        {
217
                lcd_putchar(*t);
218
                t++;
219
        }
220
}
221
222
/*
223
go to coordinate x, y
224
y: vertically - 1 char
225
x: horizontally - 1 pixel
226

227
multiply x by 6 if want to move 1 entire character
228

229
origin (0,0) is at top left corner of lcd screen
230
*/
231
void lcd_gotoxy(int x, int y)
232
{
233
234
#ifndef FFPP
235
  LCDPORT &= ~(D_C);
236
  lcd_putbyte(0x40 | (y & 0x07));
237
  lcd_putbyte(0x80 | (x & 0x7f));
238
  LCDPORT |= D_C;
239
#endif
240
241
}
242
243
/*
244
prints an int to the lcd
245

246
code adapted from Chris Efstathiou's code (hendrix@otenet.gr)
247
*/
248
void lcd_putint(int value ) {
249
        unsigned char lcd_data[6]={'0','0','0','0','0','0' }, position=sizeof(lcd_data), radix=10;
250
251
        /* convert int to ascii  */
252
        if(value<0) { lcd_putchar('-'); value=-value; }
253
        do { position--; *(lcd_data+position)=(value%radix)+'0'; value/=radix;  } while(value);
254
255
256
        /* start displaying the number */
257
        for(;position<=(sizeof(lcd_data)-1);position++)
258
          {
259
260
            lcd_putchar(lcd_data[position]);
261
          }
262
263
        return;
264
}