Project

General

Profile

Revision 378

Added by Jason knichel almost 15 years ago

fixed style problems

View differences:

lcd.c
54 54

  
55 55
//**************************************Old shit below!*****************
56 56
/*
57
FontLookup - a lookup table for all characters
57
  FontLookup - a lookup table for all characters
58 58
*/
59 59
static const unsigned char FontLookup [][5] =
60
{
60
  {
61 61
    { 0x00, 0x00, 0x00, 0x00, 0x00 },  // sp
62 62
    { 0x00, 0x00, 0x5f, 0x00, 0x00 },   // !
63 63
    { 0x00, 0x07, 0x00, 0x07, 0x00 },   // "
......
154 154
    { 0x41, 0x41, 0x36, 0x08, 0x00 },   // }
155 155
    { 0x02, 0x01, 0x01, 0x02, 0x01 },   // ~
156 156
    { 0x55, 0x2A, 0x55, 0x2A, 0x55 },   // del
157
};
157
  };
158 158

  
159 159

  
160 160
/**
......
170 170
 * Initializes the LCD. Must be called before any other
171 171
 * LCD functions.
172 172
 **/
173
void lcd_init(void)
174
{
175
	LCDDDR |= (SCE | SDI | SCK);
176
	LCDRESETDDR |= (RST|D_C);
173
void lcd_init(void) {
174
  LCDDDR |= (SCE | SDI | SCK);
175
  LCDRESETDDR |= (RST|D_C);
177 176

  
178
	LCDPORT &= ~( SCE | SDI | SCK);
179
	LCDRESETPORT &=~(D_C);
177
  LCDPORT &= ~( SCE | SDI | SCK);
178
  LCDRESETPORT &=~(D_C);
180 179
  
181
	SPCR |= 0x50;//0b01010000; // no SPI int, SPI en, Master, sample on rising edge, fosc/2
182
	SPSR |= 0x01;       // a continuation of the above
180
  SPCR |= 0x50;//0b01010000; // no SPI int, SPI en, Master, sample on rising edge, fosc/2
181
  SPSR |= 0x01;       // a continuation of the above
183 182

  
184
	LCDRESETPORT |= RST;
185
	delay_ms(10);
186
	LCDRESETPORT &= (~RST);
187
	delay_ms(100);
188
	LCDRESETPORT |= RST;
183
  LCDRESETPORT |= RST;
184
  delay_ms(10);
185
  LCDRESETPORT &= (~RST);
186
  delay_ms(100);
187
  LCDRESETPORT |= RST;
189 188
	
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.
189
  lcd_putbyte( 0x21 );  // LCD Extended Commands.
190
  lcd_putbyte( 0xC8 );  // Set LCD Vop (Contrast).
191
  lcd_putbyte( 0x06 );  // Set Temp coefficent.
192
  lcd_putbyte( 0x13 );  // LCD bias mode 1:48.
193
  lcd_putbyte( 0x20 );  // LCD Standard Commands, Horizontal addressing mode.
194
  lcd_putbyte( 0x0C );  // LCD in normal mode.
196 195
	
197
	LCDRESETPORT |= D_C;		//put it in init instead of main
196
  LCDRESETPORT |= D_C;		//put it in init instead of main
198 197
	
199
	lcd_clear_screen();
198
  lcd_clear_screen();
200 199
}
201 200

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

  
215 214
/**
......
220 219
 *
221 220
 * @see lcd_init
222 221
 **/
223
void lcd_putc(char c)
224
{
225
	int i;
222
void lcd_putc(char c) {
223
  int i;
226 224
	
227
	for (i = 0; i < 5; i++)
228
		lcd_putbyte(FontLookup[c-32][i]);
229
	lcd_putbyte(0);
225
  for (i = 0; i < 5; i++)
226
    lcd_putbyte(FontLookup[c-32][i]);
227
  lcd_putbyte(0);
230 228
}
231 229

  
232 230
/*
233
print an entire string to the lcd
231
  print an entire string to the lcd
234 232
*/
235
void lcd_puts(char *s)
236
{
237
	char *t = s;
238
	while (*t != 0)
239
	{
240
		lcd_putc(*t);
241
		t++;
242
	}
233
void lcd_puts(char *s) {
234
  char *t = s;
235
  while (*t != 0) {
236
    lcd_putc(*t);
237
    t++;
238
  }
243 239
}
244 240

  
245 241
/*
246
go to coordinate x, y
247
y: vertically - 1 char
248
x: horizontally - 1 pixel
242
  go to coordinate x, y
243
  y: vertically - 1 char
244
  x: horizontally - 1 pixel
249 245

  
250
multiply x by 6 if want to move 1 entire character
246
  multiply x by 6 if want to move 1 entire character
251 247

  
252
origin (0,0) is at top left corner of lcd screen
248
  origin (0,0) is at top left corner of lcd screen
253 249
*/
254 250

  
255 251
/**
......
261 257
 *
262 258
 * @see lcd_init
263 259
 **/
264
void lcd_gotoxy(int x, int y)
265
{
266
	LCDRESETPORT &= ~(D_C);
267
	lcd_putbyte(0x40 | (y & 0x07));
268
	lcd_putbyte(0x80 | (x & 0x7f));
269
	LCDRESETPORT |= D_C;
260
void lcd_gotoxy(int x, int y) {
261
  LCDRESETPORT &= ~(D_C);
262
  lcd_putbyte(0x40 | (y & 0x07));
263
  lcd_putbyte(0x80 | (x & 0x7f));
264
  LCDRESETPORT |= D_C;
270 265
}
271 266

  
272 267
/*
273
prints an int to the lcd
268
  prints an int to the lcd
274 269

  
275
code adapted from Chris Efstathiou's code (hendrix@otenet.gr)
270
  code adapted from Chris Efstathiou's code (hendrix@otenet.gr)
276 271
*/
277 272

  
278 273
/**
......
283 278
 *
284 279
 * @see lcd_init
285 280
 **/
286
void lcd_puti(int value )
287
{
288
	unsigned char lcd_data[6]={'0','0','0','0','0','0' }, position=sizeof(lcd_data), radix=10; 
281
void lcd_puti(int value ) {
282
  unsigned char lcd_data[6]={'0','0','0','0','0','0' }, position=sizeof(lcd_data), radix=10; 
289 283

  
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); 
284
  /* convert int to ascii  */ 
285
  if(value<0) { 
286
    lcd_putc('-'); 
287
    value=-value; 
288
  }    
289
  do { 
290
    position--; 
291
    *(lcd_data+position)=(value%radix)+'0'; 
292
    value/=radix;  
293
  } while(value); 
293 294

  
294 295
    
295
        /* start displaying the number */
296
        for(;position<=(sizeof(lcd_data)-1);position++)
297
		lcd_putc(lcd_data[position]);
296
  /* start displaying the number */
297
  for(;position<=(sizeof(lcd_data)-1);position++)
298
    lcd_putc(lcd_data[position]);
298 299

  
299
	return;
300
  return;
300 301
}
301 302

  
302 303
/** @} **/ //end defgroup
303 304

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

  

Also available in: Unified diff