1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- /* max7219.cpp
- * MAX7219 Interaction Code
- * ---------------------------
- * For more information see
- * http://www.adnbr.co.uk/articles/max7219-and-7-segment-displays
- *
- * Created on: 29 ñ³÷. 2016
- * Author: shilov
- */
- #include <user_config.h>
- #include <SmingCore/SmingCore.h>
- #include "configuration.h"
- #include "max7219.h"
- // çàù¸ëêà
- #define MAX7219_LOAD1 PinSet(PIN_SS)
- #define MAX7219_LOAD0 PinRes(PIN_SS)
- #define MAX7219_ON 0x01
- #define MAX7219_OFF 0x00
- #define MAX7219_BRIGHT 0x08
- // ïåðåâîä ÷èñëà 0-7 â íîìåð èíäèêàòîðà
- const uint8_t max7219_dig[8] = {
- 0x05,0x01,0x07,0x03,0x04,0x08,0x06,0x02
- };
- const uint8_t digitsInUse = 8;
- // ïðîãðàììíûé SPI. Âûâîäèò áàéò íà÷èíàÿ ñî ñòàðøåãî áèòà
- // âûõîäíûå ïèíû -- SCK, MOSI
- static void spi_SendByte (uint8_t DataByte) {
- uint8_t i; // ñ÷åò÷èê áèò
- for (i=8; i!=0; i--) {
- PinRes(PIN_SCK); // âûäàëè ñòðîá
- if (bit_is_set(DataByte,7)) { // åñëè áèò 7 == 1
- PinSet(PIN_MOSI); // MOSI = 1
- } else { // åñëè áèò 7 == 0
- PinRes(PIN_MOSI); // MOSI = 0
- }
- PinSet(PIN_SCK); // çàù¸ëêíóëè ñòðîá
- DataByte <<= 1; // ñäâèã âëåâî íà 1 áèò
- }
- }
- void MAX7219_writeData(uint8_t data_register, uint8_t data)
- {
- MAX7219_LOAD0;
- // Send the register where the data will be stored
- spi_SendByte(data_register);
- // Send the data to be stored
- spi_SendByte(data);
- MAX7219_LOAD1;
- }
- void MAX7219_Init(void) {
- // íàñòðîéêà ïèíîâ SPI
- pinMode(PIN_SS, OUTPUT);
- pinMode(PIN_MOSI, OUTPUT);
- pinMode(PIN_SCK, OUTPUT);
- PinSet(PIN_SS);
- PinSet(PIN_MOSI);
- PinSet(PIN_SCK);
- // Íàñòðîéêà MAX71219
- MAX7219_writeData(MAX7219_MODE_DECODE, 0x00); // âñå áåç BCD äåêîäèðîâàíèÿ
- MAX7219_writeData(MAX7219_MODE_SCAN_LIMIT, digitsInUse - 1); // Scan limit runs from 0.
- MAX7219_writeData(MAX7219_MODE_INTENSITY, MAX7219_BRIGHT); // ÿðêîñòü èç 16
- MAX7219_writeData(MAX7219_MODE_POWER,MAX7219_ON); // âêëþ÷èëè ïèòàíèå
- }
|