OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [MSP430X_MSP430F5438_IAR/] [MSP-EXP430F5438_HAL/] [hal_lcd.c] - Blame information for rev 605

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 584 jeremybenn
/**
2
 * @file  hal_lcd.c
3
 *
4
 * Copyright 2010 Texas Instruments, Inc.
5
***************************************************************************/
6
 
7
#include "msp430.h"
8
#include "hal_MSP-EXP430F5438.h"
9
#include "hal_lcd_fonts.h"
10
 
11
unsigned char LcdInitMacro[]={
12
            0x74,0x00,0x00,0x76,0x00,0x01,  // R00 start oscillation
13
            0x74,0x00,0x01,0x76,0x00,0x0D,  // R01 driver output control
14
            0x74,0x00,0x02,0x76,0x00,0x4C,  // R02 LCD - driving waveform control
15
            0x74,0x00,0x03,0x76,0x12,0x14,  // R03 Power control
16
            0x74,0x00,0x04,0x76,0x04,0x66,  // R04 Contrast control
17
            0x74,0x00,0x05,0x76,0x00,0x10,  // R05 Entry mode
18
            0x74,0x00,0x06,0x76,0x00,0x00,  // R06 RAM data write mask
19
            0x74,0x00,0x07,0x76,0x00,0x15,  // R07 Display control
20
            0x74,0x00,0x08,0x76,0x00,0x03,  // R08 Cursor Control
21
            0x74,0x00,0x09,0x76,0x00,0x00,  // R09 RAM data write mask
22
            0x74,0x00,0x0A,0x76,0x00,0x15,  // R0A
23
            0x74,0x00,0x0B,0x76,0x00,0x03,  // R0B Horizontal Cursor Position
24
            0x74,0x00,0x0C,0x76,0x00,0x03,  // R0C Vertical Cursor Position
25
            0x74,0x00,0x0D,0x76,0x00,0x00,  // R0D
26
            0x74,0x00,0x0E,0x76,0x00,0x15,  // R0E
27
            0x74,0x00,0x0F,0x76,0x00,0x03,  // R0F
28
            0x74,0x00,0x10,0x76,0x00,0x15,  // R0E
29
            0x74,0x00,0x11,0x76,0x00,0x03,  // R0F
30
};
31
 
32
unsigned char Read_Block_Address_Macro[]= {0x74,0x00,0x12,0x77,0x00,0x00};
33
unsigned char Draw_Block_Value_Macro[]={0x74,0x00,0x12,0x76,0xFF,0xFF};
34
unsigned char Draw_Block_Address_Macro[]={0x74,0x00,0x11,0x76,0x00,0x00};
35
 
36
unsigned int  LcdAddress = 0, LcdTableAddress = 0;
37
unsigned char contrast   = 0x66;
38
unsigned char backlight  = 8;
39
int LCD_MEM[110*17];            //This array stores a copy of all data on the LCD
40
                                                        //screen. If memory is an issue though, this array
41
                                                        //can be eliminated and the halLcdReadBlock()
42
                                                        //command can be used instead whenever you are
43
                                                        //manipulating the currently displayed data.
44
 
45
/**********************************************************************//**
46
 * @brief  Sends 3+3 bytes of data to the LCD using the format specified
47
 *         by the LCD Guide.
48
 *
49
 * @param  Data[] Data array for transmission
50
 *
51
 * @return none
52
 *************************************************************************/
53
void halLcdSendCommand(unsigned char Data[])
54
{
55
  unsigned char i;
56
 
57
  LCD_CS_RST_OUT &= ~LCD_CS_PIN;            //CS = 0 --> Start Transfer
58
  for ( i = 0; i < 6; i++ )
59
  {
60
    while (!(UCB2IFG & UCTXIFG));           // Wait for TXIFG
61
    UCB2TXBUF = Data[i];                    // Load data
62
 
63
    if (i == 2)                             //Pull CS up after 3 bytes
64
    {
65
      while (UCB2STAT & UCBUSY);
66
      LCD_CS_RST_OUT |= LCD_CS_PIN;         //CS = 1 --> Stop Transfer
67
      LCD_CS_RST_OUT &= ~LCD_CS_PIN;        //CS = 0 --> Start Transfer 
68
    }
69
  }
70
  while (UCB2STAT & UCBUSY);
71
  LCD_CS_RST_OUT |= LCD_CS_PIN;             //CS = 1 --> Stop Transfer
72
}
73
 
74
/**********************************************************************//**
75
 * @brief  Initializes the USCI module, LCD device for communication.
76
 *
77
 * - Sets up the SPI2C Communication Module
78
 * - Performs Hitachi LCD Initialization Procedure
79
 *
80
 * @param  none
81
 *
82
 * @return none
83
 *************************************************************************/
84
void halLcdInit(void)
85
{
86
  volatile unsigned int i=0;
87
 
88
  LCD_CS_RST_OUT |= LCD_CS_PIN | LCD_RESET_PIN ;
89
  LCD_CS_RST_DIR |= LCD_CS_PIN | LCD_RESET_PIN ;
90
 
91
  LCD_BACKLT_SEL |= LCD_BACKLIGHT_PIN;
92
 
93
  LCD_CS_RST_OUT &= ~LCD_RESET_PIN;         // Reset LCD
94
  __delay_cycles(0x47FF);                   //Reset Pulse
95
  LCD_CS_RST_OUT |= LCD_RESET_PIN;
96
 
97
  // UCLK,MOSI setup, SOMI cleared
98
  LCD_SPI_SEL |= LCD_MOSI_PIN + LCD_CLK_PIN;
99
  LCD_SPI_SEL &= ~LCD_MISO_PIN;
100
  LCD_SPI_DIR &= ~(LCD_MISO_PIN + LCD_MOSI_PIN);            // Pin direction controlled by module,
101
                                                            // Set both pins to input as default
102
 
103
  // Initialize the USCI_B2 module for SPI operation
104
  UCB2CTL1 = UCSWRST;                       // Hold USCI in SW reset mode while configuring it
105
  UCB2CTL0 = UCMST+UCSYNC+UCCKPL+UCMSB;     // 3-pin, 8-bit SPI master
106
  UCB2CTL1 |= UCSSEL_2;                     // SMCLK
107
  UCB2BR0 = 4;                              // Note: Do not exceed D/S spec for UCLK!
108
  UCB2BR1 = 0;
109
  UCB2CTL1 &= ~UCSWRST;                     // Release USCI state machine
110
  UCB2IFG &= ~UCRXIFG;
111
 
112
  // Wake-up the LCD as per datasheet specifications
113
  halLcdActive();
114
 
115
  // LCD Initialization Routine Using Predefined Macros
116
  halLcdSendCommand(&LcdInitMacro[ 1 * 6 ]);
117
  halLcdSendCommand(&LcdInitMacro[ 2 * 6 ]);
118
  halLcdSendCommand(&LcdInitMacro[ 4 * 6 ]);
119
  halLcdSendCommand(&LcdInitMacro[ 5 * 6 ]);
120
  halLcdSendCommand(&LcdInitMacro[ 6 * 6 ]);
121
  halLcdSendCommand(&LcdInitMacro[ 7 * 6 ]);
122
 
123
}
124
 
125
/**********************************************************************//**
126
 * @brief  Shuts down the LCD display and hdisables the USCI communication.
127
 *
128
 * @param  none
129
 *
130
 * @return none
131
 *************************************************************************/
132
void halLcdShutDown(void)
133
{
134
  halLcdStandby();
135
 
136
  LCD_CS_RST_DIR |= LCD_CS_PIN | LCD_RESET_PIN ;
137
  LCD_CS_RST_OUT &= ~(LCD_CS_PIN | LCD_RESET_PIN );
138
  LCD_CS_RST_OUT &= ~LCD_RESET_PIN;
139
 
140
  LCD_SPI_SEL &= ~(LCD_MOSI_PIN + LCD_CLK_PIN + LCD_MISO_PIN);
141
  LCD_CS_RST_DIR |= LCD_MOSI_PIN + LCD_CLK_PIN + LCD_MISO_PIN;
142
  LCD_CS_RST_OUT &= ~(LCD_MOSI_PIN + LCD_CLK_PIN + LCD_MISO_PIN);
143
 
144
  UCB2CTL0 = UCSWRST;
145
}
146
 
147
/**********************************************************************//**
148
 * @brief  Initializes the LCD backlight PWM signal.
149
 *
150
 * @param  none
151
 *
152
 * @return none
153
 *
154
 *************************************************************************/
155
void halLcdBackLightInit(void)
156
{
157
  LCD_BACKLT_DIR |= LCD_BACKLIGHT_PIN;
158
  LCD_BACKLT_OUT |= LCD_BACKLIGHT_PIN;
159
  LCD_BACKLT_SEL |= LCD_BACKLIGHT_PIN;
160
 
161
  TA0CCTL3 = OUTMOD_7;
162
  TA0CCR3 = TA0CCR0 >> 1 ;
163
  backlight = 8;
164
 
165
  TA0CCR0 = 400;
166
  TA0CTL = TASSEL_2+MC_1;
167
}
168
 
169
/**********************************************************************//**
170
 * @brief  Get function for the backlight PWM's duty cycle.
171
 *
172
 * @param  none
173
 *
174
 * @return backlight One of the the 17 possible settings - valued 0 to 16.
175
 *
176
 *************************************************************************/
177
unsigned int halLcdGetBackLight(void)
178
{
179
  return backlight;
180
}
181
 
182
/**********************************************************************//**
183
 * @brief  Set function for the backlight PWM's duty cycle
184
 *
185
 * @param  BackLightLevel The target backlight duty cycle - valued 0 to 16.
186
 *
187
 * @return none
188
 *************************************************************************/
189
void halLcdSetBackLight(unsigned char BackLightLevel)
190
{
191
  unsigned int dutyCycle = 0, i, dummy;
192
 
193
  if (BackLightLevel > 0)
194
  {
195
    TA0CCTL3 = OUTMOD_7;
196
    dummy = (TA0CCR0 >> 4);
197
 
198
    for (i = 0; i < BackLightLevel; i++)
199
      dutyCycle += dummy;
200
 
201
    TA0CCR3 = dutyCycle;
202
 
203
    // If the backlight was previously turned off, turn it on.
204
    if (!backlight)
205
      TA0CTL |= MC0;
206
  }
207
  else
208
  {
209
    TA0CCTL3 = 0;
210
    TA0CTL &= ~MC0;
211
  }
212
  backlight = BackLightLevel;
213
}
214
 
215
/**********************************************************************//**
216
 * @brief  Turns off the backlight.
217
 *
218
 * Clears the respective GPIO and timer settings.
219
 *
220
 * @param  none
221
 *
222
 * @return none
223
 *************************************************************************/
224
void halLcdShutDownBackLight(void)
225
{
226
  LCD_BACKLT_DIR |= LCD_BACKLIGHT_PIN;
227
  LCD_BACKLT_OUT &= ~(LCD_BACKLIGHT_PIN);
228
  LCD_BACKLT_SEL &= ~LCD_BACKLIGHT_PIN;
229
 
230
  TA0CCTL3 = 0;
231
  TA0CTL = 0;
232
 
233
  backlight = 0;
234
}
235
 
236
/**********************************************************************//**
237
 * @brief  Set function for the contrast level of the LCD.
238
 *
239
 * @param  ContrastLevel The target contrast level
240
 *
241
 * @return none
242
 *************************************************************************/
243
void halLcdSetContrast(unsigned char ContrastLevel)
244
{
245
  if (ContrastLevel > 127) ContrastLevel = 127;
246
  if (ContrastLevel < 70) ContrastLevel = 70;
247
  LcdInitMacro[ 0x04 * 6 + 5 ] = ContrastLevel;
248
  halLcdSendCommand(&LcdInitMacro[ 0x04 * 6 ]);
249
}
250
 
251
/**********************************************************************//**
252
 * @brief  Get function for the contrast level of the LCD.
253
 *
254
 * @param  none
255
 *
256
 * @return ContrastLevel The LCD constrast level
257
 *************************************************************************/
258
unsigned char halLcdGetContrast(void)
259
{
260
  return LcdInitMacro[ 0x04 * 6 + 5 ] ;
261
}
262
 
263
/**********************************************************************//**
264
 * @brief  Turns the LCD cursor on at the current text position.
265
 *
266
 * @param  none
267
 *
268
 * @return none
269
 *************************************************************************/
270
void halLcdCursor(void)
271
{
272
  LcdInitMacro[  8 * 6 + 5 ] ^= BIT2;
273
  halLcdSendCommand(&LcdInitMacro[ 8 * 6 ]);
274
 
275
  LcdInitMacro[ 0x0B * 6 + 5 ] = ((LcdAddress & 0x1F) << 3) ;
276
  LcdInitMacro[ 0x0B * 6 + 4 ] = ( (LcdAddress & 0x1F) << 3 ) + 3;
277
  LcdInitMacro[ 0x0C * 6 + 5 ] = (LcdAddress >> 5);
278
  LcdInitMacro[ 0x0C * 6 + 4 ] = (LcdAddress >> 5) + 7;
279
  halLcdSendCommand(&LcdInitMacro[ 0x0B * 6 ]);
280
  halLcdSendCommand(&LcdInitMacro[ 0x0C * 6 ]);
281
 
282
  halLcdSetAddress(LcdAddress);
283
}
284
 
285
/**********************************************************************//**
286
 * @brief  Turns off the LCD cursor.
287
 *
288
 * @param  none
289
 *
290
 * @return none
291
 *************************************************************************/
292
void halLcdCursorOff(void)
293
{
294
  LcdInitMacro[  8 * 6 + 5 ] &= ~BIT2;
295
  halLcdSendCommand(&LcdInitMacro[ 8 * 6 ]);
296
}
297
 
298
/**********************************************************************//**
299
 * @brief  Inverts the grayscale values of the LCD display (Black <> white).
300
 *
301
 * @param  none
302
 *
303
 * @return none
304
 *************************************************************************/
305
void halLcdReverse(void)
306
{
307
  LcdInitMacro[  7 * 6 + 5 ] ^= BIT1;
308
  halLcdSendCommand(&LcdInitMacro[ 7 * 6 ]);
309
}
310
 
311
/**********************************************************************//**
312
 * @brief  Sets the LCD in standby mode to reduce power consumption.
313
 *
314
 * @param  none
315
 *
316
 * @return none
317
 *************************************************************************/
318
void halLcdStandby(void)
319
{
320
  LcdInitMacro[ 3 * 6 + 5 ] &= (~BIT3) & (~BIT2);
321
  LcdInitMacro[ 3 * 6 + 5 ] |= BIT0;
322
  halLcdSendCommand(&LcdInitMacro[ 3 * 6 ]);
323
}
324
 
325
/**********************************************************************//**
326
 * @brief  Puts the LCD into active mode.
327
 *
328
 * @param  none
329
 *
330
 * @return none
331
 *************************************************************************/
332
void halLcdActive(void)
333
{
334
  halLcdSendCommand(LcdInitMacro);                  // R00 start oscillation
335
 
336
  // Wait a minimum of 25ms after issuing "start oscillation"
337
  // command (to accomodate for MCLK up to 25MHz)
338
  __delay_cycles(250000);
339
 
340
  LcdInitMacro[ 3 * 6 + 5 ] |= BIT3;
341
  LcdInitMacro[ 3 * 6 + 5 ] &= ~BIT0;
342
  halLcdSendCommand(&LcdInitMacro[ 3 * 6 ]);        // R03 Power control
343
}
344
 
345
/**********************************************************************//**
346
 * @brief  Sets the pointer location in the LCD.
347
 *
348
 * - LcdAddress      = Address
349
 * - LcdTableAddress = Correct Address Row + Column
350
 *                   = (Address / 0x20)* 17 + Column
351
 *
352
 * @param  Address The target pointer location in the LCD.
353
 *
354
 * @return none
355
 *************************************************************************/
356
void halLcdSetAddress(int Address)
357
{
358
  int temp;
359
 
360
  Draw_Block_Address_Macro[4] = Address >> 8;
361
  Draw_Block_Address_Macro[5] = Address & 0xFF;
362
  halLcdSendCommand(Draw_Block_Address_Macro);
363
  LcdAddress = Address;
364
  temp = Address >> 5;                      // Divided by 0x20
365
  temp = temp + (temp << 4);
366
  //Multiplied by (1+16) and added by the offset
367
  LcdTableAddress = temp + (Address & 0x1F);
368
}
369
 
370
/**********************************************************************//**
371
 * @brief  Draws a block at the specified LCD address.
372
 *
373
 * A block is the smallest addressable memory on the LCD and is
374
 * equivalent to 8 pixels, each of which is represented by 2 bits
375
 * that represent a grayscale value between 00b and 11b.
376
 *
377
 * @param  Address The address at which to draw the block.
378
 *
379
 * @param  Value   The value of the block
380
 *
381
 * @return none
382
 *************************************************************************/
383
void halLcdDrawBlock(unsigned int Address, unsigned int Value)
384
{
385
  halLcdSetAddress(Address);
386
  halLcdDrawCurrentBlock(Value);
387
}
388
 
389
/**********************************************************************//**
390
 * @brief  Writes Value to LCD CGram and MSP430 internal LCD table.
391
 *
392
 * Also updates the LcdAddress and LcdTableAddress to the correct values.
393
 *
394
 * @param  Value The value of the block to be written to the LCD.
395
 *
396
 * @return none
397
 *************************************************************************/
398
void halLcdDrawCurrentBlock(unsigned int Value)
399
{
400
  int temp;
401
 
402
  Draw_Block_Value_Macro[4] = Value >> 8;
403
  Draw_Block_Value_Macro[5] = Value & 0xFF;
404
  LCD_MEM[ LcdTableAddress ] = Value;
405
 
406
  halLcdSendCommand(Draw_Block_Value_Macro);
407
 
408
  LcdAddress++;
409
  temp = LcdAddress >> 5;                   // Divided by 0x20
410
  temp = temp + (temp << 4);
411
  // Multiplied by (1+16) and added by the offset
412
  LcdTableAddress = temp + (LcdAddress & 0x1F);
413
 
414
  // If LcdAddress gets off the right edge, move to next line
415
  if ((LcdAddress & 0x1F) > 0x11)
416
    halLcdSetAddress( (LcdAddress & 0xFFE0) + 0x20 );
417
  if (LcdAddress == LCD_Size)
418
    halLcdSetAddress( 0 );
419
}
420
 
421
/**********************************************************************//**
422
 * @brief  Returns the LCD CGRAM value at location Address.
423
 *
424
 * @param  Address The address of the block to be read from the LCD.
425
 *
426
 * @return Value   The value held at the specified address.
427
 *************************************************************************/
428
int halLcdReadBlock(unsigned int Address)
429
{
430
  int i = 0, Value = 0, ReadData[7];
431
 
432
  halLcdSetAddress( Address );
433
  halLcdSendCommand(Read_Block_Address_Macro);
434
 
435
  LCD_CS_RST_OUT &= ~LCD_CS_PIN;              // start transfer CS=0
436
  UCB2TXBUF = 0x77;                         // Transmit first character 0x77
437
 
438
  while (!(UCB2IFG & UCTXIFG));
439
  while (UCB2STAT & UCBUSY);
440
 
441
  //Read 5 dummies values and 2 valid address data
442
  LCD_SPI_SEL &= ~LCD_MOSI_PIN;             //Change SPI2C Dir
443
  LCD_SPI_SEL |= LCD_MISO_PIN;
444
 
445
  for (i = 0; i < 7; i ++ )
446
  {
447
    UCB2IFG &= ~UCRXIFG;
448
    UCB2TXBUF = 1;                          // load dummy byte 1 for clk
449
    while (!(UCB2IFG & UCRXIFG));
450
    ReadData[i] = UCB2RXBUF;
451
  }
452
  LCD_CS_RST_OUT |= LCD_CS_PIN;              // Stop Transfer CS = 1
453
 
454
  LCD_SPI_SEL |= LCD_MOSI_PIN;               //Change SPI2C Dir
455
  LCD_SPI_SEL &= ~LCD_MISO_PIN;
456
  LCD_CS_RST_DIR |= LCD_MOSI_PIN + LCD_CLK_PIN;
457
  LCD_CS_RST_DIR &= ~LCD_MISO_PIN;
458
 
459
  Value = (ReadData[5] << 8) + ReadData[6];
460
  return Value;
461
}
462
 
463
/**********************************************************************//**
464
 * @brief  Draw a Pixel of grayscale at coordinate (x,y) to LCD
465
 *
466
 * @param  x         x-coordinate for grayscale value
467
 *
468
 * @param  y         y-coordinate for grayscale value
469
 *
470
 * @param  GrayScale The intended grayscale value of the pixel - one of
471
 *                   four possible settings.
472
 *
473
 * @return none
474
 *************************************************************************/
475
void halLcdPixel( int x, int y, unsigned char GrayScale)
476
{
477
  int  Address, Value;
478
  unsigned char offset;
479
 
480
  //Each line increments by 0x20
481
  if ( (x>=0 ) && (x<LCD_COL) && (y>=0) && (y<LCD_ROW))
482
  {
483
    Address = (y << 5) + (x >> 3) ;         //Narrow down to 8 possible pixels
484
 
485
    Value = LCD_MEM[(y << 4)+ y + (x>>3)];  //y * 17 --> row. x>>3 --> column
486
 
487
    offset = (x & 0x07) << 1;      //3 LSBs = pos. within the 8 columns
488
    Value &= ~  (3 << offset);     //clear out the corresponding bits
489
    Value |= GrayScale << offset;  //set pixel to GrayScale level
490
 
491
    halLcdDrawBlock( Address, Value );
492
  }
493
}
494
 
495
/**********************************************************************//**
496
 * @brief  Clears entire LCD CGRAM as well as LCD_MEM.
497
 *
498
 * @param  none
499
 *
500
 * @return none
501
 *************************************************************************/
502
void halLcdClearScreen(void)
503
{
504
  int i, j, k, Current_Location = 0;
505
  halLcdSetAddress(0);
506
 
507
  for (i=0; i < 110; i++)
508
  {
509
    //prepare to send image
510
    LCD_CS_RST_OUT &= ~LCD_CS_PIN;            //CS = 0 --> Start Transfer
511
    for ( k = 0; k < 3; k++ )
512
    {
513
      while (!(UCB2IFG & UCTXIFG));           // Wait for TXIFG
514
      UCB2TXBUF = Draw_Block_Value_Macro[k];     // Load data
515
    }
516
    while (UCB2STAT & UCBUSY);
517
    LCD_CS_RST_OUT |= LCD_CS_PIN;         //CS = 1 --> Stop Transfer
518
    LCD_CS_RST_OUT &= ~LCD_CS_PIN;        //CS = 0 --> Start Transfer   
519
    while (!(UCB2IFG & UCTXIFG));           // Wait for TXIFG
520
    UCB2TXBUF = Draw_Block_Value_Macro[3];     // Load data
521
 
522
    //send blank line
523
    for (j=0; j < 17; j++)
524
    {
525
          LCD_MEM[ LcdTableAddress++ ] = 0x00;
526
      while (!(UCB2IFG & UCTXIFG));       // Wait for TXIFG
527
      UCB2TXBUF = 0x00;                   // Load data
528
      while (!(UCB2IFG & UCTXIFG));       // Wait for TXIFG
529
      UCB2TXBUF = 0x00;                   // Load data
530
    }
531
    //Clear the partially visible block at the edge of the screen
532
    while (!(UCB2IFG & UCTXIFG));       // Wait for TXIFG
533
      UCB2TXBUF = 0x00;                   // Load data
534
    while (!(UCB2IFG & UCTXIFG));       // Wait for TXIFG
535
      UCB2TXBUF = 0x00;                   // Load data
536
    while (UCB2STAT & UCBUSY);
537
    LCD_CS_RST_OUT |= LCD_CS_PIN;             //CS = 1 --> Stop Transfer
538
 
539
    Current_Location += 0x20;
540
    halLcdSetAddress(Current_Location );
541
  }
542
 
543
  halLcdSetAddress(0);
544
}
545
 
546
/**********************************************************************//**
547
 * @brief  Loads an image of size = rows * columns, starting at the
548
 *         coordinate (x,y).
549
 *
550
 * @param  Image[] The image to be loaded
551
 *
552
 * @param  Rows    The number of rows in the image. Size = Rows * Columns.
553
 *
554
 * @param  Columns The number of columns in the image. Size = Rows * Columns.
555
 *
556
 * @param  x       x-coordinate of the image's starting location
557
 *
558
 * @param  y       y-coordinate of the image's starting location
559
 *
560
 * @return none
561
 *************************************************************************/
562
void halLcdImage(const unsigned int Image[], int Columns, int Rows, int x, int y)
563
{
564
  int i, CurrentLocation;
565
 
566
  CurrentLocation = (y << 5) + (x >> 3);
567
  halLcdSetAddress(CurrentLocation);
568
  for (i=0; i < Rows; i++)
569
  {
570
    halLcdDrawCurrentLine(Image, Columns);
571
    Image += Columns;
572
    CurrentLocation += 0x20;
573
    halLcdSetAddress(CurrentLocation);
574
  }
575
}
576
 
577
/**********************************************************************//**
578
 * @brief  Writes Value to LCD CGram and MSP430 internal LCD table.
579
 *
580
 * Also updates the LcdAddress and LcdTableAddress to the correct values.
581
 *
582
 * @param  *value Pointer to the line to be written to the LCD.
583
 *
584
 * @return none
585
 *************************************************************************/
586
void halLcdDrawCurrentLine(const unsigned int *value, int Columns)
587
{
588
  unsigned char i;
589
 
590
  //prepare to send image
591
  LCD_CS_RST_OUT &= ~LCD_CS_PIN;            //CS = 0 --> Start Transfer
592
  for ( i = 0; i < 3; i++ )
593
  {
594
      while (!(UCB2IFG & UCTXIFG));           // Wait for TXIFG
595
      UCB2TXBUF = Draw_Block_Value_Macro[i];     // Load data
596
  }
597
  while (UCB2STAT & UCBUSY);
598
  LCD_CS_RST_OUT |= LCD_CS_PIN;         //CS = 1 --> Stop Transfer
599
  LCD_CS_RST_OUT &= ~LCD_CS_PIN;        //CS = 0 --> Start Transfer     
600
  while (!(UCB2IFG & UCTXIFG));           // Wait for TXIFG
601
  UCB2TXBUF = Draw_Block_Value_Macro[3];     // Load data
602
 
603
  //send the image
604
  for ( i = 0; i < Columns; i++ )
605
  {
606
    // Make sure we are not writing outside LCD_MEM[]
607
    if (LcdTableAddress >= sizeof(LCD_MEM)) {
608
        break;
609
    }
610
        LCD_MEM[ LcdTableAddress++ ] = *value;
611
        while (!(UCB2IFG & UCTXIFG));           // Wait for TXIFG
612
    UCB2TXBUF = (*value) >> 8;                   // Load data
613
    while (!(UCB2IFG & UCTXIFG));           // Wait for TXIFG
614
    UCB2TXBUF = (*value++) & 0xFF;                   // Load data
615
  }
616
 
617
  while (UCB2STAT & UCBUSY);
618
  LCD_CS_RST_OUT |= LCD_CS_PIN;             //CS = 1 --> Stop Transfer
619
}
620
 
621
/**********************************************************************//**
622
 * @brief  Clears an image of size rows x columns starting at (x, y).
623
 *
624
 * @param  Columns The size, in columns, of the image to be cleared.
625
 *
626
 * @param  Rows    The size, in rows, of the image to be cleared.
627
 *
628
 * @param  x       x-coordinate of the image to be cleared
629
 *
630
 * @param  y       y-coordinate of the image to be cleared
631
 *
632
 * @return none
633
 *************************************************************************/
634
void halLcdClearImage(int Columns, int Rows, int x, int y)
635
{
636
  int i,j,k, Current_Location;
637
  Current_Location = (y << 5) + (x >> 3);
638
  halLcdSetAddress( Current_Location );
639
 
640
  for (i=0; i < Rows; i++)
641
  {
642
    //prepare to send image
643
    LCD_CS_RST_OUT &= ~LCD_CS_PIN;            //CS = 0 --> Start Transfer
644
    for ( k = 0; k < 3; k++ )
645
    {
646
      while (!(UCB2IFG & UCTXIFG));           // Wait for TXIFG
647
      UCB2TXBUF = Draw_Block_Value_Macro[k];     // Load data
648
    }
649
    while (UCB2STAT & UCBUSY);
650
    LCD_CS_RST_OUT |= LCD_CS_PIN;         //CS = 1 --> Stop Transfer
651
    LCD_CS_RST_OUT &= ~LCD_CS_PIN;        //CS = 0 --> Start Transfer   
652
    while (!(UCB2IFG & UCTXIFG));           // Wait for TXIFG
653
    UCB2TXBUF = Draw_Block_Value_Macro[3];     // Load data
654
 
655
    //send blank line
656
    for (j=0; j < Columns; j++)
657
    {
658
          LCD_MEM[ LcdTableAddress++ ] = 0x00;
659
      while (!(UCB2IFG & UCTXIFG));       // Wait for TXIFG
660
      UCB2TXBUF = 0x00;                   // Load data
661
      while (!(UCB2IFG & UCTXIFG));       // Wait for TXIFG
662
      UCB2TXBUF = 0x00;                   // Load data
663
    }
664
    while (UCB2STAT & UCBUSY);
665
    LCD_CS_RST_OUT |= LCD_CS_PIN;             //CS = 1 --> Stop Transfer
666
 
667
    Current_Location += 0x20;
668
    halLcdSetAddress(Current_Location );
669
  }
670
}
671
 
672
/**********************************************************************//**
673
 * @brief  Writes Value to LCD CGRAM. Pointers internal to the LCD
674
 *         are also updated.
675
 *
676
 * @param  Value The value to be written to the current LCD pointer
677
 *
678
 * @return none
679
 *************************************************************************/
680
void halLcdDrawTextBlock(unsigned int Value)
681
{
682
  int temp;
683
 
684
  Draw_Block_Value_Macro[4] = Value >> 8;
685
  Draw_Block_Value_Macro[5] = Value & 0xFF;
686
  LCD_MEM[ LcdTableAddress ] = Value;
687
 
688
  halLcdSendCommand(Draw_Block_Value_Macro);
689
 
690
  LcdAddress++;
691
  temp = LcdAddress >> 5;                   // Divided by 0x20
692
  temp = temp + (temp << 4);
693
  //Multiplied by (1+16) and added by the offset
694
  LcdTableAddress = temp + (LcdAddress & 0x1F);
695
 
696
  // If LcdAddress gets off the right edge, move to next line
697
  if ((LcdAddress & 0x1F) > 0x10)
698
    halLcdSetAddress( (LcdAddress & 0xFFE0) + 0x20 );
699
 
700
  if (LcdAddress >= LCD_Size)
701
    halLcdSetAddress( 0 );
702
}
703
 
704
/**********************************************************************//**
705
 * @brief  Displays the string to the LCD starting at current location.
706
 *
707
 * Writes all the data to LCD_MEM first, then updates all corresponding
708
 * LCD CGRAM locations at once, in a continuous fashion.
709
 *
710
 * @param  String[]  The string to be displayed on LCD.
711
 *
712
 * @param  TextStyle Value that specifies whether the string is to be
713
 *                   inverted or overwritten.
714
 *                   - Invert    = 0x01
715
 *                   - Overwrite = 0x04
716
 *
717
 * @return none
718
 *************************************************************************/
719
void halLcdPrint( char String[], unsigned char TextStyle)
720
{
721
  int i, j, Counter=0, BlockValue;
722
  int Address, LCD_MEM_Add, ActualAddress;
723
  int temp;
724
  char LookUpChar;
725
 
726
  ActualAddress = LcdAddress;
727
  Counter =  LcdAddress & 0x1F;
728
  i=0;
729
 
730
  while (String[i]!=0)                      // Stop on null character
731
  {
732
    LookUpChar = fonts_lookup[String[i]];
733
 
734
    for (j=0;j < FONT_HEIGHT ;j++)
735
    {
736
      Address = ActualAddress + j*0x20;
737
      temp = Address >> 5;
738
      temp += (temp <<4);
739
 
740
      LCD_MEM_Add = temp + (Address & 0x1F);
741
 
742
      BlockValue = LCD_MEM[ LCD_MEM_Add ];
743
 
744
      if(TextStyle & GRAYSCALE_TEXT)
745
      {
746
        if (TextStyle & INVERT_TEXT)
747
          if (TextStyle & OVERWRITE_TEXT)
748
            BlockValue = 0xAAAA - GrayScale_fonts[LookUpChar*(FONT_HEIGHT+1) +j];
749
          else
750
            BlockValue |= 0xAAAA - GrayScale_fonts[LookUpChar*(FONT_HEIGHT+1) +j];
751
        else
752
          if (TextStyle & OVERWRITE_TEXT)
753
            BlockValue = GrayScale_fonts[LookUpChar*(FONT_HEIGHT+1) +j];
754
          else
755
            BlockValue |= GrayScale_fonts[LookUpChar*(FONT_HEIGHT+1) +j];
756
      }
757
      else
758
      {
759
        if (TextStyle & INVERT_TEXT)
760
          if (TextStyle & OVERWRITE_TEXT)
761
            BlockValue = 0xFFFF - fonts[LookUpChar*13+j];
762
          else
763
            BlockValue |= 0xFFFF - fonts[LookUpChar*13+j];
764
 
765
        else
766
          if (TextStyle & OVERWRITE_TEXT)
767
            BlockValue = fonts[LookUpChar*(FONT_HEIGHT+1) +j];
768
          else
769
            BlockValue |= fonts[LookUpChar*(FONT_HEIGHT+1) +j];
770
      }
771
      halLcdDrawBlock( Address, BlockValue);
772
    }
773
 
774
    Counter++;
775
    if (Counter == 17)
776
    {
777
      Counter = 0;
778
      ActualAddress += 0x20*FONT_HEIGHT  - 16;
779
      if (ActualAddress > LCD_Last_Pixel-0x20*FONT_HEIGHT )
780
        ActualAddress = 0;
781
    }
782
    else
783
      ActualAddress++;
784
    i++;
785
  }
786
  halLcdSetAddress(ActualAddress);
787
 
788
}
789
 
790
/**********************************************************************//**
791
 * @brief  Displays the string to the LCD starting at (x,y) location.
792
 *
793
 * Writes all the data to LCD_MEM first, then updates all corresponding
794
 * LCD CGRAM locations at once, in a continuous fashion.
795
 *
796
 * @param  String[]  String to be displayed on LCD
797
 *
798
 * @param  x         x-coordinate of the write location on the LCD
799
 *
800
 * @param  y         y-coordinate of the write location on the LCD
801
 *
802
 * @param  TextStyle Value that specifies whether the string is to be
803
 *                   inverted or overwritten.
804
 *                   - Invert    = 0x01
805
 *                   - Overwrite = 0x04
806
 *************************************************************************/
807
void halLcdPrintXY( char String[], int x, int y, unsigned char TextStyle)
808
{
809
  //Each line increments by 0x20
810
  halLcdSetAddress( (y << 5) + (x >> 3)) ;  //Narrow down to 8 possible pixels
811
  halLcdPrint(String,  TextStyle);
812
}
813
 
814
/**********************************************************************//**
815
 * @brief  Displays a string on the LCD on the specified line.
816
 *
817
 * @param  String[]  The string to be displayed on LCD.
818
 *
819
 * @param  Line      The line on the LCD on which to print the string.
820
 *
821
 * @param  TextStyle Value that specifies whether the string is to be
822
 *                   inverted or overwritten.
823
 *                   - Invert    = 0x01
824
 *                   - Overwrite = 0x04
825
 *
826
 * @return none
827
 *************************************************************************/
828
void halLcdPrintLine(char String[], unsigned char Line, unsigned char TextStyle)
829
{
830
  int temp;
831
  temp = Line * FONT_HEIGHT ;
832
  halLcdSetAddress( temp << 5 ) ;           // 0x20 = 2^5
833
  halLcdPrint(String, TextStyle);
834
}
835
 
836
/**********************************************************************//**
837
 * @brief  Prints a string beginning on a given line and column.
838
 *
839
 * @param  String[]  The string to be displayed on LCD.
840
 *
841
 * @param  Line      The line on which to print the string of text
842
 *
843
 * @param  Col       The column on which to print the string of text
844
 *
845
 * @param  TextStyle Value that specifies whether the string is to be
846
 *                   inverted or overwritten.
847
 *                   - Invert    = 0x01
848
 *                   - Overwrite = 0x04
849
 *
850
 * @return none
851
 *************************************************************************/
852
void halLcdPrintLineCol(char String[], unsigned char Line, unsigned char Col,
853
                        unsigned char TextStyle)
854
{
855
  int temp;
856
 
857
  temp = Line * FONT_HEIGHT;
858
  temp <<= 5;
859
  temp += Col;
860
 
861
  halLcdSetAddress( temp ) ;                // 0x20 = 2^5
862
  halLcdPrint(String, TextStyle);
863
}
864
 
865
 
866
/**********************************************************************//**
867
 * @brief  Draws a horizontral line from (x1,y) to (x2,y) of GrayScale level
868
 *
869
 * @param  x1        x-coordinate of the first point
870
 *
871
 * @param  x2        x-coordinate of the second point
872
 *
873
 * @param  y         y-coordinate of both points
874
 *
875
 * @param  GrayScale Grayscale level of the horizontal line
876
 *
877
 * @return none
878
 *************************************************************************/
879
void halLcdHLine( int x1, int x2, int y, unsigned char GrayScale)
880
{
881
  int x_dir, x;
882
  if ( x1 < x2 )
883
    x_dir = 1;
884
  else
885
    x_dir = -1;
886
  x = x1;
887
  while (x != x2)
888
  {
889
    halLcdPixel( x,y, GrayScale);
890
    x += x_dir;
891
  }
892
}
893
 
894
/**********************************************************************//**
895
 * @brief  Draws a vertical line from (x,y1) to (x,y2) of GrayScale level
896
 *
897
 * @param  x         x-coordinate of both points
898
 *
899
 * @param  y1        y-coordinate of the first point
900
 *
901
 * @param  y2        y-coordinate of the second point
902
 *
903
 * @param  GrayScale GrayScale level of the vertical line
904
 *
905
 * @return none
906
 *************************************************************************/
907
void halLcdVLine( int x, int y1, int y2, unsigned char GrayScale)
908
{
909
  int y_dir, y;
910
  if ( y1 < y2 )
911
    y_dir = 1;
912
  else
913
    y_dir = -1;
914
  y = y1;
915
  while (y != y2)
916
  {
917
    halLcdPixel( x,y, GrayScale);
918
    y += y_dir;
919
  }
920
}
921
 
922
/**********************************************************************//**
923
 * @brief  Draws a line from (x1,y1) to (x2,y2) of GrayScale level.
924
 *
925
 * Uses Bresenham's line algorithm.
926
 *
927
 * @param  x1         x-coordinate of the first point
928
 *
929
 * @param  y1         y-coordinate of the first point
930
 *
931
 * @param  x2         x-coordinate of the second point
932
 *
933
 * @param  y2         y-coordinate of the second point
934
 *
935
 * @param  GrayScale  Grayscale level of the line
936
 *
937
 * @return none
938
 *************************************************************************/
939
void halLcdLine( int x1, int y1, int x2, int y2, unsigned char GrayScale)
940
{
941
  int x, y, deltay, deltax, d;
942
  int x_dir, y_dir;
943
 
944
  if ( x1 == x2 )
945
    halLcdVLine( x1, y1, y2, GrayScale );
946
  else
947
  {
948
    if ( y1 == y2 )
949
      halLcdHLine( x1, x2, y1, GrayScale );
950
    else                                    // a diagonal line
951
    {
952
      if (x1 > x2)
953
        x_dir = -1;
954
      else x_dir = 1;
955
      if (y1 > y2)
956
        y_dir = -1;
957
      else y_dir = 1;
958
 
959
      x = x1;
960
      y = y1;
961
      deltay = ABS(y2 - y1);
962
      deltax = ABS(x2 - x1);
963
 
964
      if (deltax >= deltay)
965
      {
966
        d = (deltay << 1) - deltax;
967
        while (x != x2)
968
        {
969
          halLcdPixel(x, y,  GrayScale);
970
          if ( d < 0 )
971
            d += (deltay << 1);
972
          else
973
          {
974
            d += ((deltay - deltax) << 1);
975
            y += y_dir;
976
          }
977
          x += x_dir;
978
        }
979
      }
980
      else
981
      {
982
        d = (deltax << 1) - deltay;
983
        while (y != y2)
984
        {
985
          halLcdPixel(x, y, GrayScale);
986
          if ( d < 0 )
987
            d += (deltax << 1);
988
          else
989
          {
990
            d += ((deltax - deltay) << 1);
991
            x += x_dir;
992
          }
993
          y += y_dir;
994
        }
995
      }
996
    }
997
  }
998
}
999
 
1000
 
1001
/**********************************************************************//**
1002
 * @brief  Draw a circle of Radius with center at (x,y) of GrayScale level.
1003
 *
1004
 * Uses Bresenham's circle algorithm
1005
 *
1006
 * @param  x         x-coordinate of the circle's center point
1007
 *
1008
 * @param  y         y-coordinate of the circle's center point
1009
 *
1010
 * @param  Radius    Radius of the circle
1011
 *
1012
 * @param  GrayScale Grayscale level of the circle
1013
 *************************************************************************/
1014
void halLcdCircle(int x, int y, int Radius, int GrayScale)
1015
{
1016
  int xx, yy, ddF_x, ddF_y, f;
1017
 
1018
  ddF_x = 0;
1019
  ddF_y = -(2 * Radius);
1020
  f = 1 - Radius;
1021
 
1022
  xx = 0;
1023
  yy = Radius;
1024
  halLcdPixel(x + xx, y + yy, GrayScale);
1025
  halLcdPixel(x + xx, y - yy, GrayScale);
1026
  halLcdPixel(x - xx, y + yy, GrayScale);
1027
  halLcdPixel(x - xx, y - yy, GrayScale);
1028
  halLcdPixel(x + yy, y + xx, GrayScale);
1029
  halLcdPixel(x + yy, y - xx, GrayScale);
1030
  halLcdPixel(x - yy, y + xx, GrayScale);
1031
  halLcdPixel(x - yy, y - xx, GrayScale);
1032
  while (xx < yy)
1033
  {
1034
    if (f >= 0)
1035
    {
1036
      yy--;
1037
      ddF_y += 2;
1038
      f += ddF_y;
1039
    }
1040
    xx++;
1041
    ddF_x += 2;
1042
    f += ddF_x + 1;
1043
    halLcdPixel(x + xx, y + yy, GrayScale);
1044
    halLcdPixel(x + xx, y - yy, GrayScale);
1045
    halLcdPixel(x - xx, y + yy, GrayScale);
1046
    halLcdPixel(x - xx, y - yy, GrayScale);
1047
    halLcdPixel(x + yy, y + xx, GrayScale);
1048
    halLcdPixel(x + yy, y - xx, GrayScale);
1049
    halLcdPixel(x - yy, y + xx, GrayScale);
1050
    halLcdPixel(x - yy, y - xx, GrayScale);
1051
  }
1052
}
1053
 
1054
/**********************************************************************//**
1055
 * @brief  Scrolls a single row of pixels one column to the left.
1056
 *
1057
 * The column that is scrolled out of the left side of the LCD will be
1058
 * displayed the right side of the LCD.
1059
 *
1060
 * @param  y    The row of pixels to scroll. y = 0 is at the top-left
1061
 *              corner of the LCD.
1062
 *
1063
 * @return none
1064
 *************************************************************************/
1065
void halLcdScrollRow(int y)
1066
{
1067
  int i, Address, LcdTableAddressTemp;
1068
  unsigned int temp;
1069
 
1070
  Address = y << 5;
1071
 
1072
  halLcdSetAddress( Address );
1073
 
1074
  //Multiplied by (1+16) and added by the offset
1075
  LcdTableAddressTemp = y + (y << 4);
1076
  temp = ((LCD_MEM[LcdTableAddressTemp] & 0x0003) <<14);
1077
 
1078
  for (i = 0; i < 0x10; i++)
1079
    halLcdDrawCurrentBlock( ( (LCD_MEM[LcdTableAddressTemp+i] & 0xFFFC ) >> 2 ) \
1080
    + ((LCD_MEM[LcdTableAddressTemp+i+1] & 0x0003) << 14 ));
1081
 
1082
  halLcdDrawCurrentBlock( (( LCD_MEM[LcdTableAddressTemp + 0x10] & 0xFFFC ) >> 2) + temp);
1083
}
1084
 
1085
/**********************************************************************//**
1086
 * @brief  Scrolls multiple rows of pixels, yStart to yEnd,
1087
 *         one column to the left.
1088
 *
1089
 * The column that is scrolled out of the left side of the LCD will be
1090
 * displayed the right side of the LCD. y = 0 is at the top-left of the
1091
 * LCD screen.
1092
 *
1093
 * @param  yStart The beginning row to be scrolled
1094
 *
1095
 * @param  yEnd   The last row to be scrolled
1096
 *
1097
 * @return none
1098
 *************************************************************************/
1099
void halLcdHScroll(int yStart, int yEnd)
1100
{
1101
  int i ;
1102
 
1103
  for (i = yStart; i < yEnd+1; i++)
1104
    halLcdScrollRow(i);
1105
}
1106
 
1107
/**********************************************************************//**
1108
 * @brief  Scrolls a line of text one column to the left.
1109
 *
1110
 * @param  Line The line of text to be scrolled.
1111
 *
1112
 * @return none
1113
 *************************************************************************/
1114
void halLcdScrollLine(int Line)
1115
{
1116
  int i, Row ;
1117
 
1118
  Row = Line * FONT_HEIGHT;
1119
 
1120
  for (i = Row; i < Row + FONT_HEIGHT ; i++)
1121
    halLcdScrollRow(i);
1122
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.