The following circuit and the associated SPI-based codes have appeared as working. The program codes given below add two 8-bit binary numbers (0x12 ans 0x13) (in the setup() function) and show the result on DP0-DP1 positions of the display. Anyway, it works for any combinations of numbers. However, something is there, which has gone against the very feature of the MAX7219 Controller.
When the initialization codes (also the result transfer codes) are moved from the loop() function into the the setup() function, the circuit/code is not working (no display!). But, the MAX7219, according to data sheets, contains 8x8 RAM for the digits' data and also the scanning circuitry. Therefore, there is no need for continuous delivery of data into the controller; the user will just update new data as they arrive. The refreshing will be taken care of by the controller.
#include<SPI.h>
byte registerAddress[] = {0x0C, 0x09, 0x0A, 0x0B};
byte registerData[] = {0x01, 0x00, 0x01, 0x07};
//normal mdeo; no-decode;intensity;8-digit scan
byte dataArray[50]; //to hold cc-codes (no-decode format)
byte digitAddress[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};//DP)-DP7
byte lupTable[] = {0x7E, 0x30, 0x6D, 0x79, 0x33, 0x5B, 0x5F, 0x70,
0x7F, 0x7B, 0x77, 0x1F, 0x4E, 0x3D, 0x4F, 0x47}; //0, 1, ...., E, F
void setup()
{
pinMode(10, OUTPUT); //LOAD Pin of MAX7219
//-------------------
SPI.begin();
bitSet(SPCR, 4); //UNO is Master SPI
SPI.setBitOrder(MSBFIRST); //MSB_bit will be transferred first
SPI.setClockDivider(SPI_CLOCK_DIV128); //TX rate = 16MHz/128 = 125 kbit
SPI.setDataMode(SPI_MODE0);//MOSI is sampled at the rising edge of CLK
//------------------------------------------------
digitalWrite(10, LOW); //Low at LOAD pin
//---- computation----------------------------------
byte z = 0x12 + 0x13; //[s]z = 3C[/s] z = 25
dataArray[0] = lupTable[z>>4];
dataArray[1] = lupTable[z&0x0F];
//-------------------------------------------------
}
void loop()
{
//---keep intializing the Mode of Operation------------
for(int i=0; i<4; i++)
{
SPI.transfer(registerAddress[i]);
SPI.transfer(registerData[i]);
digitalWrite(10, HIGH); //assert LH/LL on LOAD pin
digitalWrite(10, LOW);
}
//--keep transferring the result/data----------------------
for(int i=0; i<2; i++)
{
SPI.transfer(digitAddress[i]); //DPX position
SPI.transfer(dataArray[i]); //shows 2 on DP0-position
digitalWrite(10, HIGH); //assert LH/LL on LOAD pin
digitalWrite(10, LOW);
}
}