Professional Documents
Culture Documents
Báo Cáo Thực Tập Vi Xử Lý Tuần 4-6
Báo Cáo Thực Tập Vi Xử Lý Tuần 4-6
BÁO CÁO
Thực tập Vi xử lý _ Tuần 4-6
SVTH:
1. Mao Đình Huân 21146463
e. Chương trình
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
unsigned char Led_Code[10] = {0xAF, 0xA0, 0x6E, 0xEA, 0xE1,
0xCB, 0xCF, 0xA2, 0xEF, 0xEB};
unsigned char Led_Position[5] = {0x08, 0x10,0x20,0x40,0x80};
/* USER CODE END Includes */
void Display_Quet_5_Led()
{
Shift_Led_Position(0);
Shift_Led_Code_5(count);
Latch_Led();
Shift_Led_Position(1);
Shift_Led_Code_4(count);
Latch_Led();
Shift_Led_Position(2);
Shift_Led_Code_3(0x40);
Latch_Led();
Shift_Led_Position(3);
Shift_Led_Code_2(count);
Latch_Led();
Shift_Led_Position(4);
Shift_Led_Code_1(count);
Latch_Led();
}
void Get_Data165()
{
HAL_GPIO_WritePin(SH165_GPIO_Port,SH165_Pin,1);
HAL_GPIO_WritePin(SH165_GPIO_Port,SH165_Pin,0);
HAL_GPIO_WritePin(SH165_GPIO_Port,SH165_Pin,1);
if(HAL_GPIO_ReadPin(Input165_GPIO_Port,Input165_Pin) ==
0)
Data75HC165 &= ~(1<<(7-i));
else
Data75HC165 |= (1<<(7-i));
int main(void)
{
/* Reset of all peripherals, Initializes the Flash interface and the
Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource =
RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct,
FLASH_LATENCY_0) != HAL_OK)
{
Error_Handler();
}
}
/**
* @brief TIM1 Initialization Function
* @param None
* @retval None
*/
static void MX_TIM1_Init(void)
{
}
/**
* @brief GPIO Initialization Function
* @param None
* @retval None
*/
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* USER CODE BEGIN MX_GPIO_Init_1 */
/* USER CODE END MX_GPIO_Init_1 */
/**
* @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 */
__disable_irq();
while (1)
{
}
/* USER CODE END Error_Handler_Debug */
}
II. CHƯƠNG TRÌNH ĐIỀU KHIỂN BĂNG TẢI VỚI TIMER NGẮT
a. Bài toán: Nhấn nút Star cấp nguồn cho hệ thống, khi cảm biến S1 có
tín hiệu sản cho băng tải chạy. Khi cảm biến S2 có tín hiệu sản phẩm
cho dừng băng tải. Nếu sau 10s (dùng Timer để đếm) cảm biến S1
không có phát hiện sản phẩm sẽ ngắt nguồn hệ thống, ngược lại hệ
thống tiếp tục vận hành. Nhấn nút Stop ngắt nguồn hệ thống.
b. Vi xử lý: STM32F207VCT6.
c. Thiết bị: Motor vận hành băng tải, cảm biến S1 và S2, nút nhấn vật lý.
d. Giá trị I/O
Giá trị chân I/O Chức năng
PB0 Motor
PD11 Button 1 (Start)
PC6 Button 2 (Stop)
PD13 Cảm biến S1
PD12 Cảm biến S2
e. Chương trình
/* Private variables ---------------------------------------------------------*/
TIM_HandleTypeDef htim1;
unsigned P1_state=0;
unsigned P2_state=0;
unsigned S1;
unsigned S2;
unsigned Time_Pause=0;
unsigned Power;
/* USER CODE END PV */
/* MCU Configuration--------------------------------------------------------
*/
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
HAL_GPIO_WritePin(Motor_GPIO_Port,Motor_Pin,1);
HAL_TIM_Base_Stop_IT(&htim1);
Time_Pause = 0;
P2_state=1;
}
else if ((P3!=0) && (P2_state==1))
{
P2_state=0;
}
//----------------------------------------------------S1_On->BangTai_On
if((Power==1) && (S1==1))
{
HAL_TIM_Base_Stop_IT(&htim1);
Time_Pause = 0;
HAL_GPIO_WritePin(Motor_GPIO_Port,Motor_Pin,0);
}
//---------------------------------------------------S2_On->BangTai_Off
if((Power==1) && (S2==1))
{
HAL_TIM_Base_Start_IT(&htim1);
HAL_GPIO_WritePin(Motor_GPIO_Port,Motor_Pin,1);
}
}
/* USER CODE END 3 */
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource =
RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct,
FLASH_LATENCY_0) != HAL_OK)
{
Error_Handler();
}
}
/**
* @brief TIM1 Initialization Function
* @param None
* @retval None
*/
static void MX_TIM1_Init(void)
{
/**
* @brief GPIO Initialization Function
* @param None
* @retval None
*/
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};