Laporan Akhir 2
PERCOBAAN 8
1. Prosedur[Kembali]
- Rangkai semua komponen sesuai dengan percobaan pada modul
- Buat program untuk STM32 program STM32CubeIDE
- Simulasikan rangkaian
3. Rangkaian Simulasi dan Prinsip Kerja[Kembali]
4. Flowchart dan Listing Program[Kembali]
#include "main.h"
void SystemClock_Config(void); static void MX_GPIO_Init(void);
int main(void)
{
HAL_Init(); SystemClock_Config(); MX_GPIO_Init();
while (1)
{
uint8_t pir_status = HAL_GPIO_ReadPin(GPIOB, PIR_Pin);
uint8_t touch_status = HAL_GPIO_ReadPin(GPIOB, TOUCH_Pin);
HAL_GPIO_WritePin(GPIOA, GREEN_Pin | RED_Pin | BUZZER_Pin,
GPIO_PIN_RESET);
if (pir_status == GPIO_PIN_SET)
{
HAL_GPIO_WritePin(GPIOA, RED_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOA, BUZZER_Pin, GPIO_PIN_SET);
}
if (touch_status == GPIO_PIN_SET)
{
HAL_GPIO_WritePin(GPIOA, GREEN_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOA, BUZZER_Pin, GPIO_PIN_SET);
}
HAL_Delay(100);
}
}
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|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();
}
}
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
HAL_RCC_GPIOD_CLK_ENABLE();
HAL_RCC_GPIOA_CLK_ENABLE();
HAL_RCC_GPIOB_CLK_ENABLE();
HAL_GPIO_WritePin(GPIOA, RED_Pin|GREEN_Pin|BUZZER_Pin,
GPIO_PIN_RESET);
HAL_GPIO_WritePin(BLUE_GPIO_Port, BLUE_Pin, GPIO_PIN_RESET);
GPIO_InitStruct.Pin = RED_Pin|GREEN_Pin|BUZZER_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pin = BLUE_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(BLUE_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = PIR_Pin|TOUCH_Pin; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}
void Error_Handler(void)
{
disable_irq(); while (1)
{
}
}
#ifdef USE_FULL_ASSERT
void assert_failed(uint8_t *file, uint32_t line)
{
Komentar
Posting Komentar