Untitled
unknown
plain_text
a year ago
3.6 kB
10
Indexable
#include "Ramdom2.h"
FLASH_EraseInitTypeDef FlashErase;
uint32_t PageError;
uint32_t begin = 0;
#define Address (0x803F800)
int flag = 0;
int flag1 = 0;
int k = 0;
int g = 0;
int16_t i = 0;
uint8_t stage = 0;
uint8_t var = 0;
uint8_t var1 = 0;
uint16_t pwm = 0;
uint16_t getDigit(uint8_t dig)
{
switch (dig)
{
case 0x00: return 0x3F;
case 0x01: return 0x06;
case 0x02: return 0x5B;
case 0x03: return 0x4F;
case 0x04: return 0x66;
case 0x05: return 0x6D;
case 0x06: return 0x7D;
case 0x07: return 0x07;
case 0x08: return 0x7F;
case 0x09: return 0x6F;
case 0x0A: return 0x77;
case 0x0B: return 0x7C;
case 0x0C: return 0x39;
case 0x0D: return 0x5E;
case 0x0E: return 0x79;
case 0x0F: return 0x71;
default: return 0x40;
}
}
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim)
{
if (htim == &htim6)
{
HAL_GPIO_WritePin(GPIOD, 0xFF00, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15, GPIO_PIN_SET);
uint16_t digit = 0;
switch (stage)
{
case 0: digit = getDigit(i / 100); break;
case 1: digit = getDigit(i / 10 % 10); break;
case 2: digit = getDigit(i % 10); break;
}
HAL_GPIO_WritePin(GPIOD, digit << 8, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOB, 1 << (13 + stage), GPIO_PIN_RESET);
stage++;
stage = stage % 3;
}
}
void AppInit()
{
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
HAL_TIM_Base_Start_IT(&htim6);
HAL_TIM_Base_Start_IT(&htim7);
FlashErase.NbPages = 1;
FlashErase.PageAddress = Address;
FlashErase.TypeErase = FLASH_TYPEERASE_PAGES;
do
{
i = *(uint32_t*)(Address + begin);
begin += 4;
} while (i != 0xFFFFFFFF);
begin -= 8;
i = *(uint32_t*)(Address + begin);
}
void AppWork()
{
static uint16_t pwm = 0;
if ((HAL_GPIO_ReadPin(GPIOD, GPIO_PIN_0) == GPIO_PIN_SET) && (flag == 0))
{
k++;
if (k > 11)
{
flag = 1;
i++;
if (i > 100)
i = 100;
htim1.Instance->CCR1 = i * 8000 / 100;
pwm = (uint16_t)((float)i / 100);
HAL_FLASH_Unlock();
begin += 4;
if (begin > 8000)
{
HAL_FLASHEx_Erase(&FlashErase, &PageError);
begin = 0;
}
HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, Address + begin, i);
HAL_FLASH_Lock();
}
}
else if (HAL_GPIO_ReadPin(GPIOD, GPIO_PIN_0) == GPIO_PIN_RESET)
{
flag = 0;
k = 0;
}
if ((HAL_GPIO_ReadPin(GPIOD, GPIO_PIN_1) == GPIO_PIN_SET) && (flag1 == 0))
{
g++;
if (g > 5)
{
flag1 = 1;
i--;
if (i < 0) i = 0;
htim1.Instance->CCR1 = i * 8000 / 100;
pwm = (uint16_t)((float)i / 100);
HAL_FLASH_Unlock();
begin += 4;
if (begin > 8000)
{
HAL_FLASHEx_Erase(&FlashErase, &PageError);
begin = 0;
}
HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, Address + begin, i);
HAL_FLASH_Lock();
}
}
else if (HAL_GPIO_ReadPin(GPIOD, GPIO_PIN_1) == GPIO_PIN_RESET)
{
flag1 = 0;
g = 0;
}
}Editor is loading...
Leave a Comment