#include "stm32c0xx_hal.h"
#include <string.h>
#include "lcd.h"
#include "keypad.h"
#define PASSWORD_LENGTH 4
// LCD Pin Mapping on GPIOB
#define RS_Pin GPIO_PIN_0
#define E_Pin GPIO_PIN_1
#define D4_Pin GPIO_PIN_2
#define D5_Pin GPIO_PIN_3
#define D6_Pin GPIO_PIN_4
#define D7_Pin GPIO_PIN_5
#define LCD_Port GPIOB
// === MAIN SETUP ===
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
char Correct_Password[PASSWORD_LENGTH + 1] = "1234";
char Entered_Password[PASSWORD_LENGTH + 1] = {0};
uint8_t password_index = 0;
int main(void) {
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
LCD_Init();
LCD_SetCursor(0, 0);
LCD_WriteString("ENTER PASSWORD:");
while (1) {
}
}
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
// Configure HSI as system clock source
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
// NO PLL available in basic config for STM32C031C6 on Wokwi
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
// Clock configuration: use HSI for SYSCLK
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
{
Error_Handler();
}
}
static void MX_GPIO_Init(void) {
__HAL_RCC_GPIOA_CLK_ENABLE(); // Ensure GPIOA clock is enabled
__HAL_RCC_GPIOB_CLK_ENABLE();
//GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitTypeDef GPIO_InitStruct = {0};
// LCD Pins PB0–PB5: Output
GPIO_InitStruct.Pin = RS_Pin|E_Pin|D4_Pin|D5_Pin|D6_Pin|D7_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(LCD_Port, &GPIO_InitStruct);
// Keypad Rows PB6–PB9: Output
GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
// Keypad Cols PB10–PB13: Input with Pull-Up
GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
//FOR RGB LED'S
// __HAL_RCC_GPIOA_CLK_ENABLE(); // Ensure GPIOA clock is enabled
GPIO_InitStruct.Pin = GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12;
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);
}
void Error_Handler(void)
{
// You can blink an LED here or print an error if needed
while (1)
{
// Infinite loop to indicate error
}
}
Loading
st-nucleo-c031c6
st-nucleo-c031c6