Browse Source

Дабавил MAX7219, сделал вывод времени

Vladimir N. Shilov 9 years ago
parent
commit
047e6a4325
2 changed files with 145 additions and 0 deletions
  1. 74 0
      app/max7219.cpp
  2. 71 0
      include/max7219.h

+ 74 - 0
app/max7219.cpp

@@ -0,0 +1,74 @@
+/* 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); // âêëþ÷èëè ïèòàíèå
+
+}

+ 71 - 0
include/max7219.h

@@ -0,0 +1,71 @@
+/*
+ * max7219.h
+ *
+ *  Created on: 29 ñ³÷. 2016
+ *      Author: shilov
+ */
+
+#ifndef INCLUDE_MAX7219_H_
+#define INCLUDE_MAX7219_H_
+
+// symbols
+// Äëÿ BCD
+#define MAX7219_CHAR_BLANK	0x0F
+#define MAX7219_CHAR_FULL	0x88
+// áåç êîäèðîâàíèÿ
+#define SYM_Gradus			0x63
+#define SYM_LGradus			0x1D
+#define SYM_Temp			0x10
+#define SYM_Minus			0x01
+#define SYM_BLANK			0x00
+#define SYM_FULL			0xFF
+
+#define MAX7219_ON			0x01
+#define MAX7219_OFF			0x00
+#define MAX7219_BRIGHT		0x08
+
+// ðåæèìû ðàáîòû
+#define MAX7219_MODE_DECODE		0x09
+#define MAX7219_MODE_INTENSITY	0x0A
+#define MAX7219_MODE_SCAN_LIMIT	0x0B
+#define MAX7219_MODE_POWER		0x0C
+#define MAX7219_MODE_TEST		0x0F
+#define MAX7219_MODE_NOOP		0x00
+
+// ñîîòâåòñâèå ðàçðÿäîâ
+#define MAX7219_DIGIT0			0x01
+#define MAX7219_DIGIT1			0x02
+#define MAX7219_DIGIT2			0x03
+#define MAX7219_DIGIT3			0x04
+#define MAX7219_DIGIT4			0x05
+#define MAX7219_DIGIT5			0x06
+#define MAX7219_DIGIT6			0x07
+#define MAX7219_DIGIT7			0x08
+
+// ñîîòâåòñâèå áèò ñåãìåíòàì
+#define SEG_A					0
+#define SEG_B					1
+#define SEG_C					2
+#define SEG_D					3
+#define SEG_E					4
+#define SEG_F					5
+#define SEG_G					6
+#define SEG_DP					7
+
+// symbols
+// Äëÿ BCD
+#define MAX7219_CHAR_BLANK		0x0F
+#define MAX7219_CHAR_FULL		0x88
+// áåç êîäèðîâàíèÿ
+#define SYM_Gradus				0x63
+#define SYM_LGradus				0x1D
+#define SYM_Temp				0x10
+#define SYM_Minus				0x01
+#define SYM_BLANK				0x00
+#define SYM_FULL				0xFF
+
+void MAX7219_writeData(uint8_t data_register, uint8_t data);
+void MAX7219_Init(void);
+
+
+#endif /* INCLUDE_MAX7219_H_ */