451
/* Includes ------------------------------------------------------------------*/ #include "main.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* Private variables ---------------------------------------------------------*/ UART_HandleTypeDef huart1; /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_USART1_UART_Init(void); /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ uint16_t number[10] = { 0b00000011, 0b10011111, 0b00100101, 0b00001101, 0b10011001, 0b01001001, 0b01000001, 0b00011011, 0b00000001, 0b00001001 }; /* USER CODE END 0 */ int main(void) { /* USER CODE BEGIN 1 */ int cnt=0; uint16_t data = 0; /* USER CODE END 1 */ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ static uint8_t cnt = 0; // Counter from 0 to 9 uint8_t data = number[cnt]; // Get the data for the current count HAL_GPIO_WritePin(GPIOA, SRCLR_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(OE_GPIO_Port, OE_Pin, GPIO_PIN_SET); for(int i = 0; i < 8; i++) { if(data & (1 << i)) { HAL_GPIO_WritePin(GPIOA, SER_Pin, GPIO_PIN_SET); // SER_Pin, 1 } else { HAL_GPIO_WritePin(GPIOA, SER_Pin, GPIO_PIN_RESET); // SER_Pin, 0 } HAL_GPIO_WritePin(GPIOA, SRCLK_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(GPIOA, SRCLK_Pin, GPIO_PIN_RESET); } HAL_GPIO_WritePin(GPIOA, RCLK_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(GPIOA, RCLK_Pin, GPIO_PIN_RESET); HAL_GPIO_WritePin(OE_GPIO_Port, OE_Pin, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOA, SRCLR_Pin, GPIO_PIN_RESET); cnt = (cnt + 1) % 10; // Increment counter and wrap around to 0 after 9 HAL_Delay(1000); // Delay to make the counter increment every second (adjust as needed) } /* USER CODE END 3 */ }