I have a concern about the library port handling. I have used direct port direction manipulation successfully in previous projects but there seems to be a problem here.
// This code mostly taken from the example
#include "LedControl.h"
LedControl lc=LedControl(11,13,10,1);
//LedControl lc=LedControl(12,11,10,1); // original
// pin 12 is connected to the DIN pin (now MOSI 11)
// pin 11 is connected to the CLK pin (now SCK 13)
// pin 10 is connected to the CS pin (now SS 10)
// 1 as we are only using 1 MAX7219
// I am actually using all arduino pins except 12 for my project
#define PD_MSK B11111100 // Data pins PD2..7 (pins2..7)
#define PB_MSK B00000011 // Data pins PB0,1 (pins8,9)
#define PC_MSK B00001111 // Data pins PC0..3 (pins 14..17)
void setup()
{
// set pins 2..9 as inputs
DDRD = DDRD & !PD_MSK; // this works OK
DDRB = DDRB & !PB_MSK; // configure ports D,B inputs *** doesnt work with this
// pinMode(8, INPUT); //*** does work with this
//pinMode(9, INPUT); //*** does work with this
DDRC = DDRC | PC_MSK; // configure PortC0..3 as outputs
PORTC |= 0x0F; // set PortC0..3 high (default)
// the zero refers to the MAX7219 number, it is zero for 1 chip
lc.shutdown(0,false);// turn off power saving, enables display
lc.setIntensity(0,8);// sets brightness (0~15 possible values)
lc.clearDisplay(0);// clear screen
}
void loop()
{
//numbers 7 to 0
for (int a=0; a<8; a++)
{
lc.setDigit(0,a,a,false);
}
delay(1000);
//display number 8 on all segments
for (int a=0; a<8; a++)
{
lc.setDigit(0,a,8,false);
}
delay(1000);
// numbers 7 to 0 reverse order
for (int a=8; a>=0; a--)
{
lc.setDigit(0,a,a,false);
//delay(100);
}
delay(1000);
}
The direct port direction setting does not seem to allow the library to work while the pinMode commands doing the same job do. I note that the library uses software SPI but I would like to use hardware if possible. I have certainly used hardware SPI with frequent port direction changes on the remaining pins for other projects. Any insight as to why this problem occurs?
Thanks.
&=