I have a common anode bi-color led matrix with 24 pins and want to drive two of these using one microcontroller . So I decided to try Max7219 driver for that. But being a novice I'm having a hard time figuring out what to do and the online resources seem to be centered around arduino. I did find a library developed by Davide Gironi. But it seems to be working with a common cathode matrix. So I changed the rows to columns to adapt with the common anode structure but with no luck. Can you please give me some clues to where to look for the solution?
I'd try to light up a single led first, then a row and column without the library. Once you have a good understanding how it works you can either write a library yourself or adapt the low level driver firmware in the library you're using. Once you've got working code, you can debug the library until it works.
Here's some pseudo code. I'm not very familiar with the exact functions of Atmega 16 but I'm sure you're able to to replace the delay and port configuration with the proper code.
#define CLOCK PORT1.0 // Replace PORT1.x with proper port
#define DIN PORT1.1
#define LOAD PORT1.2
#define nCS PORT1.3
void SetupIO()
{
//Set clock as an output
//Set DIN as an output
//Set LOAD as an output
//Set nCS as an output
}
void DoClock()
{
CLOCK = 1;
delay_us(1);
CLOCK = 0;
delay_us(1);
}
void WriteBits(char address, char data)
{
char i;
// Set LOAD and nCS low
LOAD = 0;
nCS = 0;
delay_us(1); // replace all delay functions/macros with proper delay macro
// write address
for( i = 7; i > 0 ; i--)
{
DIN = (address >> i) & 1; // shift data to the proper bit
delay_us(1); // allow signal to settle
DoClock(); // clock the bit into the MAX7219
}
// write data
for( i = 7; i > 0 ; i--)
{
DIN = (data >> i) & 1; // shift data to the proper bit
delay_us(1);
DoClock(); // clock the bit into the MAX7219
}
// Latch the address/data
LOAD = 1;
nCS = 1;
delay_us(1);
LOAD = 0;
nCS = 0;
delay_us(1);
}
void main()
{
SetupPins();
// initialize display
WriteBits(0x0C, 0x01); // Normal operation
WriteBits(0x09, 0x00); // BCD decoder off
WriteBits(0x0A, 0xFF); // Max intensity
WriteBits(0x0B, 0x07); // Scan all digits
//Test display 8, all digits on
WriteBits(0x00, 0xff);
}