/* Includes ------------------------------------------------------------------*/
#include "LEDC.h"
/* Private typedef -----------------------------------------------------------*/
typedef struct
{
char ch;
uint8_t Data;
} LED_CODING_TypeDef;
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
MultiTimer LEDC_MultiTimer;
/* Private variables ---------------------------------------------------------*/
const LED_CODING_TypeDef LED_CODE_Table[38] =
{
{' ', 0x00},
{'0', 0x3F},
{'1', 0x06},
{'2', 0x5B},
{'3', 0x4F},
{'4', 0x66},
{'5', 0x6D},
{'6', 0x7D},
{'7', 0x07},
{'8', 0x7F},
{'9', 0x6F},
{'A', 0x77},
{'b', 0x7C},
{'c', 0x58},
{'C', 0x39},
{'d', 0x5E},
{'E', 0x79},
{'F', 0x71},
{'g', 0x6F},
{'H', 0x76},
{'h', 0x74},
{'i', 0x04},
{'I', 0x30},
{'J', 0x1E},
{'l', 0x30},
{'L', 0x38},
{'n', 0x54},
{'o', 0x5C},
{'O', 0x3F},
{'P', 0x73},
{'q', 0x67},
{'r', 0x50},
{'S', 0x6D},
{'t', 0x78},
{'u', 0x1C},
{'U', 0x3E},
{'y', 0x6E},
{'-', 0x40},
};
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/* Exported variables --------------------------------------------------------*/
/* Exported function prototypes ----------------------------------------------*/
/*******************************************************************************
* [url=home.php?mod=space&uid=247401]@brief[/url]
* @param
* @retval
* [url=home.php?mod=space&uid=93590]@Attention[/url]
*******************************************************************************/
uint8_t LEDC_GetCode(char ch)
{
uint8_t SEGn[8] =
{
0x10, /* a :SEG4 */
0x80, /* b :SEG7 */
0x04, /* c :SEG2 */
0x20, /* d :SEG5 */
0x08, /* e :SEG3 */
0x01, /* f :SEG0 */
0x40, /* g :SEG6 */
0x02, /* dp:SEG1 */
};
for(uint8_t i = 0; i < 38; i++)
{
if(ch == LED_CODE_Table[i].ch)
{
uint8_t Data = 0;
uint8_t Temp = LED_CODE_Table[i].Data;
for(uint8_t j = 0; j < 8; j++)
{
if((Temp >> j) & 0x01) Data += SEGn[j];
}
return Data;
}
}
return 0x00;
}
/*******************************************************************************
* [url=home.php?mod=space&uid=247401]@brief[/url]
* @param
* @retval
* [url=home.php?mod=space&uid=93590]@Attention[/url]
*******************************************************************************/
void LEDC_MultiTimerCallback(MultiTimer *timer, void *userData)
{
static uint8_t Index = 0;
LEDC_SetData(4, LEDC_GetCode(LED_CODE_Table[Index].ch));
LEDC_SetData(5, LEDC_GetCode(LED_CODE_Table[Index].ch));
LEDC_SetData(6, LEDC_GetCode(LED_CODE_Table[Index].ch));
LEDC_SetData(7, LEDC_GetCode(LED_CODE_Table[Index].ch));
Index = (Index + 1) % 38;
MultiTimerStart(&LEDC_MultiTimer, 250, LEDC_MultiTimerCallback, "LEDC");
}
/*******************************************************************************
* [url=home.php?mod=space&uid=247401]@brief[/url]
* @param
* @retval
* [url=home.php?mod=space&uid=93590]@Attention[/url]
*******************************************************************************/
void LEDC_Configuration(void)
{
LEDC_InitTypeDef LEDC_InitStruct;
CKCU_PeripClockConfig_TypeDef CKCUClock = {{0}};
CKCUClock.Bit.LEDC = 1;
CKCUClock.Bit.AFIO = 1;
CKCU_PeripClockConfig(CKCUClock, ENABLE);
/* SEG0~7 */
AFIO_GPxConfig(GPIO_PA, AFIO_PIN_0, AFIO_FUN_LEDC);
AFIO_GPxConfig(GPIO_PA, AFIO_PIN_1, AFIO_FUN_LEDC);
AFIO_GPxConfig(GPIO_PA, AFIO_PIN_2, AFIO_FUN_LEDC);
AFIO_GPxConfig(GPIO_PA, AFIO_PIN_3, AFIO_FUN_LEDC);
AFIO_GPxConfig(GPIO_PD, AFIO_PIN_4, AFIO_FUN_LEDC);
AFIO_GPxConfig(GPIO_PD, AFIO_PIN_5, AFIO_FUN_LEDC);
AFIO_GPxConfig(GPIO_PD, AFIO_PIN_2, AFIO_FUN_LEDC);
AFIO_GPxConfig(GPIO_PA, AFIO_PIN_7, AFIO_FUN_LEDC);
/* COM0~4 */
AFIO_GPxConfig(GPIO_PC, AFIO_PIN_4, AFIO_FUN_LEDC);
AFIO_GPxConfig(GPIO_PC, AFIO_PIN_5, AFIO_FUN_LEDC);
AFIO_GPxConfig(GPIO_PC, AFIO_PIN_6, AFIO_FUN_LEDC);
AFIO_GPxConfig(GPIO_PC, AFIO_PIN_7, AFIO_FUN_LEDC);
/* Frame = fCK_LED / (LEDC_DutyClockNumber * COM Number) */
/* = 1600 / (8*4) = 50Hz */
LEDC_InitStruct.LEDC_ClockSource = LEDC_SRC_LSI; /* LSI = 32Khz */
LEDC_InitStruct.LEDC_ClockPrescaler = 20 - 1; /* fCK_LED = 32Khz / 20 = 1600 Hz */
LEDC_InitStruct.LEDC_DutyClockNumber = LEDC_DTYNUM_8; /* Duty CLock Number = 8 Clock */
LEDC_InitStruct.LEDC_COMxEN = LEDC_COM4EN | LEDC_COM5EN | LEDC_COM6EN | LEDC_COM7EN;
/* Change the brightness, the parameter range is 0~Duty (CLock Number-1.) */
/* 0: the brightest, 7: the darkest. */
LEDC_InitStruct.LEDC_DeadTime = 0;
LEDC_Init(&LEDC_InitStruct);
/* Set the LEDC mode to COMMON_CATHODE. */
LEDC_SetPolarityMode(LEDC_COM4POL | LEDC_COM5POL | LEDC_COM6POL | LEDC_COM7POL,
LEDC_SEG0POL | LEDC_SEG1POL | LEDC_SEG2POL | LEDC_SEG3POL | LEDC_SEG4POL | LEDC_SEG5POL | LEDC_SEG6POL | LEDC_SEG7POL,
COMMON_CATHODE);
LEDC_IntConfig(ENABLE);
NVIC_EnableIRQ(LEDC_IRQn);
LEDC_Cmd(ENABLE);
MultiTimerStart(&LEDC_MultiTimer, 250, LEDC_MultiTimerCallback, "LEDC");
}
/*******************************************************************************
* @brief
* @param
* @retval
* @attention
*******************************************************************************/
void LEDC_IRQHandler(void)
{
if(LEDC_GetFlagStatus())
{
LEDC_ClearFlagStatus();
}
}