/** * @brief Initializes the LCD. * @param None * @retval None */ void GL_LCD_Init(void) { /* Setups the LCD */ #if defined(USE_STM3210C_EVAL) STM3210C_LCD_Init(); #elif defined (USE_STM3210B_EVAL) STM3210B_LCD_Init(); #elif defined (USE_STM32100B_EVAL) STM32100B_LCD_Init(); #elif defined(USE_STM3210E_EVAL) STM3210E_LCD_Init(); #elif defined(USE_STM32100E_EVAL) STM32100E_LCD_Init(); #elif defined(USE_STM322xG_EVAL) STM322xG_LCD_Init(); #elif defined(USE_STM32L152_EVAL) STM32L152_LCD_Init(); #endif }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f10x_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f10x.c file */ /* Initialize LEDs, Key Button, LCD and COM port(USART) available on STM3210X-EVAL board ******************************************************/ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* USARTx configured as follow: - BaudRate = 115200 baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; STM_EVAL_COMInit(COM1, &USART_InitStructure); /* Initialize the LCD */ #ifdef USE_STM32100B_EVAL STM32100B_LCD_Init(); #elif defined (USE_STM3210B_EVAL) STM3210B_LCD_Init(); #elif defined (USE_STM3210E_EVAL) STM3210E_LCD_Init(); #elif defined (USE_STM3210C_EVAL) STM3210C_LCD_Init(); #elif defined (USE_STM32100E_EVAL) STM32100E_LCD_Init(); #endif /* Display message on STM3210X-EVAL LCD *************************************/ /* Clear the LCD */ LCD_Clear(LCD_COLOR_WHITE); /* Set the LCD Back Color */ LCD_SetBackColor(LCD_COLOR_BLUE); /* Set the LCD Text Color */ LCD_SetTextColor(LCD_COLOR_WHITE); LCD_DisplayStringLine(LCD_LINE_0, (uint8_t *)MESSAGE1); LCD_DisplayStringLine(LCD_LINE_1, (uint8_t *)MESSAGE2); LCD_DisplayStringLine(LCD_LINE_2, (uint8_t *)MESSAGE3); /* Retarget the C library printf function to the USARTx, can be USART1 or USART2 depending on the EVAL board you are using ********************************/ printf("\n\r %s", MESSAGE1); printf(" %s", MESSAGE2); printf(" %s\n\r", MESSAGE3); /* Turn on leds available on STM3210X-EVAL **********************************/ STM_EVAL_LEDOn(LED1); STM_EVAL_LEDOn(LED2); STM_EVAL_LEDOn(LED3); STM_EVAL_LEDOn(LED4); /* Add your application code here */ /* Infinite loop */ while (1) { } }
/** * @brief Main program * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f10x_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f10x.c file */ /* NVIC Configuration */ NVIC_Configuration(); /* Initialize the LCD */ #ifdef USE_STM32100E_EVAL STM32100E_LCD_Init(); #elif defined USE_STM3210E_EVAL STM3210E_LCD_Init(); #elif defined USE_STM32100B_EVAL STM32100B_LCD_Init(); #elif defined USE_STM3210B_EVAL STM3210B_LCD_Init(); #endif #ifdef USE_STM3210E_EVAL /* Disable FSMC only for STM32 High-density and XL-density devices */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, DISABLE); #endif /* USE_STM3210E_EVAL */ /* Initialize the Temperature Sensor */ LM75_Init(); if (LM75_GetStatus() == SUCCESS) { #ifdef USE_STM3210E_EVAL /* Enable FSMC */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); #endif /* USE_STM3210E_EVAL */ /* Clear the LCD */ LCD_Clear(LCD_COLOR_WHITE); /* Set the Back Color */ LCD_SetBackColor(LCD_COLOR_BLUE); /* Set the Text Color */ LCD_SetTextColor(LCD_COLOR_GREEN); LCD_DisplayStringLine(LCD_LINE_0, " Temperature "); #ifdef USE_STM3210E_EVAL /* Disable FSMC */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, DISABLE); /* Initialize the Temperature Sensor */ LM75_Init(); #endif /* USE_STM3210E_EVAL */ /* Configure the Temperature sensor device STLM75: - Thermostat mode Interrupt - Fault tolerance: 00 */ LM75_WriteConfReg(0x02); /* Configure the THYS and TOS inorder to use the SMbus alert interrupt */ LM75_WriteReg(LM75_REG_THYS, TEMPERATURE_THYS << 8); /*31ÝC*/ LM75_WriteReg(LM75_REG_TOS, TEMPERATURE_TOS << 8); /*32ÝC*/ I2C_ClearITPendingBit(LM75_I2C, I2C_IT_SMBALERT); SMbusAlertOccurred = 0; /* Infinite Loop */ while (1) { #ifdef USE_STM3210E_EVAL /* Disable FSMC */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, DISABLE); /* Initialize the Temperature Sensor */ LM75_Init(); #endif /* USE_STM3210E_EVAL */ /* Get double of Temperature value */ TempValue = LM75_ReadTemp(); #ifdef USE_STM3210E_EVAL /* Enable FSMC */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); #endif /* USE_STM3210E_EVAL */ if (TempValue <= 256) { /* Positive temperature measured */ TempCelsiusDisplay[7] = '+'; /* Initialize the temperature sensor value*/ TempValueCelsius = TempValue; } else { /* Negative temperature measured */ TempCelsiusDisplay[7] = '-'; /* Remove temperature value sign */ TempValueCelsius = 0x200 - TempValue; } /* Calculate temperature digits in ÝC */ if ((TempValueCelsius & 0x01) == 0x01) { TempCelsiusDisplay[12] = 0x05 + 0x30; TempFahrenheitDisplay[12] = 0x05 + 0x30; } else { TempCelsiusDisplay[12] = 0x00 + 0x30; TempFahrenheitDisplay[12] = 0x00 + 0x30; } TempValueCelsius >>= 1; TempCelsiusDisplay[8] = (TempValueCelsius / 100) + 0x30; TempCelsiusDisplay[9] = ((TempValueCelsius % 100) / 10) + 0x30; TempCelsiusDisplay[10] = ((TempValueCelsius % 100) % 10) + 0x30; if (TempValue > 256) { if (((9 * TempValueCelsius) / 5) <= 32) { /* Convert temperature ÝC to Fahrenheit */ TempValueFahrenheit = abs (32 - ((9 * TempValueCelsius) / 5)); /* Calculate temperature digits in ÝF */ TempFahrenheitDisplay[8] = (TempValueFahrenheit / 100) + 0x30; TempFahrenheitDisplay[9] = ((TempValueFahrenheit % 100) / 10) + 0x30; TempFahrenheitDisplay[10] = ((TempValueFahrenheit % 100) % 10) + 0x30; /* Positive temperature measured */ TempFahrenheitDisplay[7] = '+'; } else { /* Convert temperature ÝC to Fahrenheit */ TempValueFahrenheit = abs(((9 * TempValueCelsius) / 5) - 32); /* Calculate temperature digits in ÝF */ TempFahrenheitDisplay[8] = (TempValueFahrenheit / 100) + 0x30; TempFahrenheitDisplay[9] = ((TempValueFahrenheit % 100) / 10) + 0x30; TempFahrenheitDisplay[10] = ((TempValueFahrenheit % 100) % 10) + 0x30; /* Negative temperature measured */ TempFahrenheitDisplay[7] = '-'; } } else { /* Convert temperature ÝC to Fahrenheit */ TempValueFahrenheit = ((9 * TempValueCelsius) / 5) + 32; /* Calculate temperature digits in ÝF */ TempFahrenheitDisplay[8] = (TempValueFahrenheit / 100) + 0x30; TempFahrenheitDisplay[9] = ((TempValueFahrenheit % 100) / 10) + 0x30; TempFahrenheitDisplay[10] = ((TempValueFahrenheit % 100) % 10) + 0x30; /* Positive temperature measured */ TempFahrenheitDisplay[7] = '+'; } /* Display Fahrenheit value on LCD */ for (index = 0; index < 20; index++) { LCD_DisplayChar(LCD_LINE_6, (319 - (16 * index)), TempCelsiusDisplay[index]); LCD_DisplayChar(LCD_LINE_7, (319 - (16 * index)), TempFahrenheitDisplay[index]); } if (SMbusAlertOccurred == 1) { /* Set the Back Color */ LCD_SetBackColor(LCD_COLOR_BLUE); /* Set the Text Color */ LCD_SetTextColor(LCD_COLOR_RED); LCD_DisplayStringLine(LCD_LINE_2, "Warning: Temp exceed"); LCD_DisplayStringLine(LCD_LINE_3, " 32 C "); } if (SMbusAlertOccurred == 2) { /* Set the Back Color */ LCD_SetBackColor(LCD_COLOR_WHITE); /* Set the Text Color */ LCD_SetTextColor(LCD_COLOR_WHITE); LCD_ClearLine(LCD_LINE_2); LCD_ClearLine(LCD_LINE_3); SMbusAlertOccurred = 0; /* Set the Back Color */ LCD_SetBackColor(LCD_COLOR_BLUE); /* Set the Text Color */ LCD_SetTextColor(LCD_COLOR_GREEN); } } }