Skocz do zawartości

Wyświetlanie danych liczbowych na LCD , STM32f7


Pomocna odpowiedź

Napisano

Witam. Mam problem z wyświetlaniem danych na lcd, pochodzących z spi, zwykły tekst bez problemu się wyświetla, główne problem leży w konwersji danych liczbowych do tekstowych. Pomoże ktoś ?

/**
 ******************************************************************************
 * File Name          : main.c
 * Description        : Main program body
 ******************************************************************************
 ** This notice applies to any and all portions of this file
 * that are not between comment pairs USER CODE BEGIN and
 * USER CODE END. Other portions of this file, whether 
 * inserted by the user or by software development tools
 * are owned by their respective copyright owners.
 *
 * COPYRIGHT(c) 2017 STMicroelectronics
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *   1. Redistributions of source code must retain the above copyright notice,
 *      this list of conditions and the following disclaimer.
 *   2. Redistributions in binary form must reproduce the above copyright notice,
 *      this list of conditions and the following disclaimer in the documentation
 *      and/or other materials provided with the distribution.
 *   3. Neither the name of STMicroelectronics nor the names of its contributors
 *      may be used to endorse or promote products derived from this software
 *      without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 ******************************************************************************
 */

/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stm32f7xx_hal.h"
#include "dma2d.h"
#include "ltdc.h"
#include "spi.h"
#include "tim.h"
#include "usart.h"
#include "gpio.h"
#include "fmc.h"

/* USER CODE BEGIN Includes */
#include "CAN_MCP2515.h"
#include "stm32746g_discovery.h"
#include "stm32746g_discovery_lcd.h"
#include "math.h"
/* USER CODE END Includes */

/* Private variables ---------------------------------------------------------*/

/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);


/* USER CODE BEGIN PFP */
/* Private function prototypes -----------------------------------------------*/
static void LCD_Config(void);
static void CPU_CACHE_Enable(void);
/* USER CODE END PFP */

/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

int main(void)
{

 /* USER CODE BEGIN 1 */
/* deklaracja zmiennych */
tMCPHardwareConfig hw;
tMCP2515Device mcp;
CAN_Frame can_msg;
unsigned char V0;
 /* USER CODE END 1 */

 /* MCU Configuration----------------------------------------------------------*/

 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
 HAL_Init();

 /* USER CODE BEGIN Init */

 /* USER CODE END Init */

 /* Configure the system clock */
 SystemClock_Config();

 /* USER CODE BEGIN SysInit */

 /* USER CODE END SysInit */

 /* Initialize all configured peripherals */
 MX_GPIO_Init();
 MX_SPI2_Init();
 MX_LTDC_Init();
 MX_DMA2D_Init();
 MX_USART1_UART_Init();
 MX_TIM1_Init();
 MX_FMC_Init();

 /* USER CODE BEGIN 2 */

CPU_CACHE_Enable();
LCD_Config();

BSP_LCD_SelectLayer(1);
BSP_LCD_SetTextColor(0xFF00FF00);
BSP_LCD_SetBackColor(0xFFFFFFFF);
BSP_LCD_DisplayStringAt(240,136,(unsigned char*)"Powitanie",RIGHT_MODE); // ZAMIAST "Powitanie wyswietlic" V0


/* inicjacja zmiennej konfiguracyjnej */
hw.GPIO_CS = GPIOI;
hw.GPIO_Pin_CS = GPIO_PIN_3;
hw.hspi = &hspi2;
/* inicjacja modulu komunikacyjnego */
MCP2515_Init(&mcp,&hw);
 /* USER CODE END 2 */

 /* Infinite loop */
 /* USER CODE BEGIN WHILE */

//uruchamiam tryb pracy
MCP2515_Start(&mcp,100000,eNORMAL);

 while (1)
 {
 /* USER CODE END WHILE */

 /* USER CODE BEGIN 3 */
	HAL_Delay(10);
if(MCP2515_NewMessage(&mcp)){
MCP2515_ReadMessage(&mcp,&can_msg);
}
//czekam na odbior

	if(can_msg.valid && (can_msg.id==0x1B4) && (can_msg.extended==0)){
//jest to poprawna wiadomosc o wskazanym identyfikatorze i typie
// zrób cos...
		can_msg.data[7] = V0;  // dane z ramki can odnosnie predkosci

}

 /* USER CODE END 3 */

}
}
/** System Clock Configuration
*/
void SystemClock_Config(void)
{

 RCC_OscInitTypeDef RCC_OscInitStruct;
 RCC_ClkInitTypeDef RCC_ClkInitStruct;
 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;

   /**Configure the main internal regulator output voltage 
   */
 __HAL_RCC_PWR_CLK_ENABLE();

 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);

   /**Initializes the CPU, AHB and APB busses clocks 
   */
 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
 RCC_OscInitStruct.HSIState = RCC_HSI_ON;
 RCC_OscInitStruct.HSICalibrationValue = 16;
 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
 RCC_OscInitStruct.PLL.PLLM = 10;
 RCC_OscInitStruct.PLL.PLLN = 210;
 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
 RCC_OscInitStruct.PLL.PLLQ = 2;
 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
 {
   _Error_Handler(__FILE__, __LINE__);
 }

   /**Initializes the CPU, AHB and APB busses clocks 
   */
 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                             |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;

 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
 {
   _Error_Handler(__FILE__, __LINE__);
 }

 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC|RCC_PERIPHCLK_USART1;
 PeriphClkInitStruct.PLLSAI.PLLSAIN = 192;
 PeriphClkInitStruct.PLLSAI.PLLSAIR = 2;
 PeriphClkInitStruct.PLLSAI.PLLSAIQ = 2;
 PeriphClkInitStruct.PLLSAI.PLLSAIP = RCC_PLLSAIP_DIV2;
 PeriphClkInitStruct.PLLSAIDivQ = 1;
 PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_2;
 PeriphClkInitStruct.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
 {
   _Error_Handler(__FILE__, __LINE__);
 }

   /**Configure the Systick interrupt time 
   */
 HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

   /**Configure the Systick 
   */
 HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

 /* SysTick_IRQn interrupt configuration */
 HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}

/* USER CODE BEGIN 4 */
static void CPU_CACHE_Enable(void)
{
 /* Enable I-Cache */
 SCB_EnableICache();

 /* Enable D-Cache */
 SCB_EnableDCache();
}

static void LCD_Config(void)
{
 /* LCD Initialization */ 
 BSP_LCD_Init();

 /* LCD Initialization */ 
 BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS);
 BSP_LCD_LayerDefaultInit(1, LCD_FB_START_ADDRESS+(BSP_LCD_GetXSize()*BSP_LCD_GetYSize()*4));

 /* Enable the LCD */ 
 BSP_LCD_DisplayOn(); 

 /* Select the LCD Background Layer  */
 BSP_LCD_SelectLayer(0);

 /* Clear the Background Layer */ 
 BSP_LCD_Clear(LCD_COLOR_BLACK);  

 /* Select the LCD Foreground Layer  */
 BSP_LCD_SelectLayer(1);

 /* Clear the Foreground Layer */ 
 BSP_LCD_Clear(LCD_COLOR_BLACK);

 /* Configure the transparency for foreground and background :
    Increase the transparency */
 BSP_LCD_SetTransparency(0, 255);
 BSP_LCD_SetTransparency(1, 255);
}
/* USER CODE END 4 */

/**
 * @brief  This function is executed in case of error occurrence.
 * @param  None
 * @retval None
 */
void _Error_Handler(char * file, int line)
{
 /* USER CODE BEGIN Error_Handler_Debug */
 /* User can add his own implementation to report the HAL error return state */
 while(1) 
 {
 }
 /* USER CODE END Error_Handler_Debug */ 
}

#ifdef USE_FULL_ASSERT

/**
  * @brief Reports the name of the source file and the source line number
  * where the assert_param error has occurred.
  * @param file: pointer to the source file name
  * @param line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t* file, uint32_t line)
{
 /* USER CODE BEGIN 6 */
 /* User can add his own implementation to report the file name and line number,
   ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
 /* USER CODE END 6 */

}

#endif

/**
 * @}
 */ 

/**
 * @}
*/ 

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

Nie ma kodu który źle wyświetla , aktualnie jest kod który wyświetla poprawnie tekst ,a chcę wyświetlić liczbę która będzie w zmiennej V0

   BSP_LCD_DisplayStringAt(240,136,(unsigned char*)"Powitanie",RIGHT_MODE); // ZAMIAST "Powitanie wyswietlic" V0 

To jak mam pomóc, skoro nie wklejasz programu który chcesz używać 🙂 Domyślam się, że musisz skonwertować liczbę (int), na napis. Pokaż jak to napisałeś, zobaczymy co z tym zrobić. Możesz też od razu poczytać o funkcji itoa() lub sprintf(). Ewentualnie napisać własną funkcję.

chodzi o to że pod zmienną V0 będą zapisywane na bieżąco wartości liczbowe z magistrali CAN. Ponieważ na tą chwilę nie mam możliwości podłączyć, to można założyć że zmienna V0=5440 i chcę to zmienną wyświetlić na LCD.

Poczytaj jak działa itoa() lub sprintf() - pierwsza jest znacznie mniej "zasobożerna", ale na F7 pewnie to bez znaczenia, więc równie dobrze możesz użyć sprintf().

  • Lubię! 1

Bądź aktywny - zaloguj się lub utwórz konto!

Tylko zarejestrowani użytkownicy mogą komentować zawartość tej strony

Utwórz konto w ~20 sekund!

Zarejestruj nowe konto, to proste!

Zarejestruj się »

Zaloguj się

Posiadasz własne konto? Użyj go!

Zaloguj się »
×
×
  • Utwórz nowe...