|
@@ -21,27 +21,19 @@
|
|
|
#include "stm8s.h"
|
|
|
#include "board.h"
|
|
|
#include "i2c.h"
|
|
|
+#include "led.h"
|
|
|
|
|
|
/* Private define ------------------------------------------------------------*/
|
|
|
#define TIM4_PERIOD (uint8_t)124
|
|
|
-// time to show one led digit, ms
|
|
|
-#define LED_ONE_PERIOD 2
|
|
|
|
|
|
/* Private typedef -----------------------------------------------------------*/
|
|
|
/* Private constants ---------------------------------------------------------*/
|
|
|
-static const uint16_t led_num[8] = {0x10, 0x20, 0x80, 0x40, 0x01, 0x02, 0x08, 0x04};
|
|
|
-
|
|
|
/* Private variables ---------------------------------------------------------*/
|
|
|
__IO uint16_t ConversionBuffer[ADC_SMPLS];
|
|
|
__IO uint8_t BufferIndex = 0;
|
|
|
-__IO uint8_t LedCnt = 0;
|
|
|
-static uint8_t LedDigits[8] = {1, 2, 3, 4, 5, 6, 7, 8}; // digits to dsplay
|
|
|
-static uint8_t LedPoint[8] = {0, 0, 0, 1, 0, 0, 0, 1}; // dots for digits
|
|
|
|
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
|
static void boardInit(void);
|
|
|
-static void led_SelectDigit (uint8_t first);
|
|
|
-static void led_OutputValue(void);
|
|
|
|
|
|
void main(void)
|
|
|
{
|
|
@@ -53,10 +45,6 @@ void main(void)
|
|
|
|
|
|
/* Infinite loop */
|
|
|
while (1) {
|
|
|
- if (LedCnt >= LED_ONE_PERIOD) {
|
|
|
- LedCnt = 0;
|
|
|
- led_OutputValue();
|
|
|
- }
|
|
|
|
|
|
wfi();
|
|
|
}
|
|
@@ -64,64 +52,6 @@ void main(void)
|
|
|
}
|
|
|
|
|
|
/* Private functions ---------------------------------------------------------*/
|
|
|
-/*
|
|
|
- * Output current value to next led
|
|
|
- */
|
|
|
-static void led_OutputValue(void) {
|
|
|
- static uint8_t ledn = 0;
|
|
|
-
|
|
|
- /* all off */
|
|
|
- LED_OUT_OFF;
|
|
|
-
|
|
|
- /* Fire on nex led */
|
|
|
- led_SelectDigit(ledn);
|
|
|
-
|
|
|
- /* out next value */
|
|
|
- switch (LedDigits[ledn]) {
|
|
|
- case 0:
|
|
|
- LED_OUT_0;
|
|
|
- break;
|
|
|
- case 1:
|
|
|
- LED_OUT_1;
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- LED_OUT_2;
|
|
|
- break;
|
|
|
- case 3:
|
|
|
- LED_OUT_3;
|
|
|
- break;
|
|
|
- case 4:
|
|
|
- LED_OUT_4;
|
|
|
- break;
|
|
|
- case 5:
|
|
|
- LED_OUT_5;
|
|
|
- break;
|
|
|
- case 6:
|
|
|
- LED_OUT_6;
|
|
|
- break;
|
|
|
- case 7:
|
|
|
- LED_OUT_7;
|
|
|
- break;
|
|
|
- case 8:
|
|
|
- LED_OUT_8;
|
|
|
- break;
|
|
|
- case 9:
|
|
|
- LED_OUT_9;
|
|
|
- break;
|
|
|
- default:
|
|
|
- LED_OUT_MM;
|
|
|
- }
|
|
|
- /*
|
|
|
- if(LedPoint[ledn] != 0) {
|
|
|
- LED_OUT_DP;
|
|
|
- }
|
|
|
- */
|
|
|
- ledn ++;
|
|
|
- if (ledn > 7) {
|
|
|
- ledn = 0;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
static void boardInit(void) {
|
|
|
/* Насколько я понял, для частот выше 16МГц нужно вводить задержку при работе с FLASH:
|
|
|
- Before using the HSE clock make sure that the "Flash_Wait_States" is set to 1.
|
|
@@ -225,28 +155,6 @@ static void boardInit(void) {
|
|
|
TIM4->CR1 |= (uint8_t)TIM4_CR1_CEN;
|
|
|
}
|
|
|
|
|
|
-/*
|
|
|
- * Select LED Digit.
|
|
|
- * If first != 0 - select next, by shift '1' on outputs,
|
|
|
- * else select first digit.
|
|
|
- * led digits sequence (b - bottom, t - top):
|
|
|
- * b1, b2, b4, b3, t1, t2, t4, t3.
|
|
|
- */
|
|
|
-static void led_SelectDigit (const uint8_t first) {
|
|
|
- uint8_t i;
|
|
|
- uint8_t data = led_num[first];
|
|
|
- for (i=0; i<8; i++) {
|
|
|
- GPIO_LOW(SPI_PORT, SPI_SCK); // prepare CLK
|
|
|
- if (data & 0x80) { // if msb == 1
|
|
|
- GPIO_HIGH(SPI_PORT, SPI_DATA); // DATA = 1
|
|
|
- } else {
|
|
|
- GPIO_LOW(SPI_PORT, SPI_DATA); // DATA = 0
|
|
|
- }
|
|
|
- GPIO_HIGH(SPI_PORT, SPI_SCK); // shift bit
|
|
|
- data <<= 1;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
#ifdef USE_FULL_ASSERT
|
|
|
/**
|
|
|
* @brief Reports the name of the source file and the source line number
|