Project

General

Profile

Revision 277

more cleanup

View differences:

lcd.c
58 58
*/
59 59
static const unsigned char FontLookup [][5] =
60 60
{
61
    { 0x00, 0x00, 0x00, 0x00, 0x00 },  // sp
62
    { 0x00, 0x00, 0x5f, 0x00, 0x00 },   // !
63
    { 0x00, 0x07, 0x00, 0x07, 0x00 },   // "
64
    { 0x14, 0x7f, 0x14, 0x7f, 0x14 },   // #
65
    { 0x24, 0x2a, 0x7f, 0x2a, 0x12 },   // $
66
    { 0x23, 0x13, 0x08, 0x64, 0x62 },   // %
67
    { 0x36, 0x49, 0x55, 0x22, 0x50 },   // &
68
    { 0x00, 0x05, 0x03, 0x00, 0x00 },   // '
69
    { 0x00, 0x1c, 0x22, 0x41, 0x00 },   // (
70
    { 0x00, 0x41, 0x22, 0x1c, 0x00 },   // )
71
    { 0x14, 0x08, 0x3E, 0x08, 0x14 },   // *
72
    { 0x08, 0x08, 0x3E, 0x08, 0x08 },   // +
73
    { 0x00, 0x00, 0x50, 0x30, 0x00 },   // ,
74
    { 0x10, 0x10, 0x10, 0x10, 0x10 },   // -
75
    { 0x00, 0x60, 0x60, 0x00, 0x00 },   // .
76
    { 0x20, 0x10, 0x08, 0x04, 0x02 },   // /
77
    { 0x3E, 0x51, 0x49, 0x45, 0x3E },   // 0
78
    { 0x00, 0x42, 0x7F, 0x40, 0x00 },   // 1
79
    { 0x42, 0x61, 0x51, 0x49, 0x46 },   // 2
80
    { 0x21, 0x41, 0x45, 0x4B, 0x31 },   // 3
81
    { 0x18, 0x14, 0x12, 0x7F, 0x10 },   // 4
82
    { 0x27, 0x45, 0x45, 0x45, 0x39 },   // 5
83
    { 0x3C, 0x4A, 0x49, 0x49, 0x30 },   // 6
84
    { 0x01, 0x71, 0x09, 0x05, 0x03 },   // 7
85
    { 0x36, 0x49, 0x49, 0x49, 0x36 },   // 8
86
    { 0x06, 0x49, 0x49, 0x29, 0x1E },   // 9
87
    { 0x00, 0x36, 0x36, 0x00, 0x00 },   // :
88
    { 0x00, 0x56, 0x36, 0x00, 0x00 },   // ;
89
    { 0x08, 0x14, 0x22, 0x41, 0x00 },   // <
90
    { 0x14, 0x14, 0x14, 0x14, 0x14 },   // =
91
    { 0x00, 0x41, 0x22, 0x14, 0x08 },   // >
92
    { 0x02, 0x01, 0x51, 0x09, 0x06 },   // ?
93
    { 0x32, 0x49, 0x59, 0x51, 0x3E },   // @
94
    { 0x7E, 0x11, 0x11, 0x11, 0x7E },   // A
95
    { 0x7F, 0x49, 0x49, 0x49, 0x36 },   // B
96
    { 0x3E, 0x41, 0x41, 0x41, 0x22 },   // C
97
    { 0x7F, 0x41, 0x41, 0x22, 0x1C },   // D
98
    { 0x7F, 0x49, 0x49, 0x49, 0x41 },   // E
99
    { 0x7F, 0x09, 0x09, 0x09, 0x01 },   // F
100
    { 0x3E, 0x41, 0x49, 0x49, 0x7A },   // G
101
    { 0x7F, 0x08, 0x08, 0x08, 0x7F },   // H
102
    { 0x00, 0x41, 0x7F, 0x41, 0x00 },   // I
103
    { 0x20, 0x40, 0x41, 0x3F, 0x01 },   // J
104
    { 0x7F, 0x08, 0x14, 0x22, 0x41 },   // K
105
    { 0x7F, 0x40, 0x40, 0x40, 0x40 },   // L
106
    { 0x7F, 0x02, 0x0C, 0x02, 0x7F },   // M
107
    { 0x7F, 0x04, 0x08, 0x10, 0x7F },   // N
108
    { 0x3E, 0x41, 0x41, 0x41, 0x3E },   // O
109
    { 0x7F, 0x09, 0x09, 0x09, 0x06 },   // P
110
    { 0x3E, 0x41, 0x51, 0x21, 0x5E },   // Q
111
    { 0x7F, 0x09, 0x19, 0x29, 0x46 },   // R
112
    { 0x46, 0x49, 0x49, 0x49, 0x31 },   // S
113
    { 0x01, 0x01, 0x7F, 0x01, 0x01 },   // T
114
    { 0x3F, 0x40, 0x40, 0x40, 0x3F },   // U
115
    { 0x1F, 0x20, 0x40, 0x20, 0x1F },   // V
116
    { 0x3F, 0x40, 0x38, 0x40, 0x3F },   // W
117
    { 0x63, 0x14, 0x08, 0x14, 0x63 },   // X
118
    { 0x07, 0x08, 0x70, 0x08, 0x07 },   // Y
119
    { 0x61, 0x51, 0x49, 0x45, 0x43 },   // Z
120
    { 0x00, 0x7F, 0x41, 0x41, 0x00 },   // [
121
    { 0x02, 0x04, 0x08, 0x10, 0x20 },   // backslash
122
    { 0x00, 0x41, 0x41, 0x7F, 0x00 },   // ]
123
    { 0x04, 0x02, 0x01, 0x02, 0x04 },   // ^
124
    { 0x40, 0x40, 0x40, 0x40, 0x40 },   // _
125
    { 0x00, 0x01, 0x02, 0x04, 0x00 },   // '
126
    { 0x20, 0x54, 0x54, 0x54, 0x78 },   // a
127
    { 0x7F, 0x48, 0x44, 0x44, 0x38 },   // b
128
    { 0x38, 0x44, 0x44, 0x44, 0x20 },   // c
129
    { 0x38, 0x44, 0x44, 0x48, 0x7F },   // d
130
    { 0x38, 0x54, 0x54, 0x54, 0x18 },   // e
131
    { 0x08, 0x7E, 0x09, 0x01, 0x02 },   // f
132
    { 0x0C, 0x52, 0x52, 0x52, 0x3E },   // g
133
    { 0x7F, 0x08, 0x04, 0x04, 0x78 },   // h
134
    { 0x00, 0x44, 0x7D, 0x40, 0x00 },   // i
135
    { 0x20, 0x40, 0x44, 0x3D, 0x00 },   // j
136
    { 0x7F, 0x10, 0x28, 0x44, 0x00 },   // k
137
    { 0x00, 0x41, 0x7F, 0x40, 0x00 },   // l
138
    { 0x7C, 0x04, 0x18, 0x04, 0x78 },   // m
139
    { 0x7C, 0x08, 0x04, 0x04, 0x78 },   // n
140
    { 0x38, 0x44, 0x44, 0x44, 0x38 },   // o
141
    { 0x7C, 0x14, 0x14, 0x14, 0x08 },   // p
142
    { 0x08, 0x14, 0x14, 0x18, 0x7C },   // q
143
    { 0x7C, 0x08, 0x04, 0x04, 0x08 },   // r
144
    { 0x48, 0x54, 0x54, 0x54, 0x20 },   // s
145
    { 0x04, 0x3F, 0x44, 0x40, 0x20 },   // t
146
    { 0x3C, 0x40, 0x40, 0x20, 0x7C },   // u
147
    { 0x1C, 0x20, 0x40, 0x20, 0x1C },   // v
148
    { 0x3C, 0x40, 0x30, 0x40, 0x3C },   // w
149
    { 0x44, 0x28, 0x10, 0x28, 0x44 },   // x
150
    { 0x0C, 0x50, 0x50, 0x50, 0x3C },   // y
151
    { 0x44, 0x64, 0x54, 0x4C, 0x44 },    // z
152
    { 0x00, 0x08, 0x36, 0x41, 0x41 },   // {
153
    { 0x00, 0x00, 0x7F, 0x00, 0x00 },   // |
154
    { 0x41, 0x41, 0x36, 0x08, 0x00 },   // }
155
    { 0x02, 0x01, 0x01, 0x02, 0x01 },   // ~
156
    { 0x55, 0x2A, 0x55, 0x2A, 0x55 },   // del
61
  { 0x00, 0x00, 0x00, 0x00, 0x00 },  // sp
62
  { 0x00, 0x00, 0x5f, 0x00, 0x00 },   // !
63
  { 0x00, 0x07, 0x00, 0x07, 0x00 },   // "
64
  { 0x14, 0x7f, 0x14, 0x7f, 0x14 },   // #
65
  { 0x24, 0x2a, 0x7f, 0x2a, 0x12 },   // $
66
  { 0x23, 0x13, 0x08, 0x64, 0x62 },   // %
67
  { 0x36, 0x49, 0x55, 0x22, 0x50 },   // &
68
  { 0x00, 0x05, 0x03, 0x00, 0x00 },   // '
69
  { 0x00, 0x1c, 0x22, 0x41, 0x00 },   // (
70
  { 0x00, 0x41, 0x22, 0x1c, 0x00 },   // )
71
  { 0x14, 0x08, 0x3E, 0x08, 0x14 },   // *
72
  { 0x08, 0x08, 0x3E, 0x08, 0x08 },   // +
73
  { 0x00, 0x00, 0x50, 0x30, 0x00 },   // ,
74
  { 0x10, 0x10, 0x10, 0x10, 0x10 },   // -
75
  { 0x00, 0x60, 0x60, 0x00, 0x00 },   // .
76
  { 0x20, 0x10, 0x08, 0x04, 0x02 },   // /
77
  { 0x3E, 0x51, 0x49, 0x45, 0x3E },   // 0
78
  { 0x00, 0x42, 0x7F, 0x40, 0x00 },   // 1
79
  { 0x42, 0x61, 0x51, 0x49, 0x46 },   // 2
80
  { 0x21, 0x41, 0x45, 0x4B, 0x31 },   // 3
81
  { 0x18, 0x14, 0x12, 0x7F, 0x10 },   // 4
82
  { 0x27, 0x45, 0x45, 0x45, 0x39 },   // 5
83
  { 0x3C, 0x4A, 0x49, 0x49, 0x30 },   // 6
84
  { 0x01, 0x71, 0x09, 0x05, 0x03 },   // 7
85
  { 0x36, 0x49, 0x49, 0x49, 0x36 },   // 8
86
  { 0x06, 0x49, 0x49, 0x29, 0x1E },   // 9
87
  { 0x00, 0x36, 0x36, 0x00, 0x00 },   // :
88
  { 0x00, 0x56, 0x36, 0x00, 0x00 },   // ;
89
  { 0x08, 0x14, 0x22, 0x41, 0x00 },   // <
90
  { 0x14, 0x14, 0x14, 0x14, 0x14 },   // =
91
  { 0x00, 0x41, 0x22, 0x14, 0x08 },   // >
92
  { 0x02, 0x01, 0x51, 0x09, 0x06 },   // ?
93
  { 0x32, 0x49, 0x59, 0x51, 0x3E },   // @
94
  { 0x7E, 0x11, 0x11, 0x11, 0x7E },   // A
95
  { 0x7F, 0x49, 0x49, 0x49, 0x36 },   // B
96
  { 0x3E, 0x41, 0x41, 0x41, 0x22 },   // C
97
  { 0x7F, 0x41, 0x41, 0x22, 0x1C },   // D
98
  { 0x7F, 0x49, 0x49, 0x49, 0x41 },   // E
99
  { 0x7F, 0x09, 0x09, 0x09, 0x01 },   // F
100
  { 0x3E, 0x41, 0x49, 0x49, 0x7A },   // G
101
  { 0x7F, 0x08, 0x08, 0x08, 0x7F },   // H
102
  { 0x00, 0x41, 0x7F, 0x41, 0x00 },   // I
103
  { 0x20, 0x40, 0x41, 0x3F, 0x01 },   // J
104
  { 0x7F, 0x08, 0x14, 0x22, 0x41 },   // K
105
  { 0x7F, 0x40, 0x40, 0x40, 0x40 },   // L
106
  { 0x7F, 0x02, 0x0C, 0x02, 0x7F },   // M
107
  { 0x7F, 0x04, 0x08, 0x10, 0x7F },   // N
108
  { 0x3E, 0x41, 0x41, 0x41, 0x3E },   // O
109
  { 0x7F, 0x09, 0x09, 0x09, 0x06 },   // P
110
  { 0x3E, 0x41, 0x51, 0x21, 0x5E },   // Q
111
  { 0x7F, 0x09, 0x19, 0x29, 0x46 },   // R
112
  { 0x46, 0x49, 0x49, 0x49, 0x31 },   // S
113
  { 0x01, 0x01, 0x7F, 0x01, 0x01 },   // T
114
  { 0x3F, 0x40, 0x40, 0x40, 0x3F },   // U
115
  { 0x1F, 0x20, 0x40, 0x20, 0x1F },   // V
116
  { 0x3F, 0x40, 0x38, 0x40, 0x3F },   // W
117
  { 0x63, 0x14, 0x08, 0x14, 0x63 },   // X
118
  { 0x07, 0x08, 0x70, 0x08, 0x07 },   // Y
119
  { 0x61, 0x51, 0x49, 0x45, 0x43 },   // Z
120
  { 0x00, 0x7F, 0x41, 0x41, 0x00 },   // [
121
  { 0x02, 0x04, 0x08, 0x10, 0x20 },   // backslash
122
  { 0x00, 0x41, 0x41, 0x7F, 0x00 },   // ]
123
  { 0x04, 0x02, 0x01, 0x02, 0x04 },   // ^
124
  { 0x40, 0x40, 0x40, 0x40, 0x40 },   // _
125
  { 0x00, 0x01, 0x02, 0x04, 0x00 },   // '
126
  { 0x20, 0x54, 0x54, 0x54, 0x78 },   // a
127
  { 0x7F, 0x48, 0x44, 0x44, 0x38 },   // b
128
  { 0x38, 0x44, 0x44, 0x44, 0x20 },   // c
129
  { 0x38, 0x44, 0x44, 0x48, 0x7F },   // d
130
  { 0x38, 0x54, 0x54, 0x54, 0x18 },   // e
131
  { 0x08, 0x7E, 0x09, 0x01, 0x02 },   // f
132
  { 0x0C, 0x52, 0x52, 0x52, 0x3E },   // g
133
  { 0x7F, 0x08, 0x04, 0x04, 0x78 },   // h
134
  { 0x00, 0x44, 0x7D, 0x40, 0x00 },   // i
135
  { 0x20, 0x40, 0x44, 0x3D, 0x00 },   // j
136
  { 0x7F, 0x10, 0x28, 0x44, 0x00 },   // k
137
  { 0x00, 0x41, 0x7F, 0x40, 0x00 },   // l
138
  { 0x7C, 0x04, 0x18, 0x04, 0x78 },   // m
139
  { 0x7C, 0x08, 0x04, 0x04, 0x78 },   // n
140
  { 0x38, 0x44, 0x44, 0x44, 0x38 },   // o
141
  { 0x7C, 0x14, 0x14, 0x14, 0x08 },   // p
142
  { 0x08, 0x14, 0x14, 0x18, 0x7C },   // q
143
  { 0x7C, 0x08, 0x04, 0x04, 0x08 },   // r
144
  { 0x48, 0x54, 0x54, 0x54, 0x20 },   // s
145
  { 0x04, 0x3F, 0x44, 0x40, 0x20 },   // t
146
  { 0x3C, 0x40, 0x40, 0x20, 0x7C },   // u
147
  { 0x1C, 0x20, 0x40, 0x20, 0x1C },   // v
148
  { 0x3C, 0x40, 0x30, 0x40, 0x3C },   // w
149
  { 0x44, 0x28, 0x10, 0x28, 0x44 },   // x
150
  { 0x0C, 0x50, 0x50, 0x50, 0x3C },   // y
151
  { 0x44, 0x64, 0x54, 0x4C, 0x44 },    // z
152
  { 0x00, 0x08, 0x36, 0x41, 0x41 },   // {
153
  { 0x00, 0x00, 0x7F, 0x00, 0x00 },   // |
154
  { 0x41, 0x41, 0x36, 0x08, 0x00 },   // }
155
  { 0x02, 0x01, 0x01, 0x02, 0x01 },   // ~
156
  { 0x55, 0x2A, 0x55, 0x2A, 0x55 },   // del
157 157
};
158 158

  
159 159

  
......
172 172
 **/
173 173
void lcd_init(void)
174 174
{
175
	LCDDDR |= (SCE | SDI | SCK);
176
	LCDRESETDDR |= (RST|D_C);
175
  LCDDDR |= (SCE | SDI | SCK);
176
  LCDRESETDDR |= (RST|D_C);
177 177

  
178
	LCDPORT &= ~( SCE | SDI | SCK);
179
	LCDRESETPORT &=~(D_C);
178
  LCDPORT &= ~( SCE | SDI | SCK);
179
  LCDRESETPORT &=~(D_C);
180 180

  
181
	SPCR |= 0x50;//0b01010000; // no SPI int, SPI en, Master, sample on rising edge, fosc/2
182
	SPSR |= 0x01;       // a continuation of the above
181
  SPCR |= 0x50;//0b01010000; // no SPI int, SPI en, Master, sample on rising edge, fosc/2
182
  SPSR |= 0x01;       // a continuation of the above
183 183

  
184
	LCDRESETPORT |= RST;
185
	delay_ms(10);
186
	LCDRESETPORT &= (~RST);
187
	delay_ms(100);
188
	LCDRESETPORT |= RST;
184
  LCDRESETPORT |= RST;
185
  delay_ms(10);
186
  LCDRESETPORT &= (~RST);
187
  delay_ms(100);
188
  LCDRESETPORT |= RST;
189 189

  
190
	lcd_putbyte( 0x21 );  // LCD Extended Commands.
191
	lcd_putbyte( 0xC8 );  // Set LCD Vop (Contrast).
192
	lcd_putbyte( 0x06 );  // Set Temp coefficent.
193
	lcd_putbyte( 0x13 );  // LCD bias mode 1:48.
194
	lcd_putbyte( 0x20 );  // LCD Standard Commands, Horizontal addressing mode.
195
	lcd_putbyte( 0x0C );  // LCD in normal mode.
190
  lcd_putbyte( 0x21 );  // LCD Extended Commands.
191
  lcd_putbyte( 0xC8 );  // Set LCD Vop (Contrast).
192
  lcd_putbyte( 0x06 );  // Set Temp coefficent.
193
  lcd_putbyte( 0x13 );  // LCD bias mode 1:48.
194
  lcd_putbyte( 0x20 );  // LCD Standard Commands, Horizontal addressing mode.
195
  lcd_putbyte( 0x0C );  // LCD in normal mode.
196 196

  
197
	LCDRESETPORT |= D_C;		//put it in init instead of main
197
  LCDRESETPORT |= D_C;    //put it in init instead of main
198 198

  
199
	lcd_clear_screen();
199
  lcd_clear_screen();
200 200
}
201 201

  
202 202
/**
......
205 205
 * @see lcd_init
206 206
 **/
207 207
void lcd_clear_screen( void ) {
208
	int i;
209
	for (i = 0; i < 504; i++)
210
		lcd_putbyte(0x0);
208
  int i;
209
  for (i = 0; i < 504; i++) {
210
    lcd_putbyte(0x0);
211
  }
211 212

  
212
	lcd_gotoxy(0,0);
213
  lcd_gotoxy(0,0);
213 214
}
214 215

  
215 216
/**
......
222 223
 **/
223 224
void lcd_putc(char c)
224 225
{
225
	int i;
226
  int i;
226 227

  
227
	for (i = 0; i < 5; i++)
228
		lcd_putbyte(FontLookup[c-32][i]);
229
	lcd_putbyte(0);
228
  for (i = 0; i < 5; i++) {
229
    lcd_putbyte(FontLookup[c-32][i]);
230
  }
231

  
232
  lcd_putbyte(0);
230 233
}
231 234

  
232 235
/*
......
234 237
*/
235 238
void lcd_puts(char *s)
236 239
{
237
	char *t = s;
238
	while (*t != 0)
239
	{
240
		lcd_putc(*t);
241
		t++;
242
	}
240
  char *t = s;
241
  while (*t != 0) {
242
    lcd_putc(*t);
243
    t++;
244
  }
243 245
}
244 246

  
245 247
/*
......
263 265
 **/
264 266
void lcd_gotoxy(int x, int y)
265 267
{
266
	LCDRESETPORT &= ~(D_C);
267
	lcd_putbyte(0x40 | (y & 0x07));
268
	lcd_putbyte(0x80 | (x & 0x7f));
269
	LCDRESETPORT |= D_C;
268
  LCDRESETPORT &= ~(D_C);
269
  lcd_putbyte(0x40 | (y & 0x07));
270
  lcd_putbyte(0x80 | (x & 0x7f));
271
  LCDRESETPORT |= D_C;
270 272
}
271 273

  
272 274
/*
......
285 287
 **/
286 288
void lcd_puti(int value )
287 289
{
288
	unsigned char lcd_data[6]={'0','0','0','0','0','0' }, position=sizeof(lcd_data), radix=10;
290
  unsigned char lcd_data[6]={'0','0','0','0','0','0' }, position=sizeof(lcd_data), radix=10;
289 291

  
290
        /* convert int to ascii  */
291
        if(value<0) { lcd_putc('-'); value=-value; }
292
        do { position--; *(lcd_data+position)=(value%radix)+'0'; value/=radix;  } while(value);
292
  /* convert int to ascii  */
293
  if (value<0) {
294
    lcd_putc('-');
295
    value=-value;
296
  }
293 297

  
298
  do { position--; *(lcd_data+position)=(value%radix)+'0'; value/=radix;  } while(value);
294 299

  
295
        /* start displaying the number */
296
        for(;position<=(sizeof(lcd_data)-1);position++)
297
		lcd_putc(lcd_data[position]);
300
  /* start displaying the number */
301
  for(; position <= (sizeof(lcd_data)-1); position++) {
302
    lcd_putc(lcd_data[position]);
303
  }
298 304

  
299
	return;
305
  return;
300 306
}
301 307

  
302 308
/** @} **/ //end defgroup
303 309

  
304 310
void lcd_putbyte(unsigned char b)
305 311
{
306
	SPDR = b;
307
	while (!(SPSR & 0x80)); /* Wait until SPI transaction is complete */
312
  SPDR = b;
313

  
314
  /* Wait until SPI transaction is complete */
315
  while (!(SPSR & 0x80));
308 316
}
309

  

Also available in: Unified diff