Module de 8 caractères piloté par un MAX7219
Le MAX7219 fonctionne à l’aide de registres :
Register Name | Register Address | Meaning |
---|---|---|
DIGIT0 | 1 | Right-most digit value |
DIGIT1 | 2 | Next digit value |
DIGIT2 | 3 | digit value |
DIGIT3 | 4 | digit value |
DIGIT4 | 5 | digit value |
DIGIT5 | 6 | digit value |
DIGIT6 | 7 | digit value |
DIGIT7 | 8 | Left-most digit value |
Decode Mode | 9 | With 1 bit for each of digit 0-7; if set, interpret the digit as a BCD digit to display. If not set, the bits in the digit register directly light up the 7-segments |
Intensity | 0x0A | The proportion of time the display segments are on and how bright is the display |
Scan Limit | 0x0B | How many of DIGIT0 through DIGIT7 are displayed |
Shutdown | 0x0C | If 0, turn display off; If 1, turn display on |
Display Test | 0x0F | If 0, turn test mode off; If 1, turn test mode on |
Pour écrire sur l’afficheur « 123 », il faut suivre l’algorithme suivant :
- Set the SHUTDOWN register to off
- Set the DIGIT0 register to “3”
- Set the DIGIT1 register to “2”
- Set the DIGIT2 register to “1”
- Set the DECODEMODE register to binary 00000111, so the 3 right-most digits are decoded.
- Set the SCANLIMIT register to 2, so digits 0, 1, 2 and 3 are displayed
- Set the SHUTDOWN register to on, to turn the display back on
Pour écrire dans un registre on peut utiliser la fonction suivante :
// ... write a value into a max7219 register
// See MAX7219 Datasheet, Table 1, page 6
void set_register(byte reg, byte value)
{
digitalWrite(MAX7219_CS, LOW);
shiftOut(MAX7219_DIN, MAX7219_CLK, MSBFIRST, reg);
shiftOut(MAX7219_DIN, MAX7219_CLK, MSBFIRST, value);
digitalWrite(MAX7219_CS, HIGH);
}
Pour allumer certains segments (et par exemple écrire des lettres) on utilise le tableau suivant :
Ainsi les lettres « C » et » F » donneront :
Dp | A | B | C | D | E | F | G | |
---|---|---|---|---|---|---|---|---|
Symbol C | 0 | 1 | 0 | 0 | 1 | 1 | 1 | 0 |
Symbol F | 0 | 1 | 0 | 0 | 0 | 1 | 1 | 1 |
Soit : const byte C = 0b01001110;
const byte F = 0b01000111;
set_register(0x01, C);
etset_register(0x01, F);
Pour afficher la virgule on utilise la syntaxe :
set_register(5, tempString.charAt(1) | DP); // plus dec. point
Avec DP égal à const byte DP = 0b10000000;
Exemple de sketch affichant à gauche « Stop » ou « Go » et à droite un compteur (Afficheur_8.ino)
Utilisation de la librairie « LedControl » :
A Télécharger ici
La définition d’un afficheur ce fait selon le code :
#include "LedControl.h"
/*
pin 12 is connected to the DataIn // DIN
pin 11 is connected to the CLK // CLK
pin 10 is connected to LOAD // CS
*/
LedControl lc = LedControl(12, 11, 10, 1);
/* we always wait a bit between updates of the display */
unsigned long delaytime = 250;
void setup() {
lc.shutdown(0, false);
/* Set the brightness to a medium values */
lc.setIntensity(0, 8);
/* and clear the display */
lc.clearDisplay(0);
}
Pour afficher un nombre :
void printNumber(int v) {
int ones;
int tens;
int hundreds;
boolean negative;
if (v < -999 || v > 999)
return;
if (v < 0) {
negative = true;
v = v * -1;
}
ones = v % 10;
v = v / 10;
tens = v % 10;
v = v / 10;
hundreds = v;
if (negative) {
//print character '-' in the leftmost column
lc.setChar(0, 3, '-', false);
}
else {
//print a blank in the sign column
lc.setChar(0, 3, ' ', false);
}
//Now print the number digit by digit
lc.setDigit(0, 2, (byte)hundreds, false);
lc.setDigit(0, 1, (byte)tens, false);
lc.setDigit(0, 0, (byte)ones, false);
}
Pour afficher du texte :
On utilise soit la fonction setchar(adresse, position, caractère, point décimal (vrai ou faux)) pour les caractères * ‘A’,’b’,’c’,’d’,’E’,’F’,’H’,’L’,’P’,* ‘.’,’-‘,’_’,’ ‘ pour les autres il faut les définir (cf. plus haut) et les écrire à l’aide de setRow(adresse, position, valeur). r=0x05; u=0x1c; i = B00010000;n=0x15;o=0x1D. Exemple écrire « Arduino. » :
void writeArduinoOn7Segment() {
lc.setChar(0, 7, 'a', false);
lc.setRow(0, 6, 0x05);
lc.setChar(0, 5, 'd', false);
lc.setRow(0, 4, 0x1c);
lc.setRow(0, 3, B00010000);
lc.setRow(0, 2, 0x15);
lc.setRow(0, 1, 0x1D);
lc.setChar(0,0,' ',true);
lc.clearDisplay(0);
}
Références :
http://www.whatimade.today/programming-an-8-digit-7-segment-display-the-easy-way-using-a-max7219/
https://playground.arduino.cc/Main/LedControl
http://embedded-lab.com/blog/?p=6862
For cascading a second MAX7219 device, the DOUT pin of first device should be connected to DIN pin of other, and corresponding CLK and LOAD pins must be tied together. In SPI7SEGDISP8.56, DOUT pin is accessible through JP2 header. JP2 and JP1 header pins are compatible for direct cascading (see the picture below) by plugging them together.
The following Arduino sketch illustrates daisy-chaining three SPI7SEGDISP8.56 modules using the LedControl library.
#include "LedControl.h" // Pin 7 to Data In, 6 to Clk, 5 to LOAD, number of devices is 3 LedControl lc=LedControl(7,6,5,3); void setup() { // Initialize the 3 MAX7219 devices for(int k=0; k<3; k++){ lc.shutdown(k,false); // Enable display lc.setIntensity(k,15); // Set brightness level (0 is min, 15 is max) lc.clearDisplay(k); // Clear display register } } void loop() { int count = 0; for(int j=0; j<3; j++){ for(int i=0; i<8; i++){ lc.setDigit(j,7-i,count, true); // Decimal point enabled count ++; if(count == 16) count=0; } delay(1000); } } |
Votre commentaire