max7219.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* MAX7219 Interaction Code
  2. * ---------------------------
  3. * For more information see
  4. * http://www.adnbr.co.uk/articles/max7219-and-7-segment-displays
  5. * ----------------------------------------------------------------------------
  6. * "THE BEER-WARE LICENSE" (Revision 42):
  7. * <shilow@ukr.net> wrote this file. As long as you retain this notice you
  8. * can do whatever you want with this stuff. If we meet some day, and you think
  9. * this stuff is worth it, you can buy me a beer in return. Shilov V.N.
  10. * ----------------------------------------------------------------------------
  11. */
  12. #include "max7219.h"
  13. void MAX7219_Config(void) {
  14. /* Настройка MAX71219 */
  15. MAX7219_WriteData(RegDecodeMode, 0x00); // все без BCD декодирования
  16. MAX7219_WriteData(RegScanLimit, MAX7219_DIGITS); // сколько цифр используем
  17. MAX7219_WriteData(RegIntensity, MAX7219_BRIGHT); // яркость из 16
  18. MAX7219_WriteData(RegPower, MAX7219_ON); // включили питание
  19. }
  20. void MAX7219_WriteData(max7219_reg_t reg, uint8_t data) {
  21. /*!< Wait wait until the completion of the transfer. */
  22. while ((SPI->SR & 0x80) != RESET);
  23. /* Down LOAD pin */
  24. SPI_LOAD_PORT->ODR &= ~(SPI_LOAD);
  25. /*!< Wait until the transmit buffer is empty */
  26. while ((SPI->SR & 0x02) == RESET);
  27. /* Send the register where the data will be stored */
  28. SPI->DR = reg; /* Write in the DR register the data to be sent*/
  29. /*!< Wait until the transmit buffer is empty */
  30. while ((SPI->SR & 0x02) == RESET);
  31. /* Send the data to be stored */
  32. SPI->DR = data; /* Write in the DR register the data to be sent*/
  33. /*!< Wait wait until the completion of the transfer. */
  34. while ((SPI->SR & 0x80) != RESET);
  35. /* Up LOAD pin */
  36. SPI_LOAD_PORT->ODR |= SPI_LOAD;
  37. }