STM32F10x_StdPeriph_Examples/I2C/IOExpander/main.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    I2C/IOExpander/main.c 
00004   * @author  MCD Application Team
00005   * @version V3.4.0
00006   * @date    10/15/2010
00007   * @brief   Main program body
00008   ******************************************************************************
00009   * @copy
00010   *
00011   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00012   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
00013   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
00014   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
00015   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
00016   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00017   *
00018   * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>
00019   */ 
00020 
00021 /* Includes ------------------------------------------------------------------*/
00022 #include "main.h"
00023 
00024 /** @addtogroup STM32F10x_StdPeriph_Examples
00025   * @{
00026   */
00027 
00028 /** @addtogroup I2C_IOExpander
00029   * @{
00030   */ 
00031 
00032 /* Private typedef -----------------------------------------------------------*/
00033 /* Private define ------------------------------------------------------------*/
00034 #ifdef USE_STM3210C_EVAL 
00035   #define MESSAGE1   "   STM3210C-EVAL    " 
00036 #elif defined (USE_STM32100E_EVAL)
00037   #define MESSAGE1   "   STM32100E-EVAL   " 
00038 #endif
00039 
00040 #define MESSAGE2   "  Example on how to " 
00041 #define MESSAGE3   " use the IO Expander"   
00042 
00043 /* Private macro -------------------------------------------------------------*/
00044 /* Private variables ---------------------------------------------------------*/
00045 /* Private function prototypes -----------------------------------------------*/
00046 /* Private functions ---------------------------------------------------------*/
00047 
00048 /**
00049   * @brief  Main program.
00050   * @param  None
00051   * @retval None
00052   */
00053 int main(void)
00054 {
00055   /* Initialize LEDs and push-buttons mounted on STM3210X-EVAL board */
00056   STM_EVAL_LEDInit(LED1);
00057   STM_EVAL_LEDInit(LED2);
00058   STM_EVAL_LEDInit(LED3);
00059   STM_EVAL_LEDInit(LED4);
00060   
00061    /* Initialize the LCD */
00062 #ifdef USE_STM3210C_EVAL
00063   STM3210C_LCD_Init();
00064 #elif defined (USE_STM32100E_EVAL)
00065   STM32100E_LCD_Init();  
00066 #endif /* USE_STM3210C_EVAL */
00067  
00068   /* Clear the LCD */ 
00069   LCD_Clear(White);
00070   
00071   /* Set the LCD Back Color */
00072   LCD_SetBackColor(Blue);
00073   
00074   /* Set the LCD Text Color */
00075   LCD_SetTextColor(White);    
00076  
00077   /* Display messages on the LCD */
00078   LCD_DisplayStringLine(Line0, MESSAGE1);
00079   LCD_DisplayStringLine(Line1, MESSAGE2);
00080   LCD_DisplayStringLine(Line2, MESSAGE3);
00081   
00082   /* Configure the IO Expander */
00083   if (IOE_Config() == IOE_OK)
00084   {
00085     /* Display "IO Expander OK" on the LCD */
00086     LCD_DisplayStringLine(Line4, "   IO Expander OK   ");
00087   }
00088   else
00089   { 
00090     LCD_DisplayStringLine(Line4, "IO Expander FAILED ");
00091     LCD_DisplayStringLine(Line5, " Please Reset the  ");
00092     LCD_DisplayStringLine(Line6, "   board and start ");
00093     LCD_DisplayStringLine(Line7, "    again          ");
00094     while(1);
00095   }
00096 
00097   /* Draw a rectangle with the specifies parametres and Blue Color */
00098   LCD_SetTextColor(Blue);
00099   LCD_DrawRect(180, 310, 40, 60);
00100   
00101   /* Draw a rectangle with the specifies parametres and Red Color */
00102   LCD_SetTextColor(Red);
00103   LCD_DrawRect(180, 230, 40, 60);
00104   
00105   /* Draw a rectangle with the specifies parametres and Yellow Color */
00106   LCD_SetTextColor(Yellow);
00107   LCD_DrawRect(180, 150, 40, 60);
00108   
00109   /* Draw a rectangle with the specifies parametres and Black Color */
00110   LCD_SetTextColor(Black);
00111   LCD_DrawRect(180, 70, 40, 60);
00112   
00113 
00114 #ifdef IOE_INTERRUPT_MODE
00115 
00116  #ifdef  USE_STM32100E_EVAL
00117   /* Enable the Touch Screen interrupts */
00118   IOE_ITConfig(IOE_ITSRC_TSC);
00119   
00120  #else
00121   /* Enable the Touch Screen and Joystick interrupts */
00122   IOE_ITConfig(IOE_ITSRC_JOYSTICK | IOE_ITSRC_TSC);
00123  #endif /* USE_STM32100E_EVAL */
00124  
00125 #endif /* IOE_INTERRUPT_MODE */
00126   
00127   /* Loop infinitely */
00128   while(1)
00129   {
00130 #ifdef IOE_POLLING_MODE
00131  static TS_STATE* TS_State;
00132     
00133  #ifdef  USE_STM3210C_EVAL
00134  
00135     static JOY_State_TypeDef JoyState = JOY_NONE;
00136     
00137     /* Get the Joytick State */
00138     JoyState = IOE_JoyStickGetState();
00139     
00140     switch (JoyState)
00141     {
00142         /* None Joyestick has been selected */
00143     case JOY_NONE:
00144       LCD_DisplayStringLine(Line5, "JOY:     ----       ");
00145       break; 
00146     case JOY_UP:
00147       LCD_DisplayStringLine(Line5, "JOY:     UP         ");
00148       break;     
00149     case JOY_DOWN:
00150       LCD_DisplayStringLine(Line5, "JOY:    DOWN        ");
00151       break;          
00152     case JOY_LEFT:
00153       LCD_DisplayStringLine(Line5, "JOY:    LEFT        ");
00154       break;         
00155     case JOY_RIGHT:
00156       LCD_DisplayStringLine(Line5, "JOY:    RIGHT       ");
00157       break;                 
00158     case JOY_CENTER:
00159       LCD_DisplayStringLine(Line5, "JOY:    CENTER      ");
00160       break; 
00161     default:
00162       LCD_DisplayStringLine(Line5, "JOY:    ERROR       ");
00163       break;         
00164     }
00165  #endif /* USE_STM3210C_EVAL */
00166     
00167    
00168     /* Update the structure with the current position of the Touch screen */
00169     TS_State = IOE_TS_GetState();  
00170     
00171     if ((TS_State->TouchDetected) && (TS_State->Y < 220) && (TS_State->Y > 180))
00172     {
00173       if ((TS_State->X > 10) && (TS_State->X < 70))
00174       { 
00175       /* Display LD4 on the LCD and turn on LED4 */
00176         LCD_DisplayStringLine(Line6, " LD4                ");
00177         STM_EVAL_LEDOn(LED4);
00178       }
00179       else if ((TS_State->X > 90) && (TS_State->X < 150))
00180       {
00181       /* Display LD3 on the LCD and turn on LED3 */
00182         LCD_DisplayStringLine(Line6, "      LD3           ");
00183         STM_EVAL_LEDOn(LED3);
00184       }
00185       else if ((TS_State->X > 170) && (TS_State->X < 230))
00186       {
00187       /* Display LD2 on the LCD and turn on LED2 */
00188         LCD_DisplayStringLine(Line6, "           LD2      ");
00189         STM_EVAL_LEDOn(LED2);
00190       } 
00191       else if ((TS_State->X > 250) && (TS_State->X < 310))
00192       {
00193       /* Display LD1 on the LCD and turn on LED1 */
00194         LCD_DisplayStringLine(Line6, "                LD1 ");
00195         STM_EVAL_LEDOn(LED1);
00196       }
00197       
00198     }
00199     else
00200     {
00201     /* Turn off LED1..4 */
00202       STM_EVAL_LEDOff(LED1);
00203       STM_EVAL_LEDOff(LED2);
00204       STM_EVAL_LEDOff(LED3);
00205       STM_EVAL_LEDOff(LED4);
00206     }
00207 #endif /* IOE_POLLING_MODE */  
00208   }
00209 }
00210 
00211 #ifdef  USE_FULL_ASSERT
00212 
00213 /**
00214   * @brief  Reports the name of the source file and the source line number
00215   *         where the assert_param error has occurred.
00216   * @param  file: pointer to the source file name
00217   * @param  line: assert_param error line source number
00218   * @retval None
00219   */
00220 void assert_failed(uint8_t* file, uint32_t line)
00221 { 
00222   /* User can add his own implementation to report the file name and line number,
00223      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00224 
00225    LCD_DisplayStringLine(Line0, "assert_param error!!");
00226 
00227   /* Infinite loop */
00228   while (1)
00229   {
00230   }
00231 }
00232 #endif
00233 
00234 /******************* (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