MCU Practice Lab 3

Creating C formatted strings

Creating C formatted strings (not printing them) – Stack Overflow 

STM32 Approach

/* USER CODE BEGIN Includes */
#include "stdlib.h"
#include "stdio.h"
#include "lcd.h"
/* USER CODE END Includes */

/* USER CODE BEGIN PV */
uint8_t row_update = 0;
char LCD_row0_s[17] = "", LCD_row1_s[17] = "";
/* USER CODE END PV */

  /* USER CODE BEGIN 2 */
	LCD_init();

	//
	sprintf(LCD_row0_s, "Print number: %d", 1);
	row_update = 1;

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
	while (1)
	{
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
		//
		if(row_update)
		{
			//
			row_update = 0;

			//
			LCD_clear();
			LCD_setCursor(0, 0);
			LCD_printf("%s", LCD_row0_s);
			LCD_setCursor(1, 0);
			LCD_printf("%s", LCD_row1_s);
		}
	}
  /* USER CODE END 3 */