// Implemenatation of max7219.h // // www.while1.eu 30/07/2023 #include "max7219a.h" // This array stores the 7 segment patterns to show all the ASCII characters in a // 8 digits 7 segment display driven by a MAX7219. // Sometimes uppercase letters have the same pattern of the lowercase. // Segments and bit connections ==> MSB HABCDEFG LSB (see MAX7219 datasheet). // Control characters return a zero (all LEDs off). __code uChar getSegments[0x80] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x00 Control characters return 0 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x08 Control characters return 0 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x10 Control characters return 0 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x18 Control characters return 0 0x00, 0xB0, 0x22, 0x00, 0x00, 0x00, 0x00, 0x02, // 0x20 !"#$%&' ok but # $ % & missing OK 0x4E, 0x78, 0x00, 0x00, 0x80, 0x01, 0x80, 0x25, // 0x28 ()*+,-./ ok but * + missing OK 0x7E, 0x30, 0x6D, 0x79, 0x33, 0x5B, 0x5F, 0x70, // 0x30 01234567 ok OK 0x7F, 0x7B, 0xA0, 0xA0, 0x0D, 0x09, 0x19, 0xE5, // 0x38 89:;<=>? ok OK 0x6F, 0x77, 0x1F, 0x4E, 0x3D, 0x4F, 0x47, 0x5E, // 0x40 @ABCDEFG ok OK 0x37, 0x30, 0x3C, 0xA7, 0x0E, 0x76, 0x15, 0x7E, // 0x48 HIJKLMNO ok OK 0x67, 0xFE, 0x05, 0x5B, 0x0F, 0x3E, 0x1C, 0x9C, // 0x50 PQRSTUVW ok OK 0x37, 0x3B, 0x6D, 0x4E, 0x13, 0x78, 0x62, 0x08, // 0x58 XYZ[\]^_ ok OK 0x20, 0x7D, 0x5F, 0x0D, 0x3D, 0x6F, 0x47, 0x7B, // 0x60 `abcdefg ok OK 0x17, 0x10, 0x18, 0xA7, 0x0C, 0x15, 0x15, 0x1D, // 0x68 hijklmno ok OK 0x67, 0x9D, 0x05, 0x5B, 0x0F, 0x1C, 0x1C, 0x9C, // 0x70 pqrstuvw ok OK 0x37, 0x3B, 0xED, 0x4E, 0x30, 0x78, 0x01, 0x00 // 0x78 xyz{|}~ ok OK last one is a DEL }; // Sends data or command to max7219 void writeWord(uChar command, uChar bdata){ CS = 0; CLOCK = 0; uChar counter = 8; while(counter--){ DATA = command & 0x80; CLOCK = 1; CLOCK = 0; command = command << 1;} counter = 8; while(counter--){ DATA = bdata & 0x80; CLOCK = 1; CLOCK = 0; bdata = bdata << 1;} CS = 1; } //writeWord end // Initialize max7219 void initMax7219(){ writeWord(0x0C,0x00); //Shutdown writeWord(0x09,0x00); //No one decoded writeWord(0x0B,0x07); //All digits addressable writeWord(0x0C,0x01);} //Normal operation // Clear each digit void clearMax7219(){ initMax7219(); for (uChar a = 0; a < 9; a++) {writeWord(a,0);} } // Set the level of LED brightness (Value from 0 to 15) void setBrightnessMax7219(uChar brightness) { writeWord(0xFA,brightness);} // Kind of printf limited to 8 chars void printString(char *c){ for (char i = 8; i > 0; i--) { writeWord(i,getSegments[c[8-i]]);} return;}