Files
Examples/C++/Arduino/MAX7219/MAX7219.ino
2018-05-13 16:27:04 +01:00

90 lines
3.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
int MAXPINCLK = 10; // Define Digital Port 10
int MAXPINCS = 9; // Define Digital Port 9
int MAXPINDIN = 8; // Define Digital Port 8
unsigned char x; //occupies bytes on the memory
unsigned char y; //occupies bytes on the memory
unsigned char disp1[38][8]={
{0x3C,0x42,0x42,0x42,0x42,0x42,0x42,0x3C}, //Char 0
{0x10,0x18,0x14,0x10,0x10,0x10,0x10,0x10}, //Char 1
{0x7E,0x2,0x2,0x7E,0x40,0x40,0x40,0x7E}, //Char 2
{0x3E,0x2,0x2,0x3E,0x2,0x2,0x3E,0x0}, //Char 3
{0x8,0x18,0x28,0x48,0xFE,0x8,0x8,0x8}, //Char 4
{0x3C,0x20,0x20,0x3C,0x4,0x4,0x3C,0x0}, //Char 5
{0x3C,0x20,0x20,0x3C,0x24,0x24,0x3C,0x0}, //Char 6
{0x3E,0x22,0x4,0x8,0x8,0x8,0x8,0x8}, //Char 7
{0x0,0x3E,0x22,0x22,0x3E,0x22,0x22,0x3E}, //Char 8
{0x3E,0x22,0x22,0x3E,0x2,0x2,0x2,0x3E}, //Char 9
{0x8,0x14,0x22,0x3E,0x22,0x22,0x22,0x22}, //Char A
{0x3C,0x22,0x22,0x3E,0x22,0x22,0x3C,0x0}, //Char B
{0x3C,0x40,0x40,0x40,0x40,0x40,0x3C,0x0}, //Char C
{0x7C,0x42,0x42,0x42,0x42,0x42,0x7C,0x0}, //Char D
{0x7C,0x40,0x40,0x7C,0x40,0x40,0x40,0x7C}, //Char E
{0x7C,0x40,0x40,0x7C,0x40,0x40,0x40,0x40}, //Char F
{0x3C,0x40,0x40,0x40,0x40,0x44,0x44,0x3C}, //Char G
{0x44,0x44,0x44,0x7C,0x44,0x44,0x44,0x44}, //Char H
{0x7C,0x10,0x10,0x10,0x10,0x10,0x10,0x7C}, //Char I
{0x3C,0x8,0x8,0x8,0x8,0x8,0x48,0x30}, //Char J
{0x0,0x24,0x28,0x30,0x20,0x30,0x28,0x24}, //Char K
{0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x7C}, //Char L
{0x81,0xC3,0xA5,0x99,0x81,0x81,0x81,0x81}, //Char M
{0x0,0x42,0x62,0x52,0x4A,0x46,0x42,0x0}, //Char N
{0x3C,0x42,0x42,0x42,0x42,0x42,0x42,0x3C}, //Char O
{0x3C,0x22,0x22,0x22,0x3C,0x20,0x20,0x20}, //Char P
{0x1C,0x22,0x22,0x22,0x22,0x26,0x22,0x1D}, //Char Q
{0x3C,0x22,0x22,0x22,0x3C,0x24,0x22,0x21}, //Char R
{0x0,0x1E,0x20,0x20,0x3E,0x2,0x2,0x3C}, //Char S
{0x0,0x3E,0x8,0x8,0x8,0x8,0x8,0x8}, //Char T
{0x42,0x42,0x42,0x42,0x42,0x42,0x22,0x1C}, //Char U
{0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18}, //Char V
{0x0,0x49,0x49,0x49,0x49,0x2A,0x1C,0x0}, //Char W
{0x0,0x41,0x22,0x14,0x8,0x14,0x22,0x41}, //Char X
{0x41,0x22,0x14,0x8,0x8,0x8,0x8,0x8}, //Char Y
{0x0,0x7F,0x2,0x4,0x8,0x10,0x20,0x7F}, //Char Z
};
void MX7219_WRITE_byte(unsigned char DATA) {
unsigned char x;
digitalWrite(MAXPINCS,LOW);
for(x=8;x>=1;x--)
{
digitalWrite(MAXPINCLK,LOW);
digitalWrite(MAXPINDIN,DATA&0x80);// Extracting a bit data
DATA = DATA<<1;
digitalWrite(MAXPINCLK,HIGH);
}
}
void MX7219_WRITE(unsigned char address,unsigned char dat) {
digitalWrite(MAXPINCS,LOW);
MX7219_WRITE_byte(address); // The address code of the LED
MX7219_WRITE_byte(dat); //The data figure on LED
digitalWrite(MAXPINCS,HIGH);
}
void InitMAX7219(void) {
MX7219_WRITE(0x09, 0x00); //Set decoding BCD
MX7219_WRITE(0x0a, 0x03); //Set the brightness
MX7219_WRITE(0x0b, 0x07); //Set scan & limit 8 LEDs
MX7219_WRITE(0x0c, 0x01); //On power-down mode is 0normal mode is 1
MX7219_WRITE(0x0f, 0x00); //To test display 1 EOTdisplay 0
}
void setup() {
pinMode(MAXPINCLK,OUTPUT);
pinMode(MAXPINCS,OUTPUT);
pinMode(MAXPINDIN,OUTPUT);
delay(50);
InitMAX7219();
}
void loop() {
for(y=0;y<38;y++) {
for(x=1;x<9;x++)
MX7219_WRITE(x,disp1[y][x-1]);
delay(500);
}
}