stm3210e_eval_lcd.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm3210e_eval_lcd.c
00004   * @author  MCD Application Team
00005   * @version V4.3.0
00006   * @date    10/15/2010
00007   * @brief   This file includes the LCD driver for AM-240320L8TNQW00H 
00008   *          (LCD_ILI9320) and AM-240320LDTNQW00H (LCD_SPFD5408B) Liquid Crystal
00009   *          Display Module of STM3210E-EVAL board.
00010   ******************************************************************************
00011   * @copy
00012   *
00013   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00014   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
00015   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
00016   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
00017   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
00018   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00019   *
00020   * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>
00021   */ 
00022 
00023 /* Includes ------------------------------------------------------------------*/
00024 #include "stm3210e_eval_lcd.h"
00025 #include "../Common/fonts.c"
00026 
00027 /** @addtogroup Utilities
00028   * @{
00029   */ 
00030 
00031 /** @addtogroup STM32_EVAL
00032   * @{
00033   */ 
00034 
00035 /** @addtogroup STM3210E_EVAL
00036   * @{
00037   */
00038     
00039 /** @defgroup STM3210E_EVAL_LCD 
00040   * @brief This file includes the LCD driver for AM-240320L8TNQW00H 
00041   *        (LCD_ILI9320) and AM-240320LDTNQW00H (LCD_SPFD5408B) Liquid Crystal
00042   *        Display Module of STM3210E-EVAL board.
00043   * @{
00044   */ 
00045 
00046 /** @defgroup STM3210E_EVAL_LCD_Private_TypesDefinitions
00047   * @{
00048   */ 
00049 typedef struct
00050 {
00051   __IO uint16_t LCD_REG;
00052   __IO uint16_t LCD_RAM;
00053 } LCD_TypeDef;
00054 /**
00055   * @}
00056   */ 
00057 
00058 
00059 /** @defgroup STM3210E_EVAL_LCD_Private_Defines
00060   * @{
00061   */
00062 /* Note: LCD /CS is CE4 - Bank 4 of NOR/SRAM Bank 1~4 */
00063 #define LCD_BASE           ((uint32_t)(0x60000000 | 0x0C000000))
00064 #define LCD                ((LCD_TypeDef *) LCD_BASE)
00065 #define MAX_POLY_CORNERS   200
00066 #define POLY_Y(Z)          ((int32_t)((Points + Z)->X))
00067 #define POLY_X(Z)          ((int32_t)((Points + Z)->Y))                                
00068 /**
00069   * @}
00070   */ 
00071 
00072 /** @defgroup STM3210E_EVAL_LCD_Private_Macros
00073   * @{
00074   */
00075 #define ABS(X)  ((X) > 0 ? (X) : -(X))    
00076 /**
00077   * @}
00078   */ 
00079   
00080 /** @defgroup STM3210E_EVAL_LCD_Private_Variables
00081   * @{
00082   */ 
00083 static sFONT *LCD_Currentfonts;
00084 /* Global variables to set the written text color */
00085 static  __IO uint16_t TextColor = 0x0000, BackColor = 0xFFFF;
00086   
00087 /**
00088   * @}
00089   */ 
00090 
00091 
00092 /** @defgroup STM3210E_EVAL_LCD_Private_FunctionPrototypes
00093   * @{
00094   */ 
00095 #ifndef USE_Delay
00096 static void delay(vu32 nCount);
00097 #endif /* USE_Delay*/
00098 static void PutPixel(int16_t x, int16_t y);
00099 static void LCD_PolyLineRelativeClosed(pPoint Points, uint16_t PointCount, uint16_t Closed);
00100 /**
00101   * @}
00102   */ 
00103 
00104 
00105 /** @defgroup STM3210E_EVAL_LCD_Private_Functions
00106   * @{
00107   */ 
00108 
00109 /**
00110   * @brief  DeInitializes the LCD.
00111   * @param  None
00112   * @retval None
00113   */
00114 void LCD_DeInit(void)
00115 { 
00116   GPIO_InitTypeDef GPIO_InitStructure;
00117 
00118   /*!< LCD Display Off */
00119   LCD_DisplayOff();
00120 
00121   /* BANK 4 (of NOR/SRAM Bank 1~4) is disabled */
00122   FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM4, ENABLE);
00123   
00124   /*!< LCD_SPI DeInit */
00125   FSMC_NORSRAMDeInit(FSMC_Bank1_NORSRAM4);
00126    
00127   /* Set PD.00(D2), PD.01(D3), PD.04(NOE), PD.05(NWE), PD.08(D13), PD.09(D14),
00128      PD.10(D15), PD.14(D0), PD.15(D1) as input floating */
00129   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 |
00130                                 GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_14 | 
00131                                 GPIO_Pin_15;
00132   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
00133   GPIO_Init(GPIOD, &GPIO_InitStructure);
00134   /* Set PE.07(D4), PE.08(D5), PE.09(D6), PE.10(D7), PE.11(D8), PE.12(D9), PE.13(D10),
00135      PE.14(D11), PE.15(D12) as alternate function push pull */
00136   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | 
00137                                 GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | 
00138                                 GPIO_Pin_15;
00139   GPIO_Init(GPIOE, &GPIO_InitStructure);
00140   /* Set PF.00(A0 (RS)) as alternate function push pull */
00141   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
00142   GPIO_Init(GPIOF, &GPIO_InitStructure);
00143   /* Set PG.12(NE4 (LCD/CS)) as alternate function push pull - CE3(LCD /CS) */
00144   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
00145   GPIO_Init(GPIOG, &GPIO_InitStructure); 
00146 }
00147 
00148 /**
00149   * @brief  Initializes the LCD.
00150   * @param  None
00151   * @retval None
00152   */
00153 void STM3210E_LCD_Init(void)
00154 { 
00155 /* Configure the LCD Control pins --------------------------------------------*/
00156   LCD_CtrlLinesConfig();
00157 /* Configure the FSMC Parallel interface -------------------------------------*/
00158   LCD_FSMCConfig();
00159   
00160   _delay_(5); /* delay 50 ms */
00161   /* Check if the LCD is SPFD5408B Controller */
00162   if(LCD_ReadReg(0x00) == 0x5408)
00163   {
00164     /* Start Initial Sequence ------------------------------------------------*/
00165     LCD_WriteReg(LCD_REG_1, 0x0100);  /* Set SS bit */
00166     LCD_WriteReg(LCD_REG_2, 0x0700);  /* Set 1 line inversion */
00167     LCD_WriteReg(LCD_REG_3, 0x1030);  /* Set GRAM write direction and BGR=1. */
00168     LCD_WriteReg(LCD_REG_4, 0x0000);  /* Resize register */
00169     LCD_WriteReg(LCD_REG_8, 0x0202);  /* Set the back porch and front porch */
00170     LCD_WriteReg(LCD_REG_9, 0x0000);  /* Set non-display area refresh cycle ISC[3:0] */
00171     LCD_WriteReg(LCD_REG_10, 0x0000); /* FMARK function */
00172     LCD_WriteReg(LCD_REG_12, 0x0000); /* RGB 18-bit System interface setting */
00173     LCD_WriteReg(LCD_REG_13, 0x0000); /* Frame marker Position */
00174     LCD_WriteReg(LCD_REG_15, 0x0000); /* RGB interface polarity, no impact */
00175     /* Power On sequence -----------------------------------------------------*/
00176     LCD_WriteReg(LCD_REG_16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
00177     LCD_WriteReg(LCD_REG_17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
00178     LCD_WriteReg(LCD_REG_18, 0x0000); /* VREG1OUT voltage */
00179     LCD_WriteReg(LCD_REG_19, 0x0000); /* VDV[4:0] for VCOM amplitude */
00180     _delay_(20);                 /* Dis-charge capacitor power voltage (200ms) */
00181     LCD_WriteReg(LCD_REG_17, 0x0007);  /* DC1[2:0], DC0[2:0], VC[2:0] */
00182     _delay_(5);                   /* Delay 50 ms */
00183     LCD_WriteReg(LCD_REG_16, 0x12B0);  /* SAP, BT[3:0], AP, DSTB, SLP, STB */
00184     _delay_(5);                  /* Delay 50 ms */
00185     LCD_WriteReg(LCD_REG_18, 0x01BD);  /* External reference voltage= Vci */
00186     _delay_(5); 
00187     LCD_WriteReg(LCD_REG_19, 0x1400);  /* VDV[4:0] for VCOM amplitude */
00188     LCD_WriteReg(LCD_REG_41, 0x000E);  /* VCM[4:0] for VCOMH */
00189     _delay_(5);                   /* Delay 50 ms */
00190     LCD_WriteReg(LCD_REG_32, 0x0000); /* GRAM horizontal Address */
00191     LCD_WriteReg(LCD_REG_33, 0x013F); /* GRAM Vertical Address */
00192     /* Adjust the Gamma Curve (SPFD5408B)-------------------------------------*/
00193     LCD_WriteReg(LCD_REG_48, 0x0b0d);
00194     LCD_WriteReg(LCD_REG_49, 0x1923);
00195     LCD_WriteReg(LCD_REG_50, 0x1c26);
00196     LCD_WriteReg(LCD_REG_51, 0x261c);
00197     LCD_WriteReg(LCD_REG_52, 0x2419);
00198     LCD_WriteReg(LCD_REG_53, 0x0d0b);
00199     LCD_WriteReg(LCD_REG_54, 0x1006);
00200     LCD_WriteReg(LCD_REG_55, 0x0610);
00201     LCD_WriteReg(LCD_REG_56, 0x0706);
00202     LCD_WriteReg(LCD_REG_57, 0x0304);
00203     LCD_WriteReg(LCD_REG_58, 0x0e05);
00204     LCD_WriteReg(LCD_REG_59, 0x0e01);
00205     LCD_WriteReg(LCD_REG_60, 0x010e);
00206     LCD_WriteReg(LCD_REG_61, 0x050e);
00207     LCD_WriteReg(LCD_REG_62, 0x0403);
00208     LCD_WriteReg(LCD_REG_63, 0x0607);
00209     /* Set GRAM area ---------------------------------------------------------*/
00210     LCD_WriteReg(LCD_REG_80, 0x0000); /* Horizontal GRAM Start Address */
00211     LCD_WriteReg(LCD_REG_81, 0x00EF); /* Horizontal GRAM End Address */
00212     LCD_WriteReg(LCD_REG_82, 0x0000); /* Vertical GRAM Start Address */
00213     LCD_WriteReg(LCD_REG_83, 0x013F); /* Vertical GRAM End Address */
00214     LCD_WriteReg(LCD_REG_96,  0xA700); /* Gate Scan Line */
00215     LCD_WriteReg(LCD_REG_97,  0x0001); /* NDL, VLE, REV */
00216     LCD_WriteReg(LCD_REG_106, 0x0000); /* set scrolling line */
00217     /* Partial Display Control -----------------------------------------------*/
00218     LCD_WriteReg(LCD_REG_128, 0x0000);
00219     LCD_WriteReg(LCD_REG_129, 0x0000);
00220     LCD_WriteReg(LCD_REG_130, 0x0000);
00221     LCD_WriteReg(LCD_REG_131, 0x0000);
00222     LCD_WriteReg(LCD_REG_132, 0x0000);
00223     LCD_WriteReg(LCD_REG_133, 0x0000);
00224     /* Panel Control ---------------------------------------------------------*/
00225     LCD_WriteReg(LCD_REG_144, 0x0010); 
00226     LCD_WriteReg(LCD_REG_146, 0x0000);
00227     LCD_WriteReg(LCD_REG_147, 0x0003);
00228     LCD_WriteReg(LCD_REG_149, 0x0110);
00229     LCD_WriteReg(LCD_REG_151, 0x0000);
00230     LCD_WriteReg(LCD_REG_152, 0x0000);
00231     /* Set GRAM write direction and BGR=1
00232        I/D=01 (Horizontal : increment, Vertical : decrement)
00233        AM=1 (address is updated in vertical writing direction) */
00234     LCD_WriteReg(LCD_REG_3, 0x1018);
00235     LCD_WriteReg(LCD_REG_7, 0x0112); /* 262K color and display ON */
00236     LCD_SetFont(&LCD_DEFAULT_FONT);
00237     return;
00238   }
00239 /* Start Initial Sequence ----------------------------------------------------*/
00240   LCD_WriteReg(LCD_REG_229,0x8000); /* Set the internal vcore voltage */
00241   LCD_WriteReg(LCD_REG_0,  0x0001); /* Start internal OSC. */
00242   LCD_WriteReg(LCD_REG_1,  0x0100); /* set SS and SM bit */
00243   LCD_WriteReg(LCD_REG_2,  0x0700); /* set 1 line inversion */
00244   LCD_WriteReg(LCD_REG_3,  0x1030); /* set GRAM write direction and BGR=1. */
00245   LCD_WriteReg(LCD_REG_4,  0x0000); /* Resize register */
00246   LCD_WriteReg(LCD_REG_8,  0x0202); /* set the back porch and front porch */
00247   LCD_WriteReg(LCD_REG_9,  0x0000); /* set non-display area refresh cycle ISC[3:0] */
00248   LCD_WriteReg(LCD_REG_10, 0x0000); /* FMARK function */
00249   LCD_WriteReg(LCD_REG_12, 0x0000); /* RGB interface setting */
00250   LCD_WriteReg(LCD_REG_13, 0x0000); /* Frame marker Position */
00251   LCD_WriteReg(LCD_REG_15, 0x0000); /* RGB interface polarity */
00252 /* Power On sequence ---------------------------------------------------------*/
00253   LCD_WriteReg(LCD_REG_16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
00254   LCD_WriteReg(LCD_REG_17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
00255   LCD_WriteReg(LCD_REG_18, 0x0000); /* VREG1OUT voltage */
00256   LCD_WriteReg(LCD_REG_19, 0x0000); /* VDV[4:0] for VCOM amplitude */
00257   _delay_(20);                 /* Dis-charge capacitor power voltage (200ms) */
00258   LCD_WriteReg(LCD_REG_16, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
00259   LCD_WriteReg(LCD_REG_17, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */
00260   _delay_(5);                  /* Delay 50 ms */
00261   LCD_WriteReg(LCD_REG_18, 0x0139); /* VREG1OUT voltage */
00262   _delay_(5);                  /* Delay 50 ms */
00263   LCD_WriteReg(LCD_REG_19, 0x1d00); /* VDV[4:0] for VCOM amplitude */
00264   LCD_WriteReg(LCD_REG_41, 0x0013); /* VCM[4:0] for VCOMH */
00265   _delay_(5);                  /* Delay 50 ms */
00266   LCD_WriteReg(LCD_REG_32, 0x0000); /* GRAM horizontal Address */
00267   LCD_WriteReg(LCD_REG_33, 0x0000); /* GRAM Vertical Address */
00268 /* Adjust the Gamma Curve ----------------------------------------------------*/
00269   LCD_WriteReg(LCD_REG_48, 0x0006);
00270   LCD_WriteReg(LCD_REG_49, 0x0101);
00271   LCD_WriteReg(LCD_REG_50, 0x0003);
00272   LCD_WriteReg(LCD_REG_53, 0x0106);
00273   LCD_WriteReg(LCD_REG_54, 0x0b02);
00274   LCD_WriteReg(LCD_REG_55, 0x0302);
00275   LCD_WriteReg(LCD_REG_56, 0x0707);
00276   LCD_WriteReg(LCD_REG_57, 0x0007);
00277   LCD_WriteReg(LCD_REG_60, 0x0600);
00278   LCD_WriteReg(LCD_REG_61, 0x020b);
00279   
00280 /* Set GRAM area -------------------------------------------------------------*/
00281   LCD_WriteReg(LCD_REG_80, 0x0000); /* Horizontal GRAM Start Address */
00282   LCD_WriteReg(LCD_REG_81, 0x00EF); /* Horizontal GRAM End Address */
00283   LCD_WriteReg(LCD_REG_82, 0x0000); /* Vertical GRAM Start Address */
00284   LCD_WriteReg(LCD_REG_83, 0x013F); /* Vertical GRAM End Address */
00285   LCD_WriteReg(LCD_REG_96,  0x2700); /* Gate Scan Line */
00286   LCD_WriteReg(LCD_REG_97,  0x0001); /* NDL,VLE, REV */
00287   LCD_WriteReg(LCD_REG_106, 0x0000); /* set scrolling line */
00288 /* Partial Display Control ---------------------------------------------------*/
00289   LCD_WriteReg(LCD_REG_128, 0x0000);
00290   LCD_WriteReg(LCD_REG_129, 0x0000);
00291   LCD_WriteReg(LCD_REG_130, 0x0000);
00292   LCD_WriteReg(LCD_REG_131, 0x0000);
00293   LCD_WriteReg(LCD_REG_132, 0x0000);
00294   LCD_WriteReg(LCD_REG_133, 0x0000);
00295 /* Panel Control -------------------------------------------------------------*/
00296   LCD_WriteReg(LCD_REG_144, 0x0010);
00297   LCD_WriteReg(LCD_REG_146, 0x0000);
00298   LCD_WriteReg(LCD_REG_147, 0x0003);
00299   LCD_WriteReg(LCD_REG_149, 0x0110);
00300   LCD_WriteReg(LCD_REG_151, 0x0000);
00301   LCD_WriteReg(LCD_REG_152, 0x0000);
00302   /* Set GRAM write direction and BGR = 1 */
00303   /* I/D=01 (Horizontal : increment, Vertical : decrement) */
00304   /* AM=1 (address is updated in vertical writing direction) */
00305   LCD_WriteReg(LCD_REG_3, 0x1018);
00306   LCD_WriteReg(LCD_REG_7, 0x0173); /* 262K color and display ON */  
00307   LCD_SetFont(&LCD_DEFAULT_FONT);  
00308 }
00309 
00310 /**
00311   * @brief  Sets the LCD Text and Background colors.
00312   * @param  _TextColor: specifies the Text Color.
00313   * @param  _BackColor: specifies the Background Color.
00314   * @retval None
00315   */
00316 void LCD_SetColors(__IO uint16_t _TextColor, __IO uint16_t _BackColor)
00317 {
00318   TextColor = _TextColor; 
00319   BackColor = _BackColor;
00320 }
00321 
00322 /**
00323   * @brief  Gets the LCD Text and Background colors.
00324   * @param  _TextColor: pointer to the variable that will contain the Text 
00325             Color.
00326   * @param  _BackColor: pointer to the variable that will contain the Background 
00327             Color.
00328   * @retval None
00329   */
00330 void LCD_GetColors(__IO uint16_t *_TextColor, __IO uint16_t *_BackColor)
00331 {
00332   *_TextColor = TextColor; *_BackColor = BackColor;
00333 }
00334 
00335 /**
00336   * @brief  Sets the Text color.
00337   * @param  Color: specifies the Text color code RGB(5-6-5).
00338   * @retval None
00339   */
00340 void LCD_SetTextColor(__IO uint16_t Color)
00341 {
00342   TextColor = Color;
00343 }
00344 
00345 
00346 /**
00347   * @brief  Sets the Background color.
00348   * @param  Color: specifies the Background color code RGB(5-6-5).
00349   * @retval None
00350   */
00351 void LCD_SetBackColor(__IO uint16_t Color)
00352 {
00353   BackColor = Color;
00354 }
00355 
00356 /**
00357   * @brief  Sets the Text Font.
00358   * @param  fonts: specifies the font to be used.
00359   * @retval None
00360   */
00361 void LCD_SetFont(sFONT *fonts)
00362 {
00363   LCD_Currentfonts = fonts;
00364 }
00365 
00366 /**
00367   * @brief  Gets the Text Font.
00368   * @param  None.
00369   * @retval the used font.
00370   */
00371 sFONT *LCD_GetFont(void)
00372 {
00373   return LCD_Currentfonts;
00374 }
00375 
00376 /**
00377   * @brief  Clears the selected line.
00378   * @param  Line: the Line to be cleared.
00379   *   This parameter can be one of the following values:
00380   *     @arg Linex: where x can be 0..n
00381   * @retval None
00382   */
00383 void LCD_ClearLine(uint8_t Line)
00384 {
00385   uint16_t refcolumn = LCD_PIXEL_WIDTH - 1;
00386   /* Send the string character by character on lCD */
00387   while (((refcolumn + 1)&0xFFFF) >= LCD_Currentfonts->Width)
00388   {
00389     /* Display one character on LCD */
00390     LCD_DisplayChar(Line, refcolumn, ' ');
00391     /* Decrement the column position by 16 */
00392     refcolumn -= LCD_Currentfonts->Width;
00393   }
00394 }
00395 
00396 
00397 /**
00398   * @brief  Clears the hole LCD.
00399   * @param  Color: the color of the background.
00400   * @retval None
00401   */
00402 void LCD_Clear(uint16_t Color)
00403 {
00404   uint32_t index = 0;
00405   
00406   LCD_SetCursor(0x00, 0x013F); 
00407   LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
00408   for(index = 0; index < 76800; index++)
00409   {
00410     LCD->LCD_RAM = Color;
00411   }  
00412 }
00413 
00414 
00415 /**
00416   * @brief  Sets the cursor position.
00417   * @param  Xpos: specifies the X position.
00418   * @param  Ypos: specifies the Y position. 
00419   * @retval None
00420   */
00421 void LCD_SetCursor(uint8_t Xpos, uint16_t Ypos)
00422 {
00423   LCD_WriteReg(LCD_REG_32, Xpos);
00424   LCD_WriteReg(LCD_REG_33, Ypos);
00425 }
00426 
00427 
00428 /**
00429   * @brief  Draws a character on LCD.
00430   * @param  Xpos: the Line where to display the character shape.
00431   * @param  Ypos: start column address.
00432   * @param  c: pointer to the character data.
00433   * @retval None
00434   */
00435 void LCD_DrawChar(uint8_t Xpos, uint16_t Ypos, const uint16_t *c)
00436 {
00437   uint32_t index = 0, i = 0;
00438   uint8_t Xaddress = 0;
00439    
00440   Xaddress = Xpos;
00441   
00442   LCD_SetCursor(Xaddress, Ypos);
00443   
00444   for(index = 0; index < LCD_Currentfonts->Height; index++)
00445   {
00446     LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
00447     for(i = 0; i < LCD_Currentfonts->Width; i++)
00448     {
00449       if((((c[index] & ((0x80 << ((LCD_Currentfonts->Width / 12 ) * 8 ) ) >> i)) == 0x00) &&(LCD_Currentfonts->Width <= 12))||
00450         (((c[index] & (0x1 << i)) == 0x00)&&(LCD_Currentfonts->Width > 12 )))
00451 
00452       {
00453         LCD_WriteRAM(BackColor);
00454       }
00455       else
00456       {
00457         LCD_WriteRAM(TextColor);
00458       }
00459     }
00460     Xaddress++;
00461     LCD_SetCursor(Xaddress, Ypos);
00462   }
00463 }
00464 
00465 
00466 /**
00467   * @brief  Displays one character (16dots width, 24dots height).
00468   * @param  Line: the Line where to display the character shape .
00469   *   This parameter can be one of the following values:
00470   *     @arg Linex: where x can be 0..9
00471   * @param  Column: start column address.
00472   * @param  Ascii: character ascii code, must be between 0x20 and 0x7E.
00473   * @retval None
00474   */
00475 void LCD_DisplayChar(uint8_t Line, uint16_t Column, uint8_t Ascii)
00476 {
00477   Ascii -= 32;
00478   LCD_DrawChar(Line, Column, &LCD_Currentfonts->table[Ascii * LCD_Currentfonts->Height]);
00479 }
00480 
00481 
00482 /**
00483   * @brief  Displays a maximum of 20 char on the LCD.
00484   * @param  Line: the Line where to display the character shape .
00485   *   This parameter can be one of the following values:
00486   *     @arg Linex: where x can be 0..9
00487   * @param  *ptr: pointer to string to display on LCD.
00488   * @retval None
00489   */
00490 void LCD_DisplayStringLine(uint8_t Line, uint8_t *ptr)
00491 {
00492   uint16_t refcolumn = LCD_PIXEL_WIDTH - 1;
00493 
00494   /* Send the string character by character on lCD */
00495   while ((*ptr != 0) & (((refcolumn + 1) & 0xFFFF) >= LCD_Currentfonts->Width))
00496   {
00497     /* Display one character on LCD */
00498     LCD_DisplayChar(Line, refcolumn, *ptr);
00499     /* Decrement the column position by 16 */
00500     refcolumn -= LCD_Currentfonts->Width;
00501     /* Point on the next character */
00502     ptr++;
00503   }
00504 }
00505 
00506 
00507 /**
00508   * @brief  Sets a display window
00509   * @param  Xpos: specifies the X buttom left position.
00510   * @param  Ypos: specifies the Y buttom left position.
00511   * @param  Height: display window height.
00512   * @param  Width: display window width.
00513   * @retval None
00514   */
00515 void LCD_SetDisplayWindow(uint8_t Xpos, uint16_t Ypos, uint8_t Height, uint16_t Width)
00516 {
00517   /* Horizontal GRAM Start Address */
00518   if(Xpos >= Height)
00519   {
00520     LCD_WriteReg(LCD_REG_80, (Xpos - Height + 1));
00521   }
00522   else
00523   {
00524     LCD_WriteReg(LCD_REG_80, 0);
00525   }
00526   /* Horizontal GRAM End Address */
00527   LCD_WriteReg(LCD_REG_81, Xpos);
00528   /* Vertical GRAM Start Address */
00529   if(Ypos >= Width)
00530   {
00531     LCD_WriteReg(LCD_REG_82, (Ypos - Width + 1));
00532   }  
00533   else
00534   {
00535     LCD_WriteReg(LCD_REG_82, 0);
00536   }
00537   /* Vertical GRAM End Address */
00538   LCD_WriteReg(LCD_REG_83, Ypos);
00539   LCD_SetCursor(Xpos, Ypos);
00540 }
00541 
00542 
00543 /**
00544   * @brief  Disables LCD Window mode.
00545   * @param  None
00546   * @retval None
00547   */
00548 void LCD_WindowModeDisable(void)
00549 {
00550   LCD_SetDisplayWindow(239, 0x13F, 240, 320);
00551   LCD_WriteReg(LCD_REG_3, 0x1018);    
00552 }
00553 
00554 
00555 /**
00556   * @brief  Displays a line.
00557   * @param Xpos: specifies the X position.
00558   * @param Ypos: specifies the Y position.
00559   * @param Length: line length.
00560   * @param Direction: line direction.
00561   *   This parameter can be one of the following values: Vertical or Horizontal.
00562   * @retval None
00563   */
00564 void LCD_DrawLine(uint8_t Xpos, uint16_t Ypos, uint16_t Length, uint8_t Direction)
00565 {
00566   uint32_t i = 0;
00567   
00568   LCD_SetCursor(Xpos, Ypos);
00569   if(Direction == LCD_DIR_HORIZONTAL)
00570   {
00571     LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
00572     for(i = 0; i < Length; i++)
00573     {
00574       LCD_WriteRAM(TextColor);
00575     }
00576   }
00577   else
00578   {
00579     for(i = 0; i < Length; i++)
00580     {
00581       LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
00582       LCD_WriteRAM(TextColor);
00583       Xpos++;
00584       LCD_SetCursor(Xpos, Ypos);
00585     }
00586   }
00587 }
00588 
00589 
00590 /**
00591   * @brief  Displays a rectangle.
00592   * @param  Xpos: specifies the X position.
00593   * @param  Ypos: specifies the Y position.
00594   * @param  Height: display rectangle height.
00595   * @param  Width: display rectangle width.
00596   * @retval None
00597   */
00598 void LCD_DrawRect(uint8_t Xpos, uint16_t Ypos, uint8_t Height, uint16_t Width)
00599 {
00600   LCD_DrawLine(Xpos, Ypos, Width, LCD_DIR_HORIZONTAL);
00601   LCD_DrawLine((Xpos + Height), Ypos, Width, LCD_DIR_HORIZONTAL);
00602   
00603   LCD_DrawLine(Xpos, Ypos, Height, LCD_DIR_VERTICAL);
00604   LCD_DrawLine(Xpos, (Ypos - Width + 1), Height, LCD_DIR_VERTICAL);
00605 }
00606 
00607 
00608 /**
00609   * @brief  Displays a circle.
00610   * @param  Xpos: specifies the X position.
00611   * @param  Ypos: specifies the Y position.
00612   * @param  Radius
00613   * @retval None
00614   */
00615 void LCD_DrawCircle(uint8_t Xpos, uint16_t Ypos, uint16_t Radius)
00616 {
00617   int32_t  D;/* Decision Variable */ 
00618   uint32_t  CurX;/* Current X Value */
00619   uint32_t  CurY;/* Current Y Value */ 
00620   
00621   D = 3 - (Radius << 1);
00622   CurX = 0;
00623   CurY = Radius;
00624   
00625   while (CurX <= CurY)
00626   {
00627     LCD_SetCursor(Xpos + CurX, Ypos + CurY);
00628     LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
00629     LCD_WriteRAM(TextColor);
00630     LCD_SetCursor(Xpos + CurX, Ypos - CurY);
00631     LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
00632     LCD_WriteRAM(TextColor);
00633     LCD_SetCursor(Xpos - CurX, Ypos + CurY);
00634     LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
00635     LCD_WriteRAM(TextColor);
00636     LCD_SetCursor(Xpos - CurX, Ypos - CurY);
00637     LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
00638     LCD_WriteRAM(TextColor);
00639     LCD_SetCursor(Xpos + CurY, Ypos + CurX);
00640     LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
00641     LCD_WriteRAM(TextColor);
00642     LCD_SetCursor(Xpos + CurY, Ypos - CurX);
00643     LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
00644     LCD_WriteRAM(TextColor);
00645     LCD_SetCursor(Xpos - CurY, Ypos + CurX);
00646     LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
00647     LCD_WriteRAM(TextColor);
00648     LCD_SetCursor(Xpos - CurY, Ypos - CurX);
00649     LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
00650     LCD_WriteRAM(TextColor);
00651     if (D < 0)
00652     { 
00653       D += (CurX << 2) + 6;
00654     }
00655     else
00656     {
00657       D += ((CurX - CurY) << 2) + 10;
00658       CurY--;
00659     }
00660     CurX++;
00661   }
00662 }
00663 
00664 
00665 /**
00666   * @brief  Displays a monocolor picture.
00667   * @param  Pict: pointer to the picture array.
00668   * @retval None
00669   */
00670 void LCD_DrawMonoPict(const uint32_t *Pict)
00671 {
00672   uint32_t index = 0, i = 0;
00673   LCD_SetCursor(0, (LCD_PIXEL_WIDTH - 1));
00674   LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
00675   for(index = 0; index < 2400; index++)
00676   {
00677     for(i = 0; i < 32; i++)
00678     {
00679       if((Pict[index] & (1 << i)) == 0x00)
00680       {
00681         LCD_WriteRAM(BackColor);
00682       }
00683       else
00684       {
00685         LCD_WriteRAM(TextColor);
00686       }
00687     }
00688   }
00689 }
00690 
00691 
00692 /**
00693   * @brief  Displays a bitmap picture loaded in the internal Flash.
00694   * @param  BmpAddress: Bmp picture address in the internal Flash.
00695   * @retval None
00696   */
00697 void LCD_WriteBMP(uint32_t BmpAddress)
00698 {
00699   uint32_t index = 0, size = 0;
00700   /* Read bitmap size */
00701   size = *(__IO uint16_t *) (BmpAddress + 2);
00702   size |= (*(__IO uint16_t *) (BmpAddress + 4)) << 16;
00703   /* Get bitmap data address offset */
00704   index = *(__IO uint16_t *) (BmpAddress + 10);
00705   index |= (*(__IO uint16_t *) (BmpAddress + 12)) << 16;
00706   size = (size - index)/2;
00707   BmpAddress += index;
00708   /* Set GRAM write direction and BGR = 1 */
00709   /* I/D=00 (Horizontal : decrement, Vertical : decrement) */
00710   /* AM=1 (address is updated in vertical writing direction) */
00711   LCD_WriteReg(LCD_REG_3, 0x1008);
00712  
00713   LCD_WriteRAM_Prepare();
00714  
00715   for(index = 0; index < size; index++)
00716   {
00717     LCD_WriteRAM(*(__IO uint16_t *)BmpAddress);
00718     BmpAddress += 2;
00719   }
00720  
00721   /* Set GRAM write direction and BGR = 1 */
00722   /* I/D = 01 (Horizontal : increment, Vertical : decrement) */
00723   /* AM = 1 (address is updated in vertical writing direction) */
00724   LCD_WriteReg(LCD_REG_3, 0x1018);
00725 }
00726 
00727 /**
00728   * @brief  Displays a full rectangle.
00729   * @param  Xpos: specifies the X position.
00730   * @param  Ypos: specifies the Y position.
00731   * @param  Height: rectangle height.
00732   * @param  Width: rectangle width.
00733   * @retval None
00734   */
00735 void LCD_DrawFullRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
00736 {
00737   LCD_SetTextColor(TextColor);
00738 
00739   LCD_DrawLine(Xpos, Ypos, Width, LCD_DIR_HORIZONTAL);
00740   LCD_DrawLine((Xpos + Height), Ypos, Width, LCD_DIR_HORIZONTAL);
00741   
00742   LCD_DrawLine(Xpos, Ypos, Height, LCD_DIR_VERTICAL);
00743   LCD_DrawLine(Xpos, (Ypos - Width + 1), Height, LCD_DIR_VERTICAL);
00744 
00745   Width -= 2;
00746   Height--;
00747   Ypos--;
00748 
00749   LCD_SetTextColor(BackColor);
00750 
00751   while(Height--)
00752   {
00753     LCD_DrawLine(++Xpos, Ypos, Width, LCD_DIR_HORIZONTAL);    
00754   }
00755 
00756   LCD_SetTextColor(TextColor);
00757 }
00758 
00759 /**
00760   * @brief  Displays a full circle.
00761   * @param  Xpos: specifies the X position.
00762   * @param  Ypos: specifies the Y position.
00763   * @param  Radius
00764   * @retval None
00765   */
00766 void LCD_DrawFullCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
00767 {
00768   int32_t  D;    /* Decision Variable */ 
00769   uint32_t  CurX;/* Current X Value */
00770   uint32_t  CurY;/* Current Y Value */ 
00771   
00772   D = 3 - (Radius << 1);
00773 
00774   CurX = 0;
00775   CurY = Radius;
00776   
00777   LCD_SetTextColor(BackColor);
00778 
00779   while (CurX <= CurY)
00780   {
00781     if(CurY > 0) 
00782     {
00783       LCD_DrawLine(Xpos - CurX, Ypos + CurY, 2*CurY, LCD_DIR_HORIZONTAL);
00784       LCD_DrawLine(Xpos + CurX, Ypos + CurY, 2*CurY, LCD_DIR_HORIZONTAL);
00785     }
00786 
00787     if(CurX > 0) 
00788     {
00789       LCD_DrawLine(Xpos - CurY, Ypos + CurX, 2*CurX, LCD_DIR_HORIZONTAL);
00790       LCD_DrawLine(Xpos + CurY, Ypos + CurX, 2*CurX, LCD_DIR_HORIZONTAL);
00791     }
00792     if (D < 0)
00793     { 
00794       D += (CurX << 2) + 6;
00795     }
00796     else
00797     {
00798       D += ((CurX - CurY) << 2) + 10;
00799       CurY--;
00800     }
00801     CurX++;
00802   }
00803 
00804   LCD_SetTextColor(TextColor);
00805   LCD_DrawCircle(Xpos, Ypos, Radius);
00806 }
00807 
00808 /**
00809   * @brief  Displays an uni line (between two points).
00810   * @param  x1: specifies the point 1 x position.
00811   * @param  y1: specifies the point 1 y position.
00812   * @param  x2: specifies the point 2 x position.
00813   * @param  y2: specifies the point 2 y position.
00814   * @retval None
00815   */
00816 void LCD_DrawUniLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
00817 {
00818   int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0, 
00819   yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0, 
00820   curpixel = 0;
00821   
00822   deltax = ABS(x2 - x1);        /* The difference between the x's */
00823   deltay = ABS(y2 - y1);        /* The difference between the y's */
00824   x = x1;                       /* Start x off at the first pixel */
00825   y = y1;                       /* Start y off at the first pixel */
00826   
00827   if (x2 >= x1)                 /* The x-values are increasing */
00828   {
00829     xinc1 = 1;
00830     xinc2 = 1;
00831   }
00832   else                          /* The x-values are decreasing */
00833   {
00834     xinc1 = -1;
00835     xinc2 = -1;
00836   }
00837   
00838   if (y2 >= y1)                 /* The y-values are increasing */
00839   {
00840     yinc1 = 1;
00841     yinc2 = 1;
00842   }
00843   else                          /* The y-values are decreasing */
00844   {
00845     yinc1 = -1;
00846     yinc2 = -1;
00847   }
00848   
00849   if (deltax >= deltay)         /* There is at least one x-value for every y-value */
00850   {
00851     xinc1 = 0;                  /* Don't change the x when numerator >= denominator */
00852     yinc2 = 0;                  /* Don't change the y for every iteration */
00853     den = deltax;
00854     num = deltax / 2;
00855     numadd = deltay;
00856     numpixels = deltax;         /* There are more x-values than y-values */
00857   }
00858   else                          /* There is at least one y-value for every x-value */
00859   {
00860     xinc2 = 0;                  /* Don't change the x for every iteration */
00861     yinc1 = 0;                  /* Don't change the y when numerator >= denominator */
00862     den = deltay;
00863     num = deltay / 2;
00864     numadd = deltax;
00865     numpixels = deltay;         /* There are more y-values than x-values */
00866   }
00867   
00868   for (curpixel = 0; curpixel <= numpixels; curpixel++)
00869   {
00870     PutPixel(x, y);             /* Draw the current pixel */
00871     num += numadd;              /* Increase the numerator by the top of the fraction */
00872     if (num >= den)             /* Check if numerator >= denominator */
00873     {
00874       num -= den;               /* Calculate the new numerator value */
00875       x += xinc1;               /* Change the x as appropriate */
00876       y += yinc1;               /* Change the y as appropriate */
00877     }
00878     x += xinc2;                 /* Change the x as appropriate */
00879     y += yinc2;                 /* Change the y as appropriate */
00880   }
00881 }
00882 
00883 /**
00884   * @brief  Displays an polyline (between many points).
00885   * @param  Points: pointer to the points array.
00886   * @param  PointCount: Number of points.
00887   * @retval None
00888   */
00889 void LCD_PolyLine(pPoint Points, uint16_t PointCount)
00890 {
00891   int16_t X = 0, Y = 0;
00892 
00893   if(PointCount < 2)
00894   {
00895     return;
00896   }
00897 
00898   while(--PointCount)
00899   {
00900     X = Points->X;
00901     Y = Points->Y;
00902     Points++;
00903     LCD_DrawUniLine(X, Y, Points->X, Points->Y);
00904   }
00905 }
00906 
00907 /**
00908   * @brief  Displays an relative polyline (between many points).
00909   * @param  Points: pointer to the points array.
00910   * @param  PointCount: Number of points.
00911   * @param  Closed: specifies if the draw is closed or not.
00912   *           1: closed, 0 : not closed.
00913   * @retval None
00914   */
00915 static void LCD_PolyLineRelativeClosed(pPoint Points, uint16_t PointCount, uint16_t Closed)
00916 {
00917   int16_t X = 0, Y = 0;
00918   pPoint First = Points;
00919 
00920   if(PointCount < 2)
00921   {
00922     return;
00923   }  
00924   X = Points->X;
00925   Y = Points->Y;
00926   while(--PointCount)
00927   {
00928     Points++;
00929     LCD_DrawUniLine(X, Y, X + Points->X, Y + Points->Y);
00930     X = X + Points->X;
00931     Y = Y + Points->Y;
00932   }
00933   if(Closed)
00934   {
00935     LCD_DrawUniLine(First->X, First->Y, X, Y);
00936   }  
00937 }
00938 
00939 /**
00940   * @brief  Displays a closed polyline (between many points).
00941   * @param  Points: pointer to the points array.
00942   * @param  PointCount: Number of points.
00943   * @retval None
00944   */
00945 void LCD_ClosedPolyLine(pPoint Points, uint16_t PointCount)
00946 {
00947   LCD_PolyLine(Points, PointCount);
00948   LCD_DrawUniLine(Points->X, Points->Y, (Points+PointCount-1)->X, (Points+PointCount-1)->Y);
00949 }
00950 
00951 /**
00952   * @brief  Displays a relative polyline (between many points).
00953   * @param  Points: pointer to the points array.
00954   * @param  PointCount: Number of points.
00955   * @retval None
00956   */
00957 void LCD_PolyLineRelative(pPoint Points, uint16_t PointCount)
00958 {
00959   LCD_PolyLineRelativeClosed(Points, PointCount, 0);
00960 }
00961 
00962 /**
00963   * @brief  Displays a closed relative polyline (between many points).
00964   * @param  Points: pointer to the points array.
00965   * @param  PointCount: Number of points.
00966   * @retval None
00967   */
00968 void LCD_ClosedPolyLineRelative(pPoint Points, uint16_t PointCount)
00969 {
00970   LCD_PolyLineRelativeClosed(Points, PointCount, 1);
00971 }
00972 
00973 
00974 /**
00975   * @brief  Displays a  full polyline (between many points).
00976   * @param  Points: pointer to the points array.
00977   * @param  PointCount: Number of points.
00978   * @retval None
00979   */
00980 void LCD_FillPolyLine(pPoint Points, uint16_t PointCount)
00981 {
00982   /*  public-domain code by Darel Rex Finley, 2007 */
00983   uint16_t  nodes = 0, nodeX[MAX_POLY_CORNERS], pixelX = 0, pixelY = 0, i = 0,
00984   j = 0, swap = 0;
00985   uint16_t  IMAGE_LEFT = 0, IMAGE_RIGHT = 0, IMAGE_TOP = 0, IMAGE_BOTTOM = 0;
00986 
00987   IMAGE_LEFT = IMAGE_RIGHT = Points->X;
00988   IMAGE_TOP= IMAGE_BOTTOM = Points->Y;
00989 
00990   for(i = 1; i < PointCount; i++)
00991   {
00992     pixelX = POLY_X(i);
00993     if(pixelX < IMAGE_LEFT)
00994     {
00995       IMAGE_LEFT = pixelX;
00996     }
00997     if(pixelX > IMAGE_RIGHT)
00998     {
00999       IMAGE_RIGHT = pixelX;
01000     }
01001     
01002     pixelY = POLY_Y(i);
01003     if(pixelY < IMAGE_TOP)
01004     { 
01005       IMAGE_TOP = pixelY;
01006     }
01007     if(pixelY > IMAGE_BOTTOM)
01008     {
01009       IMAGE_BOTTOM = pixelY;
01010     }
01011   }
01012   
01013   LCD_SetTextColor(BackColor);  
01014 
01015   /*  Loop through the rows of the image. */
01016   for (pixelY = IMAGE_TOP; pixelY < IMAGE_BOTTOM; pixelY++) 
01017   {  
01018     /* Build a list of nodes. */
01019     nodes = 0; j = PointCount-1;
01020 
01021     for (i = 0; i < PointCount; i++) 
01022     {
01023       if (POLY_Y(i)<(double) pixelY && POLY_Y(j)>=(double) pixelY || POLY_Y(j)<(double) pixelY && POLY_Y(i)>=(double) pixelY) 
01024       {
01025         nodeX[nodes++]=(int) (POLY_X(i)+((pixelY-POLY_Y(i))*(POLY_X(j)-POLY_X(i)))/(POLY_Y(j)-POLY_Y(i))); 
01026       }
01027       j = i; 
01028     }
01029   
01030     /* Sort the nodes, via a simple “Bubble” sort. */
01031     i = 0;
01032     while (i < nodes-1) 
01033     {
01034       if (nodeX[i]>nodeX[i+1]) 
01035       {
01036         swap = nodeX[i]; 
01037         nodeX[i] = nodeX[i+1]; 
01038         nodeX[i+1] = swap; 
01039         if(i)
01040         {
01041           i--; 
01042         }
01043       }
01044       else 
01045       {
01046         i++;
01047       }
01048     }
01049   
01050     /*  Fill the pixels between node pairs. */
01051     for (i = 0; i < nodes; i+=2) 
01052     {
01053       if(nodeX[i] >= IMAGE_RIGHT) 
01054       {
01055         break;
01056       }
01057       if(nodeX[i+1] > IMAGE_LEFT) 
01058       {
01059         if (nodeX[i] < IMAGE_LEFT)
01060         {
01061           nodeX[i]=IMAGE_LEFT;
01062         }
01063         if(nodeX[i+1] > IMAGE_RIGHT)
01064         {
01065           nodeX[i+1] = IMAGE_RIGHT;
01066         }
01067         LCD_SetTextColor(BackColor);
01068         LCD_DrawLine(pixelY, nodeX[i+1], nodeX[i+1] - nodeX[i], LCD_DIR_HORIZONTAL);
01069         LCD_SetTextColor(TextColor);
01070         PutPixel(pixelY, nodeX[i+1]);
01071         PutPixel(pixelY, nodeX[i]);
01072         /* for (j=nodeX[i]; j<nodeX[i+1]; j++) PutPixel(j,pixelY); */
01073       }
01074     }
01075   } 
01076 
01077   /* draw the edges */
01078   LCD_SetTextColor(TextColor);
01079 }
01080 
01081 /**
01082   * @brief  Writes to the selected LCD register.
01083   * @param  LCD_Reg: address of the selected register.
01084   * @param  LCD_RegValue: value to write to the selected register.
01085   * @retval None
01086   */
01087 void LCD_WriteReg(uint8_t LCD_Reg, uint16_t LCD_RegValue)
01088 {
01089   /* Write 16-bit Index, then Write Reg */
01090   LCD->LCD_REG = LCD_Reg;
01091   /* Write 16-bit Reg */
01092   LCD->LCD_RAM = LCD_RegValue;
01093 }
01094 
01095 
01096 /**
01097   * @brief  Reads the selected LCD Register.
01098   * @param  LCD_Reg: address of the selected register.
01099   * @retval LCD Register Value.
01100   */
01101 uint16_t LCD_ReadReg(uint8_t LCD_Reg)
01102 {
01103   /* Write 16-bit Index (then Read Reg) */
01104   LCD->LCD_REG = LCD_Reg;
01105   /* Read 16-bit Reg */
01106   return (LCD->LCD_RAM);
01107 }
01108 
01109 
01110 /**
01111   * @brief  Prepare to write to the LCD RAM.
01112   * @param  None
01113   * @retval None
01114   */
01115 void LCD_WriteRAM_Prepare(void)
01116 {
01117   LCD->LCD_REG = LCD_REG_34;
01118 }
01119 
01120 
01121 /**
01122   * @brief  Writes to the LCD RAM.
01123   * @param  RGB_Code: the pixel color in RGB mode (5-6-5).
01124   * @retval None
01125   */
01126 void LCD_WriteRAM(uint16_t RGB_Code)
01127 {
01128   /* Write 16-bit GRAM Reg */
01129   LCD->LCD_RAM = RGB_Code;
01130 }
01131 
01132 
01133 /**
01134   * @brief  Reads the LCD RAM.
01135   * @param  None
01136   * @retval LCD RAM Value.
01137   */
01138 uint16_t LCD_ReadRAM(void)
01139 {
01140   /* Write 16-bit Index (then Read Reg) */
01141   LCD->LCD_REG = LCD_REG_34; /* Select GRAM Reg */
01142   /* Read 16-bit Reg */
01143   return LCD->LCD_RAM;
01144 }
01145 
01146 
01147 /**
01148   * @brief  Power on the LCD.
01149   * @param  None
01150   * @retval None
01151   */
01152 void LCD_PowerOn(void)
01153 {
01154 /* Power On sequence ---------------------------------------------------------*/
01155   LCD_WriteReg(LCD_REG_16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
01156   LCD_WriteReg(LCD_REG_17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
01157   LCD_WriteReg(LCD_REG_18, 0x0000); /* VREG1OUT voltage */
01158   LCD_WriteReg(LCD_REG_19, 0x0000); /* VDV[4:0] for VCOM amplitude*/
01159   _delay_(20);                 /* Dis-charge capacitor power voltage (200ms) */
01160   LCD_WriteReg(LCD_REG_16, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
01161   LCD_WriteReg(LCD_REG_17, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */
01162   _delay_(5);                  /* Delay 50 ms */
01163   LCD_WriteReg(LCD_REG_18, 0x0139); /* VREG1OUT voltage */
01164   _delay_(5);                  /* Delay 50 ms */
01165   LCD_WriteReg(LCD_REG_19, 0x1d00); /* VDV[4:0] for VCOM amplitude */
01166   LCD_WriteReg(LCD_REG_41, 0x0013); /* VCM[4:0] for VCOMH */
01167   _delay_(5);                  /* Delay 50 ms */
01168   LCD_WriteReg(LCD_REG_7, 0x0173);  /* 262K color and display ON */
01169 }
01170 
01171 
01172 /**
01173   * @brief  Enables the Display.
01174   * @param  None
01175   * @retval None
01176   */
01177 void LCD_DisplayOn(void)
01178 {
01179   /* Display On */
01180   LCD_WriteReg(LCD_REG_7, 0x0173); /* 262K color and display ON */
01181 }
01182 
01183 
01184 /**
01185   * @brief  Disables the Display.
01186   * @param  None
01187   * @retval None
01188   */
01189 void LCD_DisplayOff(void)
01190 {
01191   /* Display Off */
01192   LCD_WriteReg(LCD_REG_7, 0x0); 
01193 }
01194 
01195 
01196 /**
01197   * @brief  Configures LCD Control lines (FSMC Pins) in alternate function mode.
01198   * @param  None
01199   * @retval None
01200   */
01201 void LCD_CtrlLinesConfig(void)
01202 {
01203   GPIO_InitTypeDef GPIO_InitStructure;
01204   /* Enable FSMC, GPIOD, GPIOE, GPIOF, GPIOG and AFIO clocks */
01205   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
01206   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE |
01207                          RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOG |
01208                          RCC_APB2Periph_AFIO, ENABLE);
01209   /* Set PD.00(D2), PD.01(D3), PD.04(NOE), PD.05(NWE), PD.08(D13), PD.09(D14),
01210      PD.10(D15), PD.14(D0), PD.15(D1) as alternate function push pull */
01211   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 |
01212                                 GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_14 | 
01213                                 GPIO_Pin_15;
01214   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
01215   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
01216   GPIO_Init(GPIOD, &GPIO_InitStructure);
01217   /* Set PE.07(D4), PE.08(D5), PE.09(D6), PE.10(D7), PE.11(D8), PE.12(D9), PE.13(D10),
01218      PE.14(D11), PE.15(D12) as alternate function push pull */
01219   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | 
01220                                 GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | 
01221                                 GPIO_Pin_15;
01222   GPIO_Init(GPIOE, &GPIO_InitStructure);
01223   /* Set PF.00(A0 (RS)) as alternate function push pull */
01224   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
01225   GPIO_Init(GPIOF, &GPIO_InitStructure);
01226   /* Set PG.12(NE4 (LCD/CS)) as alternate function push pull - CE3(LCD /CS) */
01227   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
01228   GPIO_Init(GPIOG, &GPIO_InitStructure);
01229 }
01230 
01231 
01232 /**
01233   * @brief  Configures the Parallel interface (FSMC) for LCD(Parallel mode)
01234   * @param  None
01235   * @retval None
01236   */
01237 void LCD_FSMCConfig(void)
01238 {
01239   FSMC_NORSRAMInitTypeDef  FSMC_NORSRAMInitStructure;
01240   FSMC_NORSRAMTimingInitTypeDef  p;
01241 /*-- FSMC Configuration ------------------------------------------------------*/
01242 /*----------------------- SRAM Bank 4 ----------------------------------------*/
01243   /* FSMC_Bank1_NORSRAM4 configuration */
01244   p.FSMC_AddressSetupTime = 1;
01245   p.FSMC_AddressHoldTime = 0;
01246   p.FSMC_DataSetupTime = 2;
01247   p.FSMC_BusTurnAroundDuration = 0;
01248   p.FSMC_CLKDivision = 0;
01249   p.FSMC_DataLatency = 0;
01250   p.FSMC_AccessMode = FSMC_AccessMode_A;
01251   /* Color LCD configuration ------------------------------------
01252      LCD configured as follow:
01253         - Data/Address MUX = Disable
01254         - Memory Type = SRAM
01255         - Data Width = 16bit
01256         - Write Operation = Enable
01257         - Extended Mode = Enable
01258         - Asynchronous Wait = Disable */
01259   FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM4;
01260   FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
01261   FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;
01262   FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
01263   FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
01264   FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;  
01265   FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
01266   FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
01267   FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
01268   FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
01269   FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
01270   FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
01271   FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
01272   FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
01273   FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
01274   FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);  
01275   /* BANK 4 (of NOR/SRAM Bank 1~4) is enabled */
01276   FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM4, ENABLE);
01277 }
01278 
01279 /**
01280   * @brief  Displays a pixel.
01281   * @param  x: pixel x.
01282   * @param  y: pixel y.  
01283   * @retval None
01284   */
01285 static void PutPixel(int16_t x, int16_t y)
01286 { 
01287   if(x < 0 || x > 239 || y < 0 || y > 319)
01288   {
01289     return;  
01290   }
01291   LCD_DrawLine(x, y, 1, LCD_DIR_HORIZONTAL);
01292 }
01293 
01294 #ifndef USE_Delay
01295 /**
01296   * @brief  Inserts a delay time.
01297   * @param  nCount: specifies the delay time length.
01298   * @retval None
01299   */
01300 static void delay(vu32 nCount)
01301 {
01302   vu32 index = 0; 
01303   for(index = (100000 * nCount); index != 0; index--)
01304   {
01305   }
01306 }
01307 #endif /* USE_Delay*/
01308 /**
01309   * @}
01310   */ 
01311 
01312 /**
01313   * @}
01314   */ 
01315   
01316 /**
01317   * @}
01318   */ 
01319 
01320 /**
01321   * @}
01322   */ 
01323   
01324 /**
01325   * @}
01326   */  
01327 
01328 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
STM32F10x Standard Peripherals Library: Footer

 

 

 

      For complete documentation on STM32(CORTEX M3) 32-bit Microcontrollers platform visit  www.st.com/STM32