/* MAXIM 7219 Library Carl Hakanson carlhako.gmail.com 21/02/2010 Tested @ 14mhz if your running below 10mhz you can remove the 1ms delays If you change from PBx to PDx for eg do search and replace all DDRB and PORTB with DDRD and PORTD. That and the below definitions should be the only part to change. Segments -------- A F B G E C D */ //send16(dig,(A+F+E+D)); #define DIN PB1 #define CLK PB2 #define LOAD PB3 #define A 64 #define B 32 #define C 16 #define D 8 #define E 4 #define F 2 #define G 1 void max7219_init() { DDRB |= ( (1<< CLK) | (1<< DIN) | (1<< LOAD) ); // set all pins to output send16(0x0C,0x01); // send power on send16(0x09,0x00); // send decode mode send16(0x0B,0x04); // send scan limit send16(0x0A,0x08); // send intensity send16(0x0F,0x00); // send test off send16(0x01,0x08); // send digit 0 - 8 } void send16(unsigned char first_b, unsigned char second_b) //writes the W_Byte to the DS1302 { DDRB |= ( (1<< CLK) | (1<< DIN) | (1<< LOAD) ); PORTB &= ~( (1<< CLK) | (1<< DIN) | (1<< LOAD) ); // set all pins to low unsigned char i; for(i = 0; i < 8; i++) // send first 8 bits { PORTB &= ~(1< 127) { DP = 128; num &= ~(1<<7); } else DP = 0; printf_P(PSTR("after if: %u \r\n"), DP); switch(num) { // switch pins to output based on variable num case 0: send16(dig,(DP+A+B+C+D+E+F)); break; case 1: send16(dig,(DP+B+C)); break; case 2: send16(dig,(DP+A+B+D+E+G)); break; case 3: send16(dig,(DP+A+B+C+D+G)); break; case 4: send16(dig,(DP+B+C+F+G)); break; case 5: send16(dig,(DP+A+C+D+F+G)); break; case 6: send16(dig,(DP+A+C+D+E+F+G)); break; case 7: send16(dig,(DP+A+B+C)); break; case 8: send16(dig,(DP+A+B+C+D+E+F+G)); break; case 9: send16(dig,(DP+A+B+C+D+F+G)); break; case 11: // A send16(dig,(A+F+G+E+D)); break; case 13: send16(dig,(A+F+E+D)); break; case 15: // E send16(dig,(A+F+G+E+D)); break; case 29: // S send16(dig,(A+F+G+C+D)); break; case 30: // T send16(dig,(A+F+E)); break; case 37: send16(dig,(A+F+G+B)); break; case 100: send16(dig,0); break; default: // if invalid number is passed to function E is displayed. send16(dig,(A+F+G+E+D)); break; } }