123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- /**
- * Драйвер модуля LED-индикаторов
- */
- #include "stm8s.h"
- #include "led.h"
- #define GPIO_HIGH(a,b) a->ODR |= b
- #define GPIO_LOW(a,b) a->ODR &= ~b
- #define GPIO_TOGGLE(a,b) a->ODR ^= b
- uint8_t LedDigits[LED_DIGITS_NUM] = {1, 2, 3, 4, 5, 6, 7, 8}; // digits to dsplay
- uint8_t LedPoint[LED_DIGITS_NUM] = {0, 1, 0, 0, 0, 1, 0, 0}; // dots for digits
- static const uint16_t led_num[8] = {0x10, 0x20, 0x80, 0x40, 0x01, 0x02, 0x08, 0x04};
- static void led_SelectDigit (const uint8_t first);
- /*
- * Output current value to next led
- */
- 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;
- case led_Plus:
- LED_OUT_PL;
- break;
- case led_Minus:
- LED_OUT_MM;
- break;
- case led_H:
- LED_OUT_H;
- break;
- case led_O:
- LED_OUT_O;
- break;
- case led_Off:
- break;
- default:
- GPIOD->ODR &= ~(LED_SEG_D);
- }
- if(LedPoint[ledn] != 0) {
- LED_OUT_DP;
- }
- ledn ++;
- if (ledn >= LED_DIGITS_NUM) {
- ledn = 0;
- }
- }
- /*
- * 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;
- }
- }
|