|
@@ -31,6 +31,7 @@
|
|
|
/* Private variables ---------------------------------------------------------*/
|
|
|
__IO uint16_t ConversionBuffer[ADC_SMPLS];
|
|
|
__IO uint8_t BufferIndex = 0;
|
|
|
+static uint16_t Voltage;
|
|
|
|
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
|
static void boardInit(void);
|
|
@@ -48,6 +49,18 @@ void main(void)
|
|
|
Delay(100);
|
|
|
if (BufferIndex >= ADC_SMPLS) {
|
|
|
BufferIndex = 0;
|
|
|
+ int8_t i;
|
|
|
+ uint32_t vbuf = 0;
|
|
|
+ for (i=0; i<64; i++) {
|
|
|
+ vbuf += ConversionBuffer[i];
|
|
|
+ }
|
|
|
+ vbuf *= ADC_VREF;
|
|
|
+ vbuf += 512;
|
|
|
+ vbuf /= 1023;
|
|
|
+ vbuf *= 45727;
|
|
|
+ vbuf += 5000;
|
|
|
+ vbuf /= 10000;
|
|
|
+ Voltage = vbuf;
|
|
|
}
|
|
|
showV();
|
|
|
showC();
|
|
@@ -57,17 +70,20 @@ void main(void)
|
|
|
|
|
|
/* Private functions ---------------------------------------------------------*/
|
|
|
static void showV(void) {
|
|
|
- LedDigits[0] = 0;
|
|
|
- LedDigits[1] = 1;
|
|
|
- LedDigits[2] = 2;
|
|
|
- LedDigits[3] = 3; //led_U;
|
|
|
+ uint16_t a = (Voltage + 5) / 10;
|
|
|
+ LedDigits[0] = a / 1000;
|
|
|
+ uint16_t b = a % 1000;
|
|
|
+ LedDigits[1] = b / 100;
|
|
|
+ uint8_t c = b % 100;
|
|
|
+ LedDigits[2] = c / 10;
|
|
|
+ LedDigits[3] = c % 10;
|
|
|
}
|
|
|
|
|
|
static void showC(void) {
|
|
|
- LedDigits[4] = 4;
|
|
|
- LedDigits[5] = 5;
|
|
|
- LedDigits[6] = 6;
|
|
|
- LedDigits[7] = 7; //led_A;
|
|
|
+ LedDigits[4] = 5;
|
|
|
+ LedDigits[5] = 6;
|
|
|
+ LedDigits[6] = 7;
|
|
|
+ LedDigits[7] = 8;
|
|
|
}
|
|
|
|
|
|
static void boardInit(void) {
|
|
@@ -88,7 +104,7 @@ static void boardInit(void) {
|
|
|
/* SWIM clock */
|
|
|
CLK->SWIMCCR = 0x00;
|
|
|
|
|
|
- /* ІЦШЕСР pin to Push-Pull, High, Fast */
|
|
|
+ /* SWITCH pin to Push-Pull, High, Fast */
|
|
|
SWITCH_PORT->ODR |= (uint8_t)(SWITCH_PIN);
|
|
|
SWITCH_PORT->DDR |= (uint8_t)(SWITCH_PIN);
|
|
|
SWITCH_PORT->CR1 |= (uint8_t)(SWITCH_PIN);
|
|
@@ -117,7 +133,7 @@ static void boardInit(void) {
|
|
|
GPIOD->CR2 |= (uint8_t)LED_SEG_AF;
|
|
|
|
|
|
/* `SPI` pins to Push-Pull, High, Fast */
|
|
|
- SPI_PORT->ODR |= (uint8_t)(SPI_SCK|SPI_DATA);
|
|
|
+ SPI_PORT->ODR = (uint8_t)(SPI_SCK|SPI_DATA);
|
|
|
SPI_PORT->DDR |= (uint8_t)(SPI_SCK|SPI_DATA);
|
|
|
SPI_PORT->CR1 |= (uint8_t)(SPI_SCK|SPI_DATA);
|
|
|
SPI_PORT->CR2 |= (uint8_t)(SPI_SCK|SPI_DATA);
|
|
@@ -139,7 +155,7 @@ static void boardInit(void) {
|
|
|
/* Clear the SPSEL bits */
|
|
|
ADC1->CR1 &= (uint8_t)(~ADC1_CR1_SPSEL);
|
|
|
/* Select the prescaler division factor according to ADC1_PrescalerSelection values */
|
|
|
- ADC1->CR1 |= (uint8_t)(ADC1_PRESSEL_FCPU_D2);
|
|
|
+ ADC1->CR1 |= (uint8_t)(ADC1_PRESSEL_FCPU_D8);
|
|
|
/* Enable the external Trigger */
|
|
|
ADC1->CR2 |= (uint8_t)(ADC1_CR2_EXTTRIG);
|
|
|
/* Set the 'Internal TIM1 TRGO event' as external trigger */
|