Codene
Codene
/* Private typedef
-----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* Private define
------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* Private macro
-------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* Private variables
---------------------------------------------------------*/
I2C_HandleTypeDef hi2c1;
I2S_HandleTypeDef hi2s3;
SPI_HandleTypeDef hspi1;
// display initialisation
lcd_send_cmd (0x28); // Function set --> DL=0 (4 bit mode), N = 1 (2
line display) F = 0 (5x8 characters)
HAL_Delay(1);
lcd_send_cmd (0x08); //Display on/off control --> D=0,C=0, B=0 --->
display off
HAL_Delay(1);
lcd_send_cmd (0x01); // clear display
HAL_Delay(2);
lcd_send_cmd (0x06); //Entry mode set --> I/D = 1 (increment cursor)
& S = 0 (no shift)
HAL_Delay(1);
lcd_send_cmd (0x0C); //Display on/off control --> D = 1, C and B = 0.
(Cursor and blink, last two bits)
}
void lcd_send_string (char *str)
{
while (*str) lcd_send_data (*str++);
}
void lcd_put_cur(int row, int col)
{
switch (row)
{
case 0:
col |= 0x80;
break;
case 1:
col |= 0xC0;
break;
}
lcd_send_cmd (col);
}
uint8_t BCD_to_Decimal(uint8_t bcd_value) {
return ((bcd_value >> 4) * 10) + (bcd_value & 0x0F);
}
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* MCU
Configuration--------------------------------------------------------
*/
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
MX_USB_HOST_Process();
}
/* USER CODE END 3 */
}
Code đọc điện trở (adc)
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* MCU
Configuration--------------------------------------------------------
*/
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */