Professional Documents
Culture Documents
Báo Cáo Thực Tập Vi Xử Lý Tuần 7-9
Báo Cáo Thực Tập Vi Xử Lý Tuần 7-9
BÁO CÁO
Thực tập Vi xử lý _ Tuần 7-9
SVTH:
1. Mao Đình Huân 21146463
e. Chương trình
/* Private 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};
unsigned B1=0;
unsigned B2=0;
unsigned B3=0;
unsigned Led_1=0;
unsigned Led_2=0;
unsigned PWM = 0;
//-------------------------------------------------------------------------------
void Shift_Led_Position (unsigned p)
{
for (uint8_t i=0; i<8; i++)
{
HAL_GPIO_WritePin(Data_GPIO_Port, Data_Pin,
Led_Position[p]&(1<<(7-i)) );
HAL_GPIO_WritePin(Clock_GPIO_Port, Clock_Pin, 0);
HAL_GPIO_WritePin(Clock_GPIO_Port, Clock_Pin, 1);
}
}
//-------------------------------------------------------------------------------
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);
/* Infinite loop */
while (1)
{
HAL_GPIO_WritePin(E2_GPIO_Port,E2_Pin,0);
Get_Data165();
Get_Button_1();
Get_Button_2();
Get_Button_3();
Display_Quet_5_Led();
_HAL_TIM_SetCompare(&htim2,TIM_CHANNEL_3,(800*PWM)/100);
if (PWM > 95)
{
HAL_GPIO_WritePin(Loa_GPIO_Port,Loa_Pin,1);
}
else HAL_GPIO_WritePin(Loa_GPIO_Port,Loa_Pin,0); }
//-------------------------------------------------------------------------------
II. TRUYỀN DỮ LIỆU GIỮA TERMINAL VỚI VXL BẰNG USART
a. Bài toán: Truyền dữ liệu là số 0-9 từ terminal lên VXL, sau đó hiển
thị giá trị lên Led 7 đoạn.
b. Vi xử lý: STM32F207VCT6, 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
PB3 Clock output
PB5 Data output
74HC595
PE0 Latch
PE2 GND
PB4 Data input
74HC165
PE1 Clock input
PA9 USART1_Tx
PA10 USART1_Rx
unsigned B1=0;
unsigned B2=0;
unsigned B3=0;
unsigned B4=0;
int Led_Used_USART;
int Change_rx_Data;
void Display_Quet_5_Led()
{
Shift_Led_Position(0);
Shift_Led_Code_5(Led_Used_USART);
Latch_Led();
Shift_Led_Position(1);
Shift_Led_Code_4(Led_Used_USART);
Latch_Led();
Shift_Led_Position(2);
Shift_Led_Code_3(Led_Used_USART);
Latch_Led();
Shift_Led_Position(3);
Shift_Led_Code_2(Led_Used_USART);
Latch_Led();
Shift_Led_Position(4);
Shift_Led_Code_1(Led_Used_USART);
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));
void Get_Button_3()
{
if(((Data75HC165 & (1<<5)) == 0) && B3 == 0)
{
B3 = 1; //Ðã nhân
}
else if(((Data75HC165 & (1<<5)) == (1<<5)) && B3 == 1)
{
B3 = 0; //Chua nhân
}
}
void Get_Button_4()
{
if(((Data75HC165 & (1<<0)) == 0) && B4 == 0)
{
B4 = 1; //Ðã nhân
}
else if(((Data75HC165 & (1<<0)) == (1<<0)) && B4 == 1)
{
B4 = 0; //Chua nhân
}
}
Change_rx_Data = atoi(rx_Data);
//sprintf(tx_Data, "%d", Change_rx_Data);
HAL_UART_Transmit (&huart1, (unsigned
char*)tx_Data, sizeof(tx_Data), 100);
HAL_UART_Receive_IT (&huart1, (unsigned
char*)rx_Data, 1);
}
}
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* MCU Configuration--------------------------------------------------------
*/
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
// HAL_UART_Receive_IT(&huart1, (unsigned
char*)rx_Data, 1);
// Display_Quet_5_Led();
}
/* USER CODE END 3 */
}