Skip to content

Commit

Permalink
Deleted unnencessary files for tutorial 43 WAV and added Tutorial 11 …
Browse files Browse the repository at this point in the history
…- LCD16x2 library files
  • Loading branch information
MYaqoobEmbedded committed Jun 26, 2020
1 parent 2017a01 commit b86941b
Show file tree
Hide file tree
Showing 11 changed files with 1,964 additions and 0 deletions.
423 changes: 423 additions & 0 deletions Tutorial 11 - LCD16x2/lcd16x2.c

Large diffs are not rendered by default.

106 changes: 106 additions & 0 deletions Tutorial 11 - LCD16x2/lcd16x2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
Library: lcd16x2 - Parallel 8/4 bits
Written by: Mohamed Yaqoob
Date Written: 04/12/2017
Updated: 26/06/2020
Description: This is a library for the standard 16X2 LCD display, for the STM32 MCUs based on HAL libraries.
It perfroms the basic Text/Number printing to your 16X2 LCD, in 8 bits and 4 bits modes of operation.
References**:
This was written based on the open source Arduino LiquidCrystal library
and by referring to the DATASHEET of the LCD16X2, also with the help of
the following YouTube tutorials on LCD 16X2:
(1): 'RC Tractor Guy' YouTube tutorial on the following link:
https://www.youtube.com/watch?v=efi2nlsvbCI
(2): 'Explore Embedded' YouTube tutorial on the following link:
https://www.youtube.com/watch?v=YDJISiPUdA8
* Copyright (C) 2017 - M.Yaqoob - MutexEmbedded
This is a free software under the GNU license, you can redistribute it and/or modify it under the terms
of the GNU General Public License version 3 as published by the Free Software Foundation.
This software library is shared with public for educational purposes, without WARRANTY and Author is not liable for any damages caused directly
or indirectly by this software, read more about this on the GNU General Public License.
*/

#ifndef LCD16X2_H_
#define LCD16X2_H_

#include <stdbool.h>
#include "main.h"

//Floating point linker flag: -u _printf_float

/**
* @brief Initialise LCD on 8-bits mode
* @param[in] *port_rs_e RS and EN GPIO Port (e.g. GPIOB)
* @param[in] *port_0_3 D0 to D3 GPIO Port
* @param[in] *port_4_7 D4 to D7 GPIO Port
* @param[in] x_pin GPIO pin (e.g. GPIO_PIN_1)
*/
void lcd16x2_init_8bits(
GPIO_TypeDef* port_rs_e, uint16_t rs_pin, uint16_t e_pin,
GPIO_TypeDef* port_0_3, uint16_t d0_pin, uint16_t d1_pin, uint16_t d2_pin, uint16_t d3_pin,
GPIO_TypeDef* port_4_7, uint16_t d4_pin, uint16_t d5_pin, uint16_t d6_pin, uint16_t d7_pin);

/**
* @brief Initialise LCD on 4-bits mode
* @param[in] *port_4_7 D4 to D7 GPIO Port
* @param[in] x_pin GPIO pin (e.g. GPIO_PIN_1)
*/
void lcd16x2_init_4bits(
GPIO_TypeDef* port_rs_e, uint16_t rs_pin, uint16_t e_pin,
GPIO_TypeDef* port_4_7, uint16_t d4_pin, uint16_t d5_pin, uint16_t d6_pin, uint16_t d7_pin);

/**
* @brief Set cursor position
* @param[in] row - 0 or 1 for line1 or line2
* @param[in] col - 0 - 15 (16 columns LCD)
*/
void lcd16x2_setCursor(uint8_t row, uint8_t col);
/**
* @brief Move to beginning of 1st line
*/
void lcd16x2_1stLine(void);
/**
* @brief Move to beginning of 2nd line
*/
void lcd16x2_2ndLine(void);

/**
* @brief Select LCD Number of lines mode
*/
void lcd16x2_twoLines(void);
void lcd16x2_oneLine(void);

/**
* @brief Cursor ON/OFF
*/
void lcd16x2_cursorShow(bool state);

/**
* @brief Display clear
*/
void lcd16x2_clear(void);

/**
* @brief Display ON/OFF, to hide all characters, but not clear
*/
void lcd16x2_display(bool state);

/**
* @brief Shift content to right
*/
void lcd16x2_shiftRight(uint8_t offset);

/**
* @brief Shift content to left
*/
void lcd16x2_shiftLeft(uint8_t offset);

/**
* @brief Print to display any datatype (e.g. lcd16x2_printf("Value1 = %f", 123.45))
*/
void lcd16x2_printf(const char* str, ...);

#endif /* LCD16X2_H_ */
231 changes: 231 additions & 0 deletions Tutorial 11 - LCD16x2/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "lcd16x2.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

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

/* USER CODE BEGIN PV */

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */

/* 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();
/* USER CODE BEGIN 2 */
lcd16x2_init_4bits(RS_GPIO_Port, RS_Pin, E_Pin,
// D0_GPIO_Port, D0_Pin, D1_Pin, D2_Pin, D3_Pin,
D4_GPIO_Port, D4_Pin, D5_Pin, D6_Pin, D7_Pin);

lcd16x2_printf("Hello World");
HAL_Delay(1000);
/* USER CODE END 2 */

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

/* USER CODE BEGIN 3 */
lcd16x2_1stLine();
lcd16x2_printf("Temperature 4bits");
HAL_Delay(1000);
lcd16x2_2ndLine();
lcd16x2_printf("%.2f C", 25.7824);
HAL_Delay(1000);
lcd16x2_clear();
HAL_Delay(500);
}
/* USER CODE END 3 */
}

/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

/** Configure the main internal regulator output voltage
*/
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
/** Initializes the CPU, AHB and APB busses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 4;
RCC_OscInitStruct.PLL.PLLN = 168;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 7;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** 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();
}
}

/**
* @brief GPIO Initialization Function
* @param None
* @retval None
*/
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};

/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOH_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();

/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOD, D0_Pin|D1_Pin|D2_Pin|D3_Pin
|D4_Pin|D5_Pin|D6_Pin|D7_Pin, GPIO_PIN_RESET);

/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOB, RS_Pin|E_Pin, GPIO_PIN_RESET);

/*Configure GPIO pins : D0_Pin D1_Pin D2_Pin D3_Pin
D4_Pin D5_Pin D6_Pin D7_Pin */
GPIO_InitStruct.Pin = D0_Pin|D1_Pin|D2_Pin|D3_Pin
|D4_Pin|D5_Pin|D6_Pin|D7_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

/*Configure GPIO pins : RS_Pin E_Pin */
GPIO_InitStruct.Pin = RS_Pin|E_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

}

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */

/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */

/* 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,
tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Binary file removed Tutorial 43 - WAV Player.zip
Binary file not shown.
Loading

0 comments on commit b86941b

Please sign in to comment.