2013-12-02

SPI refunctioning / refactoring notes


// ***********************************************************************
// test050.h 2013dec02hkt1046
// ***********************************************************************

#include "led050.h"
#include "key050.h"
#include "adc050.h"
#include "eeprom050.h"
#include "spi080.h"
#include "mled080.h"

#define DEBUG 1
#define NO_DEBUG 0

void testMax7219DisplayEightDigitV09a()
{
printf("\n*** testMax7219DisplayEightDigitV09a() ***\n\n");

// *** Set up SPI channels SPI0, SPI1 ***
printf("\n*** Set up SPI channels ***\n\n");
setupOneSpiChannel080(SPI_CHANNEL_0);
setupOneSpiChannel080(SPI_CHANNEL_1);

// *** Set up all slave select ports of SPI0, SPI1 ***
printf("\n*** Set up Slave select ports ***\n\n");
setupAllSlaveSelectPortV090(WuyinsSpi1SselPortPinArrayPointerArrayArrayV094[SPI_CHANNEL_0]);
setupAllSlaveSelectPortV090(WuyinsSpi1SselPortPinArrayPointerArrayArrayV094[SPI_CHANNEL_1]);

// *** Set up all Max7219s ***
printf("\n*** Set up all MAx7219s ***\n\n");

printf("\n*** Set up all MAx7219 at SPI 0,0 ***\n\n");
setupMax7219DigitModeV0909(SPI_CHANNEL_0, SLAVE_SELECT_0);

printf("\n*** Set up all MAx7219 at SPI 0,1 ***\n\n");
setupMax7219DigitModeV0909(SPI_CHANNEL_0, SLAVE_SELECT_1);

printf("\n*** Set up all MAx7219 at SPI 0,2 ***\n\n");
setupMax7219DigitModeV0909(SPI_CHANNEL_0, SLAVE_SELECT_2);

// *** loop display 8 digits of each 8 MAX7219s ***
printf("\n*** Loop displaying 8 digits ***\n\n");
       // while (1)
       {
           setupMax7219DigitModeV0909(SPI_CHANNEL_0, SLAVE_SELECT_0);
      Max7219DisplayEightDigitV0909(SPI_CHANNEL_0, SLAVE_SELECT_0, 5, 14, 1, 15, 0, 0, 15, 1, NO_DEBUG);

           setupMax7219DigitModeV0909(SPI_CHANNEL_0, SLAVE_SELECT_1);
      Max7219DisplayEightDigitV0909(SPI_CHANNEL_0, SLAVE_SELECT_1, 5, 14, 1, 15, 0, 0, 15, 1, NO_DEBUG);

           setupMax7219DigitModeV0909(SPI_CHANNEL_0, SLAVE_SELECT_2);
      Max7219DisplayEightDigitV0909(SPI_CHANNEL_0, SLAVE_SELECT_2, 5, 14, 1, 15, 0, 0, 15, 1, NO_DEBUG);

      //Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_1, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
    //                                            5, 14, 1, 15, 0, 1, 15, 1, NO_DEBUG);
      //Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_2, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
    //                                            5, 14, 1, 15, 0, 2, 15, 1, NO_DEBUG);

      Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_3, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 0, 3, 15, 1, NO_DEBUG);

      Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_0, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 1, 0, 15, 1, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_4, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                           5, 14, 1, 15, 1, 4, 15, 1, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_5, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 1, 5, 15, 1, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_6, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 1, 6, 15, 1, NO_DEBUG);
       }
}

void testMax7219DisplayEightDigitV099()
{
printf("\n*** testMax7219DisplayEightDigitV099() ***\n\n");

// *** Set up SPI channels SPI0, SPI1 ***
printf("\n*** Set up SPI channels ***\n\n");
setupOneSpiChannel080(SPI_CHANNEL_0);
setupOneSpiChannel080(SPI_CHANNEL_1);

// *** Set up all slave select ports of SPI0, SPI1 ***
printf("\n*** Set up Slave select ports ***\n\n");
setupAllSlaveSelectPortV090(WuyinsSpi1SselPortPinArrayPointerArrayArrayV094[SPI_CHANNEL_0]);
setupAllSlaveSelectPortV090(WuyinsSpi1SselPortPinArrayPointerArrayArrayV094[SPI_CHANNEL_1]);

// *** Set up all MAX7218 digit mode ***

/*
printf("\n*** Set up all MAX7219 digit mode ***\n\n");
setupMax7219DigitModeV0909(SPI_CHANNEL_0, SLAVE_SELECT_0);
setupMax7219DigitModeV0909(SPI_CHANNEL_0, SLAVE_SELECT_1);
setupMax7219DigitModeV0909(SPI_CHANNEL_0, SLAVE_SELECT_2);
setupMax7219DigitModeV0909(SPI_CHANNEL_0, SLAVE_SELECT_3);
setupMax7219DigitModeV0909(SPI_CHANNEL_1, SLAVE_SELECT_0);
setupMax7219DigitModeV0909(SPI_CHANNEL_1, SLAVE_SELECT_4);
setupMax7219DigitModeV0909(SPI_CHANNEL_1, SLAVE_SELECT_5);
setupMax7219DigitModeV0909(SPI_CHANNEL_1, SLAVE_SELECT_6);
*/

// *** loop display 8 digits of each 8 MAX7219s, connected to SPI x,y ***
printf("\n*** Loop displaying 8 digits ***\n\n");
       while (1)
       {
           setupMax7219DigitModeV0909(SPI_CHANNEL_0, SLAVE_SELECT_0);
      Max7219DisplayEightDigitV0909(SPI_CHANNEL_0, SLAVE_SELECT_0, 5, 14, 1, 15, 15, 15, 0, 0, NO_DEBUG);

           // setupMax7219DigitModeV0909(SPI_CHANNEL_0, SLAVE_SELECT_1);
      // Max7219DisplayEightDigitV0909(SPI_CHANNEL_0, SLAVE_SELECT_1, 5, 14, 1, 15, 15, 15, 0, 1, NO_DEBUG);

      /*
          Max7219DisplayEightDigitV0909(SPI_CHANNEL_0, SLAVE_SELECT_1, 5, 14, 1, 15, 15, 15, 0, 1, NO_DEBUG);
          Max7219DisplayEightDigitV0909(SPI_CHANNEL_0, SLAVE_SELECT_2, 5, 14, 1, 15, 15, 15, 0, 2, NO_DEBUG);
          Max7219DisplayEightDigitV0909(SPI_CHANNEL_0, SLAVE_SELECT_3, 5, 14, 1, 15, 15, 15, 0, 3, NO_DEBUG);

          Max7219DisplayEightDigitV0909(SPI_CHANNEL_1, SLAVE_SELECT_0, 5, 14, 1, 15, 15, 15, 1, 0, NO_DEBUG);
          Max7219DisplayEightDigitV0909(SPI_CHANNEL_1, SLAVE_SELECT_4, 5, 14, 1, 15, 15, 15, 1, 4, NO_DEBUG);
          Max7219DisplayEightDigitV0909(SPI_CHANNEL_1, SLAVE_SELECT_5, 5, 14, 1, 15, 15, 15, 1, 5, NO_DEBUG);
          Max7219DisplayEightDigitV0909(SPI_CHANNEL_1, SLAVE_SELECT_6, 5, 14, 1, 15, 15, 15, 1, 6, NO_DEBUG);
          */

      Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_1, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 0, 1, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_2, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 0, 2, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_3, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 0, 3, NO_DEBUG);

      /*
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_4, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 0, 4, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_5, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 0, 4, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_6, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 0, 6, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_7, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 0, 7, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_8, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
                                                           5, 14, 1, 15, 15, 15, 0, 7, NO_DEBUG);
           */

      Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_0, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 1, 0, NO_DEBUG);
           /*
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_1, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 1, 1, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_2, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 1, 2, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_3, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 1, 3, NO_DEBUG);
           */
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_4, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                           5, 14, 1, 15, 15, 15, 1, 4, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_5, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 1, 5, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_6, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 1, 6, NO_DEBUG);
      /*
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_7, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 1, 7, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_8, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 1, 8, NO_DEBUG);
           */
       }
}


void testMax7219DisplayEightDigitV098()
{
// printf("\n*** testMax7219DisplayEightDigitV098() ***\n\n");

// *** Set up SPI channels SPI0, SPI1 ***
// printf("\n*** Set up SPI channels SPI0, SPI1 ***\n\n");
setupOneSpiChannel080(SPI_CHANNEL_0);
setupOneSpiChannel080(SPI_CHANNEL_1);

// *** Set up all slave select ports of SPI0, SPI1 ***
// printf("\n*** Set up all slave select ports of SPI0 and SPI1 ***\n\n");
setupAllSlaveSelectPortV090(WuyinsSpi1SselPortPinArrayPointerArrayArrayV094[SPI_CHANNEL_0]);
setupAllSlaveSelectPortV090(WuyinsSpi1SselPortPinArrayPointerArrayArrayV094[SPI_CHANNEL_1]);

// *** loop display 8 digits of each 8 MAX7219s ***
// printf("\n*** Loop displaying 8 digits of each of 8 Max7219s ***\n\n");

       while (1)
       {
          Max7219DisplayEightDigitV0905(SPI_CHANNEL_0, SLAVE_SELECT_0, 5, 14, 1, 15, 0, 0, 15, 0, NO_DEBUG);
      Max7219DisplayEightDigitV0905(SPI_CHANNEL_0, SLAVE_SELECT_1, 5, 14, 1, 15, 0, 1, 15, 0, NO_DEBUG);
      Max7219DisplayEightDigitV0905(SPI_CHANNEL_0, SLAVE_SELECT_2, 5, 14, 1, 15, 0, 2, 15, 0, NO_DEBUG);
      Max7219DisplayEightDigitV0905(SPI_CHANNEL_0, SLAVE_SELECT_3, 5, 14, 1, 15, 0, 3, 15, 0, NO_DEBUG);

      Max7219DisplayEightDigitV0905(SPI_CHANNEL_1, SLAVE_SELECT_0, 5, 14, 1, 15, 0, 0, 15, 0, NO_DEBUG);
      Max7219DisplayEightDigitV0905(SPI_CHANNEL_1, SLAVE_SELECT_4, 5, 14, 1, 15, 0, 4, 15, 0, NO_DEBUG);
      Max7219DisplayEightDigitV0905(SPI_CHANNEL_1, SLAVE_SELECT_5, 5, 14, 1, 15, 0, 5, 15, 0, NO_DEBUG);
      Max7219DisplayEightDigitV0905(SPI_CHANNEL_1, SLAVE_SELECT_6, 5, 14, 1, 15, 0, 6, 15, 0, NO_DEBUG);
       }
}


void testMax7219DisplayEightDigitV097()
{
// *** Set up SPI channels SPI0, SPI1 ***
setupOneSpiChannel080(SPI_CHANNEL_0);
setupOneSpiChannel080(SPI_CHANNEL_1);

// *** Set up all slave select ports of SPI0, SPI1 ***
setupAllSlaveSelectPortV090(WuyinsSpi1SselPortPinArrayPointerArrayArrayV094[SPI_CHANNEL_0]);
setupAllSlaveSelectPortV090(WuyinsSpi1SselPortPinArrayPointerArrayArrayV094[SPI_CHANNEL_1]);

// *** Set up digit mode for 8 MAX7219s ***
setupMax7219DigitModeV0901(SPI_CHANNEL_0, SLAVE_SELECT_0, \
                  WuyinsSpi1SselPortPinArrayPointerArrayArrayV094[SPI_CHANNEL_0]);
setupMax7219DigitModeV0901(SPI_CHANNEL_0, SLAVE_SELECT_1, \
                  WuyinsSpi1SselPortPinArrayPointerArrayArrayV094[SPI_CHANNEL_0]);
setupMax7219DigitModeV0901(SPI_CHANNEL_0, SLAVE_SELECT_2, \
                  WuyinsSpi1SselPortPinArrayPointerArrayArrayV094[SPI_CHANNEL_0]);
setupMax7219DigitModeV0901(SPI_CHANNEL_0, SLAVE_SELECT_3, \
                  WuyinsSpi1SselPortPinArrayPointerArrayArrayV094[SPI_CHANNEL_0]);
setupMax7219DigitModeV0901(SPI_CHANNEL_1, SLAVE_SELECT_0, \
                  WuyinsSpi1SselPortPinArrayPointerArrayArrayV094[SPI_CHANNEL_1]);
setupMax7219DigitModeV0901(SPI_CHANNEL_1, SLAVE_SELECT_4, \
                  WuyinsSpi1SselPortPinArrayPointerArrayArrayV094[SPI_CHANNEL_1]);
setupMax7219DigitModeV0901(SPI_CHANNEL_1, SLAVE_SELECT_5, \
                  WuyinsSpi1SselPortPinArrayPointerArrayArrayV094[SPI_CHANNEL_1]);
setupMax7219DigitModeV0901(SPI_CHANNEL_1, SLAVE_SELECT_6, \
                  WuyinsSpi1SselPortPinArrayPointerArrayArrayV094[SPI_CHANNEL_1]);

// *** Display 8 digits for each of 8 MAx7219 ***
       while (1)
       {
      Max7219DisplayEightDigitV0906(SPI_CHANNEL_0, SLAVE_SELECT_0, 5, 14, 1, 15, 4, 15, 0, 0, NO_DEBUG);
      Max7219DisplayEightDigitV0906(SPI_CHANNEL_0, SLAVE_SELECT_1, 5, 14, 1, 15, 4, 15, 0, 1, NO_DEBUG);
      Max7219DisplayEightDigitV0906(SPI_CHANNEL_0, SLAVE_SELECT_2, 5, 14, 1, 15, 4, 15, 0, 2, NO_DEBUG);
      Max7219DisplayEightDigitV0906(SPI_CHANNEL_0, SLAVE_SELECT_3, 5, 14, 1, 15, 4, 15, 0, 3, NO_DEBUG);

      Max7219DisplayEightDigitV0906(SPI_CHANNEL_1, SLAVE_SELECT_0, 5, 14, 1, 15, 4, 15, 1, 0, NO_DEBUG);
      Max7219DisplayEightDigitV0906(SPI_CHANNEL_1, SLAVE_SELECT_4, 5, 14, 1, 15, 4, 15, 1, 4, NO_DEBUG);
      Max7219DisplayEightDigitV0906(SPI_CHANNEL_1, SLAVE_SELECT_5, 5, 14, 1, 15, 4, 15, 1, 5, NO_DEBUG);
      Max7219DisplayEightDigitV0906(SPI_CHANNEL_1, SLAVE_SELECT_6, 5, 14, 1, 15, 4, 15, 1, 6, NO_DEBUG);


      Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_0, \
                            WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                         5, 14, 1, 15, 6, 15, 0, 0, NO_DEBUG);

      Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_1, \
                            WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                         5, 14, 1, 15, 6, 15, 0, 1, NO_DEBUG);

      Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_0, \
                            WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                         5, 14, 1, 15, 6, 15, 1, 0, NO_DEBUG);
       }
}


void testMax7219DisplayEightDigitV096()
{
// *** Set up SPI channels SPI0, SPI1 ***
setupOneSpiChannel080(SPI_CHANNEL_0);
setupOneSpiChannel080(SPI_CHANNEL_1);

// *** Set up all slave select ports of SPI0, SPI1 ***
setupAllSlaveSelectPortV090(WuyinsSpi1SselPortPinArrayPointerArrayArrayV094[SPI_CHANNEL_0]);
setupAllSlaveSelectPortV090(WuyinsSpi1SselPortPinArrayPointerArrayArrayV094[SPI_CHANNEL_1]);

// *** Display 8 digits for each of 8 MAx7219 ***
       while (1)
       {
      Max7219DisplayEightDigitV0905(SPI_CHANNEL_0, SLAVE_SELECT_0, 5, 14, 1, 15, 5, 15, 0, 0, NO_DEBUG);
      Max7219DisplayEightDigitV0905(SPI_CHANNEL_0, SLAVE_SELECT_1, 5, 14, 1, 15, 5, 15, 0, 1, NO_DEBUG);
      Max7219DisplayEightDigitV0905(SPI_CHANNEL_0, SLAVE_SELECT_2, 5, 14, 1, 15, 5, 15, 0, 2, NO_DEBUG);
      Max7219DisplayEightDigitV0905(SPI_CHANNEL_0, SLAVE_SELECT_3, 5, 14, 1, 15, 5, 15, 0, 3, NO_DEBUG);

      Max7219DisplayEightDigitV0905(SPI_CHANNEL_1, SLAVE_SELECT_0, 5, 14, 1, 15, 5, 15, 1, 0, NO_DEBUG);
      Max7219DisplayEightDigitV0905(SPI_CHANNEL_1, SLAVE_SELECT_4, 5, 14, 1, 15, 5, 15, 1, 4, NO_DEBUG);
      Max7219DisplayEightDigitV0905(SPI_CHANNEL_1, SLAVE_SELECT_5, 5, 14, 1, 15, 5, 15, 1, 5, NO_DEBUG);
      Max7219DisplayEightDigitV0905(SPI_CHANNEL_1, SLAVE_SELECT_6, 5, 14, 1, 15, 5, 15, 1, 6, NO_DEBUG);

      Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_0, \
                            WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                         5, 14, 1, 15, 6, 15, 0, 0, NO_DEBUG);

      Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_1, \
                            WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                         5, 14, 1, 15, 6, 15, 0, 1, NO_DEBUG);

      Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_0, \
                            WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                         5, 14, 1, 15, 6, 15, 1, 0, NO_DEBUG);

       }
}


void testMax7219DisplayEightDigitV095()
{
// *** Set up SPI channels SPI0, SPI1 ***
setupOneSpiChannel080(SPI_CHANNEL_0);
setupOneSpiChannel080(SPI_CHANNEL_1);

    // v094
// *** Set up all slave select ports of SPI0, SPI1 ***
// printf("\n*** Set up Slave select ports ***\n\n");
setupAllSlaveSelectPortV090(WuyinsSpi1SselPortPinArrayPointerArrayArrayV094[SPI_CHANNEL_0]);
setupAllSlaveSelectPortV090(WuyinsSpi1SselPortPinArrayPointerArrayArrayV094[SPI_CHANNEL_1]);

// *** loop display 8 digits of each 8 MAX7219s, connected to SPI x,y ***
       while (1)
       {
      Max7219DisplayEightDigitV0905(SPI_CHANNEL_0, SLAVE_SELECT_0, 5, 14, 1, 15, 7, 15, 0, 0, NO_DEBUG);
      Max7219DisplayEightDigitV0905(SPI_CHANNEL_0, SLAVE_SELECT_1, 5, 14, 1, 15, 7, 15, 0, 1, NO_DEBUG);
      Max7219DisplayEightDigitV0905(SPI_CHANNEL_0, SLAVE_SELECT_2, 5, 14, 1, 15, 7, 15, 0, 2, NO_DEBUG);
      Max7219DisplayEightDigitV0905(SPI_CHANNEL_0, SLAVE_SELECT_3, 5, 14, 1, 15, 7, 15, 0, 3, NO_DEBUG);
      //Max7219DisplayEightDigitV0905(SPI_CHANNEL_0, SLAVE_SELECT_4, 5, 14, 1, 15, 7, 15, 0, 4, NO_DEBUG);
      //Max7219DisplayEightDigitV0905(SPI_CHANNEL_0, SLAVE_SELECT_5, 5, 14, 1, 15, 7, 15, 0, 5, NO_DEBUG);
      //Max7219DisplayEightDigitV0905(SPI_CHANNEL_0, SLAVE_SELECT_6, 5, 14, 1, 15, 7, 15, 0, 6, NO_DEBUG);
      //Max7219DisplayEightDigitV0905(SPI_CHANNEL_0, SLAVE_SELECT_7, 5, 14, 1, 15, 7, 15, 0, 7, NO_DEBUG);
      //Max7219DisplayEightDigitV0905(SPI_CHANNEL_0, SLAVE_SELECT_8, 5, 14, 1, 15, 7, 15, 0, 8, NO_DEBUG);

      Max7219DisplayEightDigitV0905(SPI_CHANNEL_1, SLAVE_SELECT_0, 5, 14, 1, 15, 7, 15, 1, 0, NO_DEBUG);
      //Max7219DisplayEightDigitV0905(SPI_CHANNEL_1, SLAVE_SELECT_1, 5, 14, 1, 15, 7, 15, 1, 1, NO_DEBUG);
      //Max7219DisplayEightDigitV0905(SPI_CHANNEL_1, SLAVE_SELECT_2, 5, 14, 1, 15, 7, 15, 1, 2, NO_DEBUG);
      //Max7219DisplayEightDigitV0905(SPI_CHANNEL_1, SLAVE_SELECT_3, 5, 14, 1, 15, 7, 15, 1, 3, NO_DEBUG);
      Max7219DisplayEightDigitV0905(SPI_CHANNEL_1, SLAVE_SELECT_4, 5, 14, 1, 15, 7, 15, 1, 4, NO_DEBUG);
      Max7219DisplayEightDigitV0905(SPI_CHANNEL_1, SLAVE_SELECT_5, 5, 14, 1, 15, 7, 15, 1, 5, NO_DEBUG);
      Max7219DisplayEightDigitV0905(SPI_CHANNEL_1, SLAVE_SELECT_6, 5, 14, 1, 15, 7, 15, 1, 6, NO_DEBUG);
      //Max7219DisplayEightDigitV0905(SPI_CHANNEL_1, SLAVE_SELECT_7, 5, 14, 1, 15, 7, 15, 1, 7, NO_DEBUG);
      //Max7219DisplayEightDigitV0905(SPI_CHANNEL_1, SLAVE_SELECT_8, 5, 14, 1, 15, 7, 15, 1, 8, NO_DEBUG);
       }
}

void testMax7219DisplayEightDigitV094()
{
// *** Set up SPI channels SPI0, SPI1 ***
// printf("\n*** Set up SPI channels ***\n\n");
setupOneSpiChannel080(SPI_CHANNEL_0);
setupOneSpiChannel080(SPI_CHANNEL_1);

// *** Set up all slave select ports of SPI0, SPI1 ***
// printf("\n*** Set up Slave select ports ***\n\n");
setupAllSlaveSelectPortV090(WuyinsSpi1SselPortPinArrayPointerArrayArrayV094[SPI_CHANNEL_0]);
setupAllSlaveSelectPortV090(WuyinsSpi1SselPortPinArrayPointerArrayArrayV094[SPI_CHANNEL_1]);

// *** loop display 8 digits of each 8 MAX7219s, connected to SPI x,y ***

       while (1)
       {
      Max7219DisplayEightDigitV0905(SPI_CHANNEL_0, SLAVE_SELECT_0, 5, 14, 1, 15, 15, 15, 0, 0, NO_DEBUG);

      Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_1, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 0, 1, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_2, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 0, 2, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_3, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 0, 3, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_4, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 0, 4, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_5, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 0, 4, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_6, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 0, 6, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_7, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 0, 7, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_8, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
                                                           5, 14, 1, 15, 15, 15, 0, 7, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_0, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 1, 0, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_1, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 1, 1, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_2, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 1, 2, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_3, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 1, 3, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_4, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 1, 4, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_5, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 1, 5, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_6, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 1, 6, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_7, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 1, 7, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_8, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 1, 8, NO_DEBUG);
       }
}

void testMax7219DisplayEightDigitV093()
{
       while (1)
       {
      // *** SPI 0,0 to 0,8 ***
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_0, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 0, 0, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_1, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 0, 1, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_2, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 0, 2, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_3, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 0, 3, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_4, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 0, 4, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_5, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 0, 4, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_6, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 0, 6, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_7, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 0, 7, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_8, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 0, 8, NO_DEBUG);

      // *** SPI 1,0 to 1,8 ***
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_0, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 1, 0, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_1, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 1, 1, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_2, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 1, 2, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_3, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 1, 3, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_4, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 1, 4, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_5, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 1, 5, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_6, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 1, 6, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_7, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 1, 7, NO_DEBUG);
      Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_8, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
                                               5, 14, 1, 15, 15, 15, 1, 8, NO_DEBUG);
       }

}

// ***************************************************************************
// End
// ***************************************************************************




void testMax7219V090()
{
// testMax7219V0901();
// testMax7219V0902();
// testMax7219V0903();
// testMax7219V0904(); // SPI0,0
// testMax7219V0905(); // SPI 1,0

  // testMax7219EightDigitV0907(SPI_CHANNEL_0, SLAVE_SELECT_0, 3, 0, 0, 0, 0, 0, 0, 0, NO_DEBUG);
       // testMax7219EightDigitV0907(SPI_CHANNEL_0, SLAVE_SELECT_1, 3, 0, 0, 0, 0, 0, 0, 1, NO_DEBUG);

  testMax7219EightDigitV0907(SPI_CHANNEL_1, SLAVE_SELECT_0, 3, 0, 0, 0, 0, 0, 1, 0, NO_DEBUG);
       // testMax7219EightDigitV0907(SPI_CHANNEL_1, SLAVE_SELECT_1, 3, 0, 0, 0, 0, 0, 1, 1, NO_DEBUG);

       // testMax7219EightDigitV0907(SPI_CHANNEL_1, SLAVE_SELECT_0, 3, 0, 0, 0, 0, 0, 0, 3, DEBUG);
       // testMax7219EightDigitV0907(SPI_CHANNEL_1, SLAVE_SELECT_1, 3, 0, 0, 0, 0, 0, 0, 3, DEBUG);
}

// ***************************************************************************
// End
// ***************************************************************************

/*
testMax7219DisplayMatrixV0804(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                             SPI_CHANNEL_0, SLAVE_SELECT_5, \
                             MATRIX_0, MatrixChar_K,  \
                             MATRIX_1, MatrixChar_O);

void testMax7219DisplayMatrixV0804(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
                                   uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
                                   uint8_t matrixNumber0, uint8_t matrixData0[], \
                                   uint8_t matrixNumber1, uint8_t matrixData1[])
{
setupAllSpiChannelsAndSlaveSelectPorts(portPinArraryPointerArrayArray);

setupMax7219MatrixModeV090(portPinArraryPointerArrayArray, \
                          spiChannelNumber, slaveSelectNumber, \
                          matrixNumber0);

setupMax7219MatrixModeV090(portPinArraryPointerArrayArray, \
                          spiChannelNumber, slaveSelectNumber, \
                          matrixNumber1);

displayMax7219OneMatrix0803(portPinArraryPointerArrayArray, \
                  spiChannelNumber, slaveSelectNumber, \
                  matrixNumber0, matrixData0);

displayMax7219OneMatrix0803(portPinArraryPointerArrayArray, \
                  spiChannelNumber, slaveSelectNumber, \
                  matrixNumber1, matrixData1);
}
*/
/*
void testMax7219DisplayMatrixV0803(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
                                   uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
                                   uint8_t matrixNumber, uint8_t matrixData[])
{
setupAllSpiChannelsAndSlaveSelectPorts(portPinArraryPointerArrayArray);

setupMax7219PositionMatrixModeV080(portPinArraryPointerArrayArray, \
                          spiChannelNumber, slaveSelectNumber, \
                          matrixNumber);

displayMax7219OneMatrix0803(portPinArraryPointerArrayArray, \
                  spiChannelNumber, slaveSelectNumber, \
                  matrixNumber, matrixData);
}
*/

/*
void testMax7219DisplayMatrixV0801(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
                                   uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
                                   uint8_t matrixNumber, uint8_t matrixData[])
{
setupAllSpiChannelsAndSlaveSelectPorts(portPinArraryPointerArrayArray);

setupMax7219PositionMatrixModeV080(portPinArraryPointerArrayArray, \
                          spiChannelNumber, slaveSelectNumber, \
                          matrixNumber);

displayMax7219OneMatrix080(portPinArraryPointerArrayArray, \
                  spiChannelNumber, slaveSelectNumber, \
                  matrixData);
}

void testMax7219PositionDisplayMatrixV080(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
                                  uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
                                  uint8_t matrixColumn[], uint8_t positionNumber)
{
setupAndDisplayMax7219MatrixV080(portPinArraryPointerArrayArray, \
                       spiChannelNumber, slaveSelectNumber, \
                       matrixColumn);
}


void testMax7219v080(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
        uint8_t spiChannelNumber, uint8_t slaveSelectNumber)
{
// *** Set up all SPI channels and their slave select ports ***
setupAllSpiChannelsAndSlaveSelectPorts(portPinArraryPointerArrayArray);

printf("\n\n*** test Max7219 - 2013nov22 ***\n\n");

displayMcp7219Display8DigitsV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, \
                         2, 2, 3, 4, 5, 6, 7, 8);
printf("\n*** End of test ***\n");

// *** For debugging only ***
printf("\n*** Now repeat 400 times every 10 mS ***\n");
uint8_t i;
for (i = 0; i < 200; i++)
{
displayMcp7219Display8DigitsV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, \
 3, 2, 3, 4, 5, 6, 7, 8);
delayMilliSecond(10);
}
}
*/

/*

void testMcp25Lc256V080(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
                uint8_t spiChannelNumber, uint8_t slaveSelectNumber)
{
uint8_t statusRegisterValue;
uint8_t readBackDataByte;

// *** Set up all SPI chanels and their slave select ports ***
setupAllSpiChannelsAndSlaveSelectPorts(portPinArraryPointerArrayArray);

// *** Now start testing EEPROM ***

printf("\n\n*** MCP25LC256 Test - 2013nov21hkt2120 ***\n\n");

printf("\nSPI Channel Number  = %2d", slaveSelectNumber);
printf("\nSlave Select Number = %2d\n", slaveSelectNumber);

printf("\nNow writing 0x88 ...\n");
eepromWriteLatch080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, ENABLE_WRITE_LATCH);
eepromByteWrite080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, TEST_ADDRESS_UPPER, TEST_ADDRESS_LOWER, TEST_DATA_BYTE_88);

printf("\nNow writing 0x88 a second time ...\n");
eepromWriteLatch080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, ENABLE_WRITE_LATCH);
eepromByteWrite080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, TEST_ADDRESS_UPPER, TEST_ADDRESS_LOWER, TEST_DATA_BYTE_88);

delayMilliSecond(100);

// printf("\n Now testing byte read ...\n");
readBackDataByte = eepromByteRead080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, TEST_ADDRESS_UPPER, TEST_ADDRESS_LOWER);
printf("\nReadback databyte = %02x \n", readBackDataByte);

// printf("\n Now testing byte read ...\n");
readBackDataByte = eepromByteRead080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, TEST_ADDRESS_UPPER, TEST_ADDRESS_LOWER);
printf("\nReadback databyte second time = %02x \n", readBackDataByte);

delayMilliSecond(100);

printf("\nNow writing 0x77 ...\n");
eepromWriteLatch080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, ENABLE_WRITE_LATCH);
eepromByteWrite080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, TEST_ADDRESS_UPPER, TEST_ADDRESS_LOWER, TEST_DATA_BYTE_77);

delayMilliSecond(100);

// printf("\n Now testing byte read ...\n");
readBackDataByte = eepromByteRead060(spiChannelNumber, slaveSelectNumber, TEST_ADDRESS_UPPER, TEST_ADDRESS_LOWER);
printf("\nReadback databyte = %02x \n", readBackDataByte);



printf("\nNow writing 0x77 ...\n");
eepromWriteLatch080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, ENABLE_WRITE_LATCH);
eepromByteWrite080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, TEST_ADDRESS_UPPER, TEST_ADDRESS_LOWER, TEST_DATA_BYTE_77);

printf("\nNow writing 0x77 a second time ...\n");
eepromWriteLatch080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, ENABLE_WRITE_LATCH);
eepromByteWrite080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, TEST_ADDRESS_UPPER, TEST_ADDRESS_LOWER, TEST_DATA_BYTE_77);

delayMilliSecond(100);

// printf("\n Now testing byte read ...\n");
readBackDataByte = eepromByteRead080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, TEST_ADDRESS_UPPER, TEST_ADDRESS_LOWER);
printf("\nReadback databyte = %02x \n", readBackDataByte);

// printf("\n Now testing byte read ...\n");
readBackDataByte = eepromByteRead080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, TEST_ADDRESS_UPPER, TEST_ADDRESS_LOWER);
printf("\nReadback databyte second time = %02x \n", readBackDataByte);



printf("\n*** End of testMcp25Lc256 ***\n");
printf("                                           \n");
printf("                                           \n");
}
*/

// ***************************************************************************
// End
// ***************************************************************************



// ***************************************************************************
// Old functions
// ***************************************************************************

/*
void testSpiLoopBack()
{
setupAllSpiChannelsAndSlaveSelectPorts(Olimex20SlaveSelectPortPinArrayPointerArrayArray);

while (1)
{
spiLoopBack082(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                  SPI_CHANNEL_0, SLAVE_SELECT_0);
spiLoopBack082(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                  SPI_CHANNEL_0, SLAVE_SELECT_1);
spiLoopBack082(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                  SPI_CHANNEL_0, SLAVE_SELECT_2);
spiLoopBack082(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                  SPI_CHANNEL_0, SLAVE_SELECT_3);
spiLoopBack082(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                  SPI_CHANNEL_0, SLAVE_SELECT_5);
spiLoopBack082(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                  SPI_CHANNEL_0, SLAVE_SELECT_6);
spiLoopBack082(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                       SPI_CHANNEL_0, SLAVE_SELECT_4);
}
}

void testSpiSselPin()
{
// testSpiSselPin0801();
// testSpiSselPin0802();
// testSpiSselPin0803();
// testSpiSselPin0804(Olimex20SlaveSelectPortPinArrayPointerArrayArray);
// testSpiSselPin0805(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                  // SPI_CHANNEL_0, SLAVE_SELECT_3, 200, 500, 4);
    // testSpiSselPin0806();
}


void testSpiLoopBack081()
{
setupAllSpiChannelAndSlaveSelect081();

spiLoopBack080(SPI_CHANNEL_0, SLAVE_SELECT_0);
spiLoopBack080(SPI_CHANNEL_0, SLAVE_SELECT_1);
spiLoopBack080(SPI_CHANNEL_0, SLAVE_SELECT_2);
spiLoopBack080(SPI_CHANNEL_0, SLAVE_SELECT_3);
spiLoopBack080(SPI_CHANNEL_0, SLAVE_SELECT_4);
spiLoopBack080(SPI_CHANNEL_0, SLAVE_SELECT_5);
    spiLoopBack080(SPI_CHANNEL_0, SLAVE_SELECT_6);
}

// ***************************************************************************
// End
// ***************************************************************************




// ***************************************************************************
// Function - Test MAX7219
// Date     - 2013nov19
// ***************************************************************************

void testMax7219v0702(uint8_t spiChannelNumber, uint8_t slaveSelectNumber)
{
printf("\n\n*** test Max7219 - 2013nov19 ***\n\n");
// spiSetup060(spiChannelNumber, slaveSelectNumber);
spiSetup070(spiChannelNumber, slaveSelectNumber); // this version will NOT
                                                 // repeatedly set up SPI
displayMcp7219Display8DigitsV0701(spiChannelNumber, slaveSelectNumber, \
                         2, 2, 3, 4, 5, 6, 7, 8);
printf("\n*** End of test ***\n");

// *** For debugging only ***
printf("\n*** Now repeat 400 times every 10 mS ***\n");
uint8_t i;
for (i = 0; i < 200; i++)
{
displayMcp7219Display8DigitsV0701(spiChannelNumber, slaveSelectNumber, \
 3, 2, 3, 4, 5, 6, 7, 8);
delayMilliSecond(10);
}
// *** End of debugging ***
}

// ***************************************************************************
// End
// ***************************************************************************



void testBlinkLedP08()
{
setupGpioPinOutputLow050(PortPinArrayP08); // Setup as output P30
blinkLed0501(PortPinArrayP08); // Blink
}

void testBlinkLedP10()
{
setupGpioPinOutputLow050(PortPinArrayP10); // Setup as output P30
blinkLed0501(PortPinArrayP10); // Blink
}

void testBlinkLedP30()
{
setupGpioPinOutputLow050(PortPinArrayP30); // Setup as output P30
blinkLed0501(PortPinArrayP30); // Blink
}


void testMcp25Lc256V0703(uint8_t spiChannelNumber, uint8_t slaveSelectNumber)
{
uint8_t statusRegisterValue;
uint8_t readBackDataByte;

printf("\n\n*** MCP25LC256 Test - 2013nov18hkt1418 ***");

printf("\nSPI Channel Number  = %2d", slaveSelectNumber);
printf("\nSlave Select Number = %2d", slaveSelectNumber);

spiSetup070(spiChannelNumber, slaveSelectNumber);

printf("\nNow writing 0x77 ...\n");
eepromWriteLatch060(spiChannelNumber, slaveSelectNumber, ENABLE_WRITE_LATCH);
eepromByteWrite060(spiChannelNumber, slaveSelectNumber, TEST_ADDRESS_UPPER, TEST_ADDRESS_LOWER, TEST_DATA_BYTE_77);

delayMilliSecond(100);

// printf("\n Now testing byte read ...\n");
readBackDataByte = eepromByteRead060(spiChannelNumber, slaveSelectNumber, TEST_ADDRESS_UPPER, TEST_ADDRESS_LOWER);
printf("\nReadback databyte = %02x \n", readBackDataByte);

delayMilliSecond(100);

printf("\nNow writing 0x55 ...\n");
eepromWriteLatch060(spiChannelNumber, slaveSelectNumber, ENABLE_WRITE_LATCH);
eepromByteWrite060(spiChannelNumber, slaveSelectNumber, TEST_ADDRESS_UPPER, TEST_ADDRESS_LOWER, TEST_DATA_BYTE_55);

delayMilliSecond(100);

// printf("\n Now testing byte read ...\n");
readBackDataByte = eepromByteRead060(spiChannelNumber, slaveSelectNumber, TEST_ADDRESS_UPPER, TEST_ADDRESS_LOWER);
printf("\nReadback databyte = %02x \n", readBackDataByte);
*/

/*

printf("\nNow writing byte 0x44 ...");
eepromWriteLatch060(spiChannelNumber, slaveSelectNumber, ENABLE_WRITE_LATCH);
eepromByteWrite(spiChannelNumber, TEST_ADDRESS_UPPER, TEST_ADDRESS_LOWER, TEST_DATA_BYTE_44);

delayMilliSecond(200);

// printf("\n Now readig back byte written ...\n");
readBackDataByte = eepromByteRead060(spiChannelNumber, slaveSelectNumber, TEST_ADDRESS_UPPER, TEST_ADDRESS_LOWER);
printf("\nReadback databyte = %02x", readBackDataByte);

printf("\n*** End of testMcp25Lc256 ***\n");
printf("                                           \n");
printf("                                           \n");

}

*/

/*
// ***************************************************************************
// Function - Blink Olimex Led01 (P30)
// Call     - testBlinkOlimexLed1()
// Date     - 2013oct27
// ***************************************************************************
void testBlinkOlimexLed1()
{
setupGpioPinOutputLow050(OlimexBoardLedPortPinArray1); // Setup as output P30
blinkLed0501(OlimexBoardLedPortPinArray1); // Blink
}

void testOlimexLedKey01() // tested OK 2013oct13
{
// *** For all mcu boards - setup GPIO pin as out and toggle ***
setupGpioPinOutputLow050(PortPinArrayP09); // setup GPIO pin as ooutput
blinkLed0501(PortPinArrayP09); // blink led

// *** Olimex test only - setup I/O pins for testing ***
setupOlimexGpio050(); // setup Olimex GPIO pins as output and input

// *** Olimex test only - blink single LED and run all LEDs***
blinkOlimexLed(LED_7, ON_ONE_FIFTH_SECOND, OFF_ONE_FIFTH_SECOND, REPEAT_6_TIMES); // blink one Led
runOlimexLeds();  // sequentially blink all 8 Leds

// *** Olimex test only - echo key by led ***
echoOlimexKeyByLed(KEY_1, LED_1); // echo Olimex key by led
echoOlimexKeyByLed(KEY_2, LED_2); // echo Olimex key by led
echoOlimexKeyByLed(KEY_1, LED_3); // echo Olimex key by led

// *** For all mcu boards, given mcu board struct, echo key by led ***
echoKeyByLed0504(OlimexLpc1114DevBoardStruct, KEY_1, LED_5); // given mcuboard struct, echo key by led
}

/*
// *** Olimex LED port pin array ***

#define MAX_OLIMEX_LED_PIN_NUMBER 8 // 2013oct11

#define SERIAL_CLOCK_INDEX 0
#define SERIAL_DATA_IN_INDEX 1
#define PARALLEL_DATA_OUTPUT_LATCH_INDEX 2
#define OUTPUT_ENABLE_INDEX 3

int SizeOfPortPinArrayPointer = sizeof(PortPinArrayP04);

portPinArray OlimexBoardLedPortPinArray1 = {PORT3, PIN0}; // LED 0 2013oct11
portPinArray OlimexBoardLedPortPinArray2 = {PORT3, PIN1}; // LED 1 2013oct11
portPinArray OlimexBoardLedPortPinArray3 = {PORT3, PIN2}; // LED 2 2013oct11
portPinArray OlimexBoardLedPortPinArray4 = {PORT3, PIN3}; // LED 3 2013oct11
portPinArray OlimexBoardLedPortPinArray5 = {PORT3, PIN4}; // LED 4 2013oct11
portPinArray OlimexBoardLedPortPinArray6 = {PORT3, PIN5}; // LED 5 2013oct11
portPinArray OlimexBoardLedPortPinArray7 = {PORT2, PIN6}; // LED 6 2013oct11
portPinArray OlimexBoardLedPortPinArray8 = {PORT2, PIN7}; // LED 7 2013oct11

portPinArrayPointerArray OlimexBoardLedPortPinArrayPointerArray[MAX_OLIMEX_LED_PIN_NUMBER] = \
  {&OlimexBoardLedPortPinArray1, &OlimexBoardLedPortPinArray2, \
  &OlimexBoardLedPortPinArray3, &OlimexBoardLedPortPinArray4, \
  &OlimexBoardLedPortPinArray5, &OlimexBoardLedPortPinArray6, \
  &OlimexBoardLedPortPinArray7, &OlimexBoardLedPortPinArray8};

// *** Olimex Key port pin array ***

#define MAX_OLIMEX_KEY_PIN_NUMBER 2

portPinArray OlimexBoardKeyPortPinArray1 = {PORT2, PIN9};
portPinArray OlimexBoardKeyPortPinArray2 = {PORT1, PIN4};

portPinArrayPointerArray OlimexBoardKeyPortPinArrayPointerArray[MAX_OLIMEX_KEY_PIN_NUMBER] = \
    {&OlimexBoardKeyPortPinArray1, &OlimexBoardKeyPortPinArray2};

// *** Olimex LPC1114 Board Struct ***

mcuBoardStruct OlimexLpc1114DevBoardStruct = {OlimexBoardLedPortPinArrayPointerArray, \
OlimexBoardKeyPortPinArrayPointerArray};
*/

/*
// ***************************************************************************
// Function - Blink P09 LED
// Call     - testBlinkLpc1114LedP03()
// Date     - 2013oct27
// ***************************************************************************
void testBlinkLpc1114LedP09()
{
    setupGpioPinOutputLow050(PortPinArrayP09); // Setup as output
blinkLed0501(PortPinArrayP09); // Blink
}
void testOlimex7segmentLed0201()
{
    // *** system self diagnostic test - blink LED P09 ***
setupGpioPinOutputLow050(PortPinArrayP03); // setup GPIO pin as output
blinkLed0501(PortPinArrayP03); // blink led

// *** Testing 7 segment LED ***
displayAllDigits050(OlimexBoardSevenSegmentLedPortPinArrayPointerArray2, MAX_OLIMEX_7_SEG_LED_PIN_NUMBER);
}

// ***************************************************************************
// Function - Test WuYin Minimal Board
// Date     - 2013nov17hkt1153
// ***************************************************************************
void testWuYinBlinkLedP33()
{
    setupGpioPinOutputLow050(PortPinArrayP33); // Setup as output init value Low

    uint8_t i;
    for (i=0; i < 2; i++)
    {
    blinkLed0501(PortPinArrayP33);
    }
}

void testWuYinEchoKeyP15ByLedP33()
{
    uint8_t i;
    for (i=0; i < 2; i++)
    {
    echoKeyByLed02(PortPinArrayP15, PortPinArrayP33);
    }
}

// ***************************************************************************
// Function - Test Blue Magic Minimal Board
// Date     - 2013nov17hkt1152
// ***************************************************************************

void testBlink6LedV0701()
{
printf("\n\*** Blink 6 LED - 2013nov17 ***\n");

setupGpioPinOutputLow050(PortPinArrayP03);
setupGpioPinOutputLow050(PortPinArrayP07);
setupGpioPinOutputLow050(PortPinArrayP011);
setupGpioPinOutputLow050(PortPinArrayP25);
setupGpioPinOutputLow050(PortPinArrayP19);
setupGpioPinOutputLow050(PortPinArrayP24);

    int8_t i;
    for (i = 0; i < 10000; i++)
    {
    blinkLed0501(PortPinArrayP03);
    blinkLed0501(PortPinArrayP07);
    blinkLed0501(PortPinArrayP011);
    blinkLed0501(PortPinArrayP25);
    blinkLed0501(PortPinArrayP19);
    blinkLed0501(PortPinArrayP24);
    }
    printf("\n\n*** End of test ***\n\n");
}


// ***************************************************************************
// Function - Blink LED P03
// Date     - 2013nov16
// ***************************************************************************
void testBlinkLedP03V0701()
{
printf("\n\*** Blink LED P03 - 2013nov16 ***\n");

setupGpioPinOutputLow050(PortPinArrayP03);
    int8_t i;
    for (i = 0; i < 1; i++)
    {
    blinkLed0501(PortPinArrayP03);
    }

    printf("\n\n*** End of test ***\n\n");
}

// ***************************************************************************
// Function - Blink LED P25
// Date     - 2013nov16
// ***************************************************************************
void testBlinkLedP25V0701()
{
printf("\n\*** Blink LED P25 - 2013nov16 ***\n");

setupGpioPinOutputLow050(PortPinArrayP25);
    int8_t i;
    for (i = 0; i < 1; i++)
    {
    blinkLed0501(PortPinArrayP25);
    }

    printf("\n\n*** End of test ***\n\n");
}

// ***************************************************************************
// Function - Blink LED P07
// Date     - 2013nov16
// ***************************************************************************
void testBlinkLedP07V0701()
{
printf("\n\*** Blink LED P07 - 2013nov16 ***\n");

setupGpioPinOutputLow050(PortPinArrayP07);
    int8_t i;
    for (i = 0; i < 1; i++)
    {
    blinkLed0501(PortPinArrayP07);
    }

    printf("\n\n*** End of test ***\n\n");
}

// ***************************************************************************
// Function - Blink LED P011
// Date     - 2013nov16
// ***************************************************************************
void testBlinkLedP011V0701()
{
printf("\n\*** Blink LED P07 - 2013nov16 ***\n");

setupGpioPinOutputLow050(PortPinArrayP011);
    int8_t i;
    for (i = 0; i < 1; i++)
    {
    blinkLed0501(PortPinArrayP011);
    }

    printf("\n\n*** End of test ***\n\n");
}

// ***************************************************************************
// Function - Blink LED P19
// Date     - 2013nov17
// ***************************************************************************
void testBlinkLedP19V0701()
{
printf("\n\*** Blink LED P19 - 2013nov17 ***\n");

setupGpioPinOutputLow050(PortPinArrayP19);
    int8_t i;
    for (i = 0; i < 1; i++)
    {
    blinkLed0501(PortPinArrayP19);
    }

    printf("\n\n*** End of test ***\n\n");
}

// ***************************************************************************
// Function - Blink LED P24
// Date     - 2013nov17
// ***************************************************************************
void testBlinkLedP24V0701()
{
printf("\n\*** Blink LED P24 - 2013nov17 ***\n");

setupGpioPinOutputLow050(PortPinArrayP24);
    int8_t i;
    for (i = 0; i < 1; i++)
    {
    blinkLed0501(PortPinArrayP24);
    }

    printf("\n\n*** End of test ***\n\n");
}


// ***************************************************************************
// Function - Test ADC
// Date     - 2013nov14
// ***************************************************************************
void testMcp3208V0701(uint8_t spiChannelNumber)
{
printf("\n\n*** Test ADC - 2013nov16 ***\n\n\n");
testMcp3208v07(spiChannelNumber, ADC_CHANNEL_0);
testMcp3208v07(spiChannelNumber, ADC_CHANNEL_1);
testMcp3208v07(spiChannelNumber, ADC_CHANNEL_2);
testMcp3208v07(spiChannelNumber, ADC_CHANNEL_3);
testMcp3208v07(spiChannelNumber, ADC_CHANNEL_4);
testMcp3208v07(spiChannelNumber, ADC_CHANNEL_5);
testMcp3208v07(spiChannelNumber, ADC_CHANNEL_6);
testMcp3208v07(spiChannelNumber, ADC_CHANNEL_7);
printf("\n*** End of test ***\n");
// printf("\n                   \n");
// printf("\n                   \n");
}

void testMcp3208v07(uint8_t spiChannelNumber, uint8_t adcChannelNumber)
{
mcp3208v03(spiChannelNumber, adcChannelNumber); // SPI0
}

// ***************************************************************************
// Function - Test EEPROM
// Date     - 2013nov14
// ***************************************************************************
void testMcp25Lc256V0701(uint8_t spiChannelNumber)
{
uint8_t statusRegisterValue;
uint8_t readBackDataByte;

printf("\n\n*** Test EEPROM - 2013nov16 ***\n\n");

setupSpi051(spiChannelNumber);

// eepromWriteLatch(ENABLE_WRITE_LATCH, spiChannelNumber);
// statusRegisterValue = eepromReadStatusRegister(spiChannelNumber);
// printf("\n Write Latch enabled Status Register value = %02x ", statusRegisterValue);

// eepromWriteLatch(DISABLE_WRITE_LATCH, spiChannelNumber);
// statusRegisterValue = eepromReadStatusRegister(spiChannelNumber);
// printf("\n Write Latch disabled Status Register value = %02x \n", statusRegisterValue);

printf("\n Now writing 0x55 ...\n");
eepromWriteLatch(ENABLE_WRITE_LATCH, spiChannelNumber);
eepromByteWrite(spiChannelNumber, TEST_ADDRESS_UPPER, TEST_ADDRESS_LOWER, TEST_DATA_BYTE_55);
// eepromByteWrite(spiChannelNumber, TEST_ADDRESS_UPPER, TEST_ADDRESS_LOWER, TEST_DATA_BYTE_77);

printf("\n Now testing byte read ...\n");
readBackDataByte = eepromByteRead(spiChannelNumber, TEST_ADDRESS_UPPER, TEST_ADDRESS_LOWER);
printf("\n Readback databyte = %02x \n", readBackDataByte);

printf("\n Now writing byte 0xaa ...\n");
eepromWriteLatch(ENABLE_WRITE_LATCH, spiChannelNumber);
eepromByteWrite(spiChannelNumber, TEST_ADDRESS_UPPER, TEST_ADDRESS_LOWER, TEST_DATA_BYTE_AA);
// eepromByteWrite(spiChannelNumber, TEST_ADDRESS_UPPER, TEST_ADDRESS_LOWER, TEST_DATA_BYTE_44);

printf("\n Now testing byte read ...\n");
readBackDataByte = eepromByteRead(spiChannelNumber, TEST_ADDRESS_UPPER, TEST_ADDRESS_LOWER);
printf("\n Readback databyte = %02x \n", readBackDataByte);

printf("\n*** End of test ***\n");
printf("                     \n");
printf("                     \n");
}

// ***************************************************************************
// Function - Test MAX7219 7-segment LED
// Date     - 2013nov06
// ***************************************************************************
void testMax7219DigitV0701(uint8_t spiChannelNumber)
{
setupSpi051(spiChannelNumber);
max7219SegmentLed01(spiChannelNumber);
}

// ***************************************************************************
// Function - Test EEPROM
// Date     - 2013nov11
// ***************************************************************************
void testMcp25Lc256V0702(uint8_t spiChannelNumber, uint8_t slaveSelectNumber)
{
uint8_t statusRegisterValue;
uint8_t readBackDataByte;

printf("\n\n*** MCP25LC256 Test - 2013nov11hkt1031 ***\n\n");

// setupSpi051(spiChannelNumber); // *** Version 5.0
spiSetup060(spiChannelNumber, slaveSelectNumber); // !!! Version 6.0

// eepromWriteLatch(ENABLE_WRITE_LATCH, spiChannelNumber);
// statusRegisterValue = eepromReadStatusRegister(spiChannelNumber);
// printf("\n Write Latch enabled Status Register value = %02x ", statusRegisterValue);

// eepromWriteLatch(DISABLE_WRITE_LATCH, spiChannelNumber);
// statusRegisterValue = eepromReadStatusRegister(spiChannelNumber);
// printf("\n Write Latch disabled Status Register value = %02x \n", statusRegisterValue);

printf("\n Now writing 0x77 ...\n");
eepromWriteLatch060(spiChannelNumber, slaveSelectNumber, ENABLE_WRITE_LATCH);
eepromByteWrite060(spiChannelNumber, slaveSelectNumber, TEST_ADDRESS_UPPER, TEST_ADDRESS_LOWER, TEST_DATA_BYTE_77);

delayMilliSecond(100);

// printf("\n Now testing byte read ...\n");
readBackDataByte = eepromByteRead060(spiChannelNumber, slaveSelectNumber, TEST_ADDRESS_UPPER, TEST_ADDRESS_LOWER);
printf("\n Readback databyte = %02x \n", readBackDataByte);

printf("\n Now writing byte 0x44 ...\n");
eepromWriteLatch060(spiChannelNumber, slaveSelectNumber, ENABLE_WRITE_LATCH);
eepromByteWrite(spiChannelNumber, TEST_ADDRESS_UPPER, TEST_ADDRESS_LOWER, TEST_DATA_BYTE_44);

delayMilliSecond(100);

// printf("\n Now testing byte read ...\n");
readBackDataByte = eepromByteRead060(spiChannelNumber, slaveSelectNumber, TEST_ADDRESS_UPPER, TEST_ADDRESS_LOWER);
printf("\n Readback databyte = %02x \n", readBackDataByte);

printf("\n*** End of testMcp25Lc256 ***\n");
printf("                                           \n");
printf("                                           \n");
}

// ***************************************************************************
// Function - Test ADC
// Date     - 2013nov16
// ***************************************************************************
void testMcp3208V0702(uint8_t spiChannelNumber, uint8_t slaveSelectNumber)
{
printf("\n\n*** Test ADC - 2013nov10hk2112 ***\n\n");

testMcp3208V0601(spiChannelNumber, slaveSelectNumber, ADC_CHANNEL_0);
testMcp3208V0601(spiChannelNumber, slaveSelectNumber, ADC_CHANNEL_1);
testMcp3208V0601(spiChannelNumber, slaveSelectNumber, ADC_CHANNEL_2);
testMcp3208V0601(spiChannelNumber, slaveSelectNumber, ADC_CHANNEL_3);
testMcp3208V0601(spiChannelNumber, slaveSelectNumber, ADC_CHANNEL_4);
testMcp3208V0601(spiChannelNumber, slaveSelectNumber, ADC_CHANNEL_5);
testMcp3208V0601(spiChannelNumber, slaveSelectNumber, ADC_CHANNEL_6);
testMcp3208V0601(spiChannelNumber, slaveSelectNumber, ADC_CHANNEL_7);
}

void testMcp3208V0601(uint8_t spiChannelNumber, uint8_t slaveSelectNumber, uint8_t adcChannelNumber)
{
mcp3208V060(spiChannelNumber, slaveSelectNumber, adcChannelNumber);
}


// ***********************************************************************
// End
// ***********************************************************************


// ***********************************************************************
// *** Old tests 2013nov13 ***
// ***********************************************************************


// *** Basic GPIO tests on P33 LED and P15 Key ***
// testWuYinBlinkLedP33(); // OK 2013nov13
// testWuYinEchoKeyP15ByLedP33(); // OK 2013nov13

// *** Basic SPI tests on SPI 0,0, SPI 1,0 ***
// testMax7219SegmentLed01(SPI_CHANNEL_0); // OK 2013nov13
// testMax7219SegmentLed01(SPI_CHANNEL_1); // OK 2013nov13

// testAdc04(SPI_CHANNEL_0); // OK 2013nov13

// testMcp25Lc256(SPI_CHANNEL_0); // OK 2013nov13

// testMax7219SegmentLed01(SPI_CHANNEL_0); // OK 2013nov13

// *** Basic SPI tests on SPI 1,0 ***
// testMax7219SegmentLed01(SPI_CHANNEL_1); // OK 2013nov13

// *** Basic SPI tests on SPI 0,0, 0,1, 0,2, 0,3 ***
// testMcp25Lc256V0600(SPI_CHANNEL_0, SLAVE_SELECT_0);


// testMax7219v0600(SPI_CHANNEL_0, SLAVE_SELECT_0);
// testMax7219v0601(SPI_CHANNEL_0, SLAVE_SELECT_1);

// testMax7219v0601(SPI_CHANNEL_0, SLAVE_SELECT_2);
// testMax7219v0601(SPI_CHANNEL_0, SLAVE_SELECT_3);

// testAdc04(SPI_CHANNEL_1);
// testMcp3208V0600(SPI_CHANNEL_0, SLAVE_SELECT_0);

// testMcp25Lc256(SPI_CHANNEL_1);

// testMcp25Lc256V0600(SPI_CHANNEL_0, SLAVE_SELECT_1);
// testMcp25Lc256V0600(SPI_CHANNEL_0, SLAVE_SELECT_2);
// testMcp25Lc256V0600(SPI_CHANNEL_0, SLAVE_SELECT_3);


// *** 2013nov11hkt1414 ***

// testMcp25Lc256V0600(SPI_CHANNEL_0, SLAVE_SELECT_0); // OK
// testMcp25Lc256V0600(SPI_CHANNEL_0, SLAVE_SELECT_1); // not stable!!!

// testMcp3208V0600(SPI_CHANNEL_0, SLAVE_SELECT_0); // OK
// testMcp3208V0600(SPI_CHANNEL_0, SLAVE_SELECT_1); // OK

// testMax7219v0600(SPI_CHANNEL_0, SLAVE_SELECT_0); // OK
// testMax7219v0601(SPI_CHANNEL_0, SLAVE_SELECT_1); // OK

// testMcp3208V0600(SPI_CHANNEL_0, SLAVE_SELECT_0); // OK
// testMcp3208V0600(SPI_CHANNEL_0, SLAVE_SELECT_1); // OK

// testBlinkLpc1114LedP03();

/*
// testBlinkLpc1114LedP03(); // testing system LED
// testAdc04(SPI_CHANNEL_1);
// testMax7219MatrixLed05(SPI_CHANNEL_0);

testLedArray060(SPI_CHANNEL_0, SLAVE_SELECT_0); // display 2 matrix LEDs, 2 8-digit LEDs
testLedArray061(SPI_CHANNEL_0, SLAVE_SELECT_1); // display 1 8-digit LED

testAdc04(SPI_CHANNEL_1);

// testAdc060(SPI_CHANNEL_0, SLAVE_SELECT_1);

// testAdc060(SPI_CHANNEL_0, SLAVE_SELECT_2);

*/



/*
void testMax7219SegmentLed02(uint8_t spiChannelNumber, uint8_t slaveSelectNumber)
{
testDisplayLedArray061(spiChannelNumber, slaveSelectNumber);
}





void testMax7219v0601(uint8_t spiChannelNumber, uint8_t slaveSelectNumber)
{
printf("\n\n*** testMax7219V0601 - 2013nov11hk0911 ***\n\n");
spiSetup060(spiChannelNumber, slaveSelectNumber);
testDisplayLedArray061(spiChannelNumber, slaveSelectNumber);
printf("\n*** End of testMax7219V0601 ***\n");
}

void testMcp3208(uint8_t spiChannelNumber, uint8_t adcChannelNumber)
{
mcp3208v03(spiChannelNumber, adcChannelNumber); // SPI0
}


// ***************************************************************************
// Function - Test ADC
// Date     - 2013nov10
// ***************************************************************************

void testAdc060(uint8_t spiChannelNumber, uint8_t slaveSelectNumber)
{
printf("\n\n*** Test ADC - 2013nov10hk2112 ***\n\n");

testMcp3208v060(spiChannelNumber, slaveSelectNumber, ADC_CHANNEL_0);
testMcp3208v060(spiChannelNumber, slaveSelectNumber, ADC_CHANNEL_1);
testMcp3208v060(spiChannelNumber, slaveSelectNumber, ADC_CHANNEL_2);
testMcp3208v060(spiChannelNumber, slaveSelectNumber, ADC_CHANNEL_3);
testMcp3208v060(spiChannelNumber, slaveSelectNumber, ADC_CHANNEL_4);
testMcp3208v060(spiChannelNumber, slaveSelectNumber, ADC_CHANNEL_5);
testMcp3208v060(spiChannelNumber, slaveSelectNumber, ADC_CHANNEL_6);
testMcp3208v060(spiChannelNumber, slaveSelectNumber, ADC_CHANNEL_7);
}

// ***************************************************************************
// Function - Test 8-channel 12-bit ADC MCP3208
// Call     - testMcp3208(SPI_CHANNEL_1, ADC_CHANNEL_2);
// Date     - 2013oct27
// ***************************************************************************

// ***********************************************************************
// End
// ***********************************************************************

void testMax7219MatrixLed05(uint8_t spiChannelNumber)
{
setupSpi051(spiChannelNumber);
max7219MatrixLed05(spiChannelNumber);
}

void testMax7219MatrixLed04(uint8_t spiChannelNumber)
{
setupSpi051(spiChannelNumber);
max7219MatrixLed04(spiChannelNumber);
}

void testMax7219MatrixLed03(uint8_t spiChannelNumber)
{
setupSpi051(spiChannelNumber);
max7219MatrixLed03(spiChannelNumber);
}

void testMax7219MatrixLed02(uint8_t spiChannelNumber)
{
setupSpi051(spiChannelNumber);
max7219MatrixLed02(spiChannelNumber);
}

void testMax7219MatrixLed01(uint8_t spiChannelNumber)
{
setupSpi051(spiChannelNumber);
max7219MatrixLed01(spiChannelNumber);
}

// ***************************************************************************
// Function - Test MAX7219 7-segment LED
// Date     - 2013nov06
// ***************************************************************************
/*
void testMax7219SegmentLed01(uint8_t spiChannelNumber)
{
setupSpi051(spiChannelNumber);
max7219SegmentLed01(spiChannelNumber);
}
*/

// ***************************************************************************
// Function - Test Max7219
// Call     - testMax7219v04(uint8_t spiChannelNumber)
// Date     - 2013oct30
// ***************************************************************************
void testMax7219v04(uint8_t spiChannelNumber)
{
max7219v04(spiChannelNumber);
}



// ***************************************************************************
// Function - Test HC595 based 7-segment LED
// Call     - testOlimex7segmentLed0101()
// Date     - 2013oct27
// ***************************************************************************
void testOlimex7segmentLed0101()
{
displayAllDigits050(OlimexBoardSevenSegmentLedPortPinArrayPointerArray1, MAX_OLIMEX_7_SEG_LED_PIN_NUMBER);
}

void testOlimex7segmentLed0102()
{
displayFourDigits050(OlimexBoardSevenSegmentLedPortPinArrayPointerArray1, MAX_OLIMEX_7_SEG_LED_PIN_NUMBER, 2, 0, 1, 3);
}

// ***************************************************************************
// End of tests - 2013oct27
// ***************************************************************************


void testMax7219Spi1()
{
// *** Blink LED at P03 ***
setupGpioPinOutputLow050(PortPinArrayP03); // setup GPIO pin as output
blinkLed0501(PortPinArrayP03); // blink led

// max7219v01();
max7219v02Spi1();
}

/*
void testMax7219()
{
// *** Blink LED at P03 ***
setupGpioPinOutputLow050(PortPinArrayP03); // setup GPIO pin as output
blinkLed0501(PortPinArrayP03); // blink led

// max7219v01();
max7219v02();
}
*/

/*
void testMcp3208Spi1() // 2013oct25
{
// *** Blink LED at P03 ***
setupGpioPinOutputLow050(PortPinArrayP03); // setup GPIO pin as output
blinkLed0501(PortPinArrayP03); // blink led

// *** Test MCP3028 ***
mcp3208v02Spi1();
}

void testSspLoopBack04()
{
sspLoopback04();
}

void testBlinkP03()
{
// *** Blink LED at P03 ***
setupGpioPinOutputLow050(PortPinArrayP03); // setup GPIO pin as output
blinkLed0501(PortPinArrayP03); // blink led
}

void testMcp320801() // 2013oct20
{
// *** Blink LED at P03 ***
setupGpioPinOutputLow050(PortPinArrayP03); // setup GPIO pin as output
blinkLed0501(PortPinArrayP03); // blink led

// *** Test MCP3028 ***
mcp320801();
}

void testSpi03() // 2013oct19
{
// *** Blink LED at P03 ***
setupGpioPinOutputLow050(PortPinArrayP03); // setup GPIO pin as output
blinkLed0501(PortPinArrayP03); // blink led

// *** Test SPI loopback ***
// loopBackSpi01();

loopBackSpi03();
}

void testWhutLedKey01() // tested OK 2013oct14
{
// *** For all mcu boards - setup GPIO pin as out and toggle ***
setupGpioPinOutputLow050(PortPinArrayP108); // setup LED1 pin
blinkLed0501(PortPinArrayP108); // blink LED1

// *** Whut only - setup I/O pins for testing ***
setupWhutGpio050(); // setup Olimex GPIO pins as output and input

// *** Whut only - blink single LED and run all LEDs***
blinkWhutLed(LED_1, ON_ONE_FIFTH_SECOND, OFF_ONE_FIFTH_SECOND, REPEAT_6_TIMES); // blink one Led
runWhutLeds();  // sequentially blink all 8 Leds

// *** Whut only - echo key by led ***
echoWhutKeyByLed(KEY_1, LED_1); // echo key by led
echoWhutKeyByLed(KEY_2, LED_2); // echo key by led
echoWhutKeyByLed(KEY_1, LED_3); // echo key by led

// *** For all mcu boards, given mcu board struct, echo key by led ***
echoKeyByLed0505(WhutLpc11c14DevBoardStruct, KEY_1, LED_2); // given mcuboard struct, echo key by led
}

void testWhutLedP108()
{
    // *** system self diagnostic test - blink LED P108 ***
setupGpioPinOutputLow050(PortPinArrayP108); // setup LED1 pin
blinkLed0501(PortPinArrayP108); // blink LED1
}

void testWhut7segmentLed01()
{
    // *** system self diagnostic test - blink LED P108 ***
setupGpioPinOutputLow050(PortPinArrayP108); // setup LED1 pin
blinkLed0501(PortPinArrayP108); // blink LED1

// *** Testing 7 segment LED ***
displayAllDigits050(WhutBoardSevenSegmentLedPortPinArrayPointerArray, MAX_WHUT_7_SEG_LED_PIN_NUMBER);
}



*/

// ***********************************************************************
// End
// ***********************************************************************

/*

// *** Old tests 2013nov08 ***

int main()
{
// *** Old tests ***
// testOlimexLedKey01();
// testWhutLedKey01();
// testOlimex7segmentLed01();
// testSpi03();
// testWhut7segmentLed01(); // OK 2013oct23
// testWhutLedP108(); // OK 2013oct23
// testOlimex7segmentLed0101();
// testOlimex7segmentLed0201();
// testBlinkP03()
// testMcp320801();

    // *** Olimex tests - 2013oct31hkt122 ***
// testBlinkOlimexLed1();
// testBlinkLpc1114LedP03();
// testOlimex7segmentLed0101();
// testMax7219v04(SPI_CHANNEL_0);
// testMcp3208(SPI_CHANNEL_1, ADC_CHANNEL_0);
// testMcp3208(SPI_CHANNEL_1, ADC_CHANNEL_1);
// testMcp3208(SPI_CHANNEL_1, ADC_CHANNEL_2);
// testMcp3208(SPI_CHANNEL_1, ADC_CHANNEL_3);
// testMcp3208(SPI_CHANNEL_1, ADC_CHANNEL_4);
// testMcp3208(SPI_CHANNEL_1, ADC_CHANNEL_5);
// testMcp3208(SPI_CHANNEL_1, ADC_CHANNEL_6);
// testMcp3208(SPI_CHANNEL_1, ADC_CHANNEL_7);

    // *** MagicBlue tests - 2013nov03hkt1054 ***
// testBlinkLpc1114LedP09(); // MOSI now for SPI0

testBlinkLpc1114LedP03();

testMcp3208(SPI_CHANNEL_0, ADC_CHANNEL_0);
testMcp3208(SPI_CHANNEL_0, ADC_CHANNEL_1);
testMcp3208(SPI_CHANNEL_0, ADC_CHANNEL_2);
testMcp3208(SPI_CHANNEL_0, ADC_CHANNEL_3);
testMcp3208(SPI_CHANNEL_0, ADC_CHANNEL_4);
testMcp3208(SPI_CHANNEL_0, ADC_CHANNEL_5);
testMcp3208(SPI_CHANNEL_0, ADC_CHANNEL_6);
testMcp3208(SPI_CHANNEL_0, ADC_CHANNEL_7);
testMcp3208(SPI_CHANNEL_0, ADC_CHANNEL_0);



testMcp3208(SPI_CHANNEL_1, ADC_CHANNEL_0);
testMcp3208(SPI_CHANNEL_1, ADC_CHANNEL_1);
testMcp3208(SPI_CHANNEL_1, ADC_CHANNEL_2);
testMcp3208(SPI_CHANNEL_1, ADC_CHANNEL_3);
testMcp3208(SPI_CHANNEL_1, ADC_CHANNEL_4);
testMcp3208(SPI_CHANNEL_1, ADC_CHANNEL_5);
testMcp3208(SPI_CHANNEL_1, ADC_CHANNEL_6);
testMcp3208(SPI_CHANNEL_1, ADC_CHANNEL_7);


// testMax7219v04(SPI_CHANNEL_1);
// testMcp3208(SPI_CHANNEL_1, ADC_CHANNEL_0);
// testMcp25Lc256(SPI_CHANNEL_1);

// testMax7219v04(SPI_CHANNEL_1);
// testMax7219v04(SPI_CHANNEL_0);

//testMax7219SegmentLed01(SPI_CHANNEL_0);

testMax7219SegmentLed01(SPI_CHANNEL_0);

// testMax7219MatrixLed01(SPI_CHANNEL_1);
// testMax7219MatrixLed02(SPI_CHANNEL_1);
// testMax7219MatrixLed03(SPI_CHANNEL_1);

testMax7219MatrixLed04(SPI_CHANNEL_1);

    return 0;
}

*/



// ***********************************************************************
// mled080.h 2013nov29hkt0954
// ***********************************************************************

#include "ledcode080.h"

// *** MAX7219 Register Addresses ***
#define NO_OP_ADDR 0x00
#define DIGIT_ADDR_0 0x01
#define DIGIT_ADDR_1 0x02
#define DIGIT_ADDR_2 0x03
#define DIGIT_ADDR_3 0x04
#define DIGIT_ADDR_4 0x05
#define DIGIT_ADDR_5 0x06
#define DIGIT_ADDR_6 0x07
#define DIGIT_ADDR_7 0x08
#define DECODE_MODE_ADDR 0x09
#define INTENSITY_ADDR     0x0a
#define SCAN_LIMIT_ADDR 0x0b
#define OPERATION_ADDR   0x0c // Shutdown address actually
#define DISPLAY_TEST_ADDR   0x0f

// *** MAX7219 Commands ***
#define SHUT_DOWN              0x00
#define NORMAL                 0x01
#define CODE_B_ALL_DIGITS      0xff
#define NO_DECODE_ALL_DIGITS   0x00
#define DECODE_ALL_8_DIGITS    0xff
#define NO_DECODE_ALL_8_DIGITS 0x00
#define NO_DECODE_ALL_8_ROWS   0x00
#define DISPLAY_8_DIGITS       0x07
#define SCAN_ALL_8_DIGITS      0x07
#define SCAN_ALL_8_ROWS        0x07

// *** Data Constants ***

#define MATRIX_0 0
#define MATRIX_1 1
#define MATRIX_2 2
#define MATRIX_3 3
#define MATRIX_4 4
#define MATRIX_5 5
#define MATRIX_6 6

#define DIGIT_0 0
#define DIGIT_1 1
#define DIGIT_2 2
#define DIGIT_3 3
#define DIGIT_4 4
#define DIGIT_5 5
#define DIGIT_6 6
#define DIGIT_7 7
#define DIGIT_8 8
#define DIGIT_9 9
#define CHAR_HYPHEN 10
#define CHAR_E 11
#define CHAR_H 12
#define CHAR_L 13
#define CHAR_P 14
#define CHAR_BLANK 15

#define PATTERN_ALL_ON 0xff
#define PATTERN_ALL_OFF 0x00

#define ADDRESS_INDEX 0
#define DATA_INDEX 1

#define MAX_MATRIX_NUMBER 16
#define MAX_BUFFER_SIZE 32

// *** SPI transmit ***
/*
void spiTransmit0901(uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
            portPinArrayPointerArray *slaveSelectPortPinArraryPointerArray[], \
                     SSP_DATA_SETUP_Type xferConfig)
{
setGpioDataPinLow01(slaveSelectPortPinArraryPointerArray[slaveSelectNumber]);
if (spiChannelNumber == 0)
SSP_ReadWrite(LPC_SSP0, &xferConfig, SSP_TRANSFER_POLLING);
else // (spiChannelNumber == 1)
SSP_ReadWrite(LPC_SSP1, &xferConfig, SSP_TRANSFER_POLLING);
    setGpioDataPinHigh01(slaveSelectPortPinArraryPointerArray[slaveSelectNumber]);
}
*/

/*
typedef slaveSelectPortPinArray *slaveSelectPortPinArrayPointerArray[SPI_SLAVE_SELECT_TOTAL];
typedef slaveSelectPortPinArrayPointerArray *slaveSelectPortPinArrayPointerArrayPointerArray[SPI_CHANNEL_TOTAL];

slaveSelectPortPinArray SlaveSelectPortPinArray00 = {PORT0, PIN2};
slaveSelectPortPinArray SlaveSelectPortPinArray01 = {PORT3, PIN0};
slaveSelectPortPinArray SlaveSelectPortPinArray02 = {PORT3, PIN1};
slaveSelectPortPinArray SlaveSelectPortPinArray03 = {PORT3, PIN2};
slaveSelectPortPinArray SlaveSelectPortPinArray04 = {PORT3, PIN3};
slaveSelectPortPinArray SlaveSelectPortPinArray05 = {PORT2, PIN6};
slaveSelectPortPinArray SlaveSelectPortPinArray06 = {PORT2, PIN7};
slaveSelectPortPinArray SlaveSelectPortPinArray07 = {PORT2, PIN8};
slaveSelectPortPinArray SlaveSelectPortPinArray08 = {PORT2, PIN9};

slaveSelectPortPinArray SlaveSelectPortPinArray10 = {PORT2, PIN0};
slaveSelectPortPinArray SlaveSelectPortPinArray11 = {PORT3, PIN0};
slaveSelectPortPinArray SlaveSelectPortPinArray12 = {PORT3, PIN1};
slaveSelectPortPinArray SlaveSelectPortPinArray13 = {PORT3, PIN2};
slaveSelectPortPinArray SlaveSelectPortPinArray14 = {PORT3, PIN3};
slaveSelectPortPinArray SlaveSelectPortPinArray15 = {PORT2, PIN6};
slaveSelectPortPinArray SlaveSelectPortPinArray16 = {PORT2, PIN7};
slaveSelectPortPinArray SlaveSelectPortPinArray17 = {PORT2, PIN8};
slaveSelectPortPinArray SlaveSelectPortPinArray18 = {PORT2, PIN9};

slaveSelectPortPinArrayPointerArray WuyinsSlaveSelectPortPinArrayPointerArraySp0V095[SPI_SLAVE_SELECT_TOTAL] = \
{&SlaveSelectPortPinArray00, &SlaveSelectPortPinArray01, &SlaveSelectPortPinArray02, \
    &SlaveSelectPortPinArray03, &SlaveSelectPortPinArray04, &SlaveSelectPortPinArray05, \
    &SlaveSelectPortPinArray06, &SlaveSelectPortPinArray07, &SlaveSelectPortPinArray08};

slaveSelectPortPinArrayPointerArray WuyinsSlaveSelectPortPinArrayPointerArraySp1V095[SPI_SLAVE_SELECT_TOTAL] = \
{&SlaveSelectPortPinArray10, &SlaveSelectPortPinArray11, &SlaveSelectPortPinArray12, \
    &SlaveSelectPortPinArray13, &SlaveSelectPortPinArray14, &SlaveSelectPortPinArray15, \
    &SlaveSelectPortPinArray16, &SlaveSelectPortPinArray17, &SlaveSelectPortPinArray18};

slaveSelectPortPinArrayPointerArrayPointerArray \
        WuyinsSlaveSelectPortPinArrayPointerArrayPointerArrayV095[SPI_CHANNEL_TOTAL] = \
{&WuyinsSlaveSelectPortPinArrayPointerArraySp0V095, \
    &WuyinsSlaveSelectPortPinArrayPointerArraySp1V095};
*/

// ***************************************************************************
// MAx7219 Functions
// ***************************************************************************

// *** Write Max7219 command ***
void writeMax7219CommandV0901(uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
                     portPinArray *spiSselPortPinArrayPointerArray[], \
                              uint8_t commandRegisterAddress, uint8_t command)
{
uint8_t txBuffer[2];
uint8_t rxBuffer[2];

SSP_DATA_SETUP_Type xferConfig;
    xferConfig.tx_data = txBuffer;
    xferConfig.rx_data = rxBuffer;
    xferConfig.length =  2;

    txBuffer[ADDRESS_INDEX] = commandRegisterAddress;
txBuffer[DATA_INDEX] = command;

    spiTransmit0901(spiChannelNumber, slaveSelectNumber, spiSselPortPinArrayPointerArray, xferConfig);
}

// *** Setup Max7219 ***
void setupMax7219DigitModeV0909(uint8_t spiChannelNumber, uint8_t slaveSelectNumber)
{
printf("\nSlave select port pin = %d,%d\n\n", \
((*WuyinsSlaveSelectPortPinArrayPointerArrayPointerArrayV095[spiChannelNumber])[slaveSelectNumber])[PORT_INDEX], \
((*WuyinsSlaveSelectPortPinArrayPointerArrayPointerArrayV095[spiChannelNumber])[slaveSelectNumber])[PIN_INDEX]);

setupMax7219DigitModeV0901(spiChannelNumber, slaveSelectNumber, \
                  (*WuyinsSlaveSelectPortPinArrayPointerArrayPointerArrayV095[spiChannelNumber])[slaveSelectNumber]);
}

void setupMax7219DigitModeV0901(uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
                       portPinArray *spiSselPortPinArrayPointerArray[])
{

writeMax7219CommandV0901(spiChannelNumber, slaveSelectNumber, spiSselPortPinArrayPointerArray,\
                OPERATION_ADDR, SHUT_DOWN);
writeMax7219CommandV0901(spiChannelNumber, slaveSelectNumber, spiSselPortPinArrayPointerArray,\
                DECODE_MODE_ADDR, DECODE_ALL_8_DIGITS);
writeMax7219CommandV0901(spiChannelNumber, slaveSelectNumber, spiSselPortPinArrayPointerArray,\
                SCAN_LIMIT_ADDR, SCAN_ALL_8_DIGITS);
writeMax7219CommandV0901(spiChannelNumber, slaveSelectNumber, spiSselPortPinArrayPointerArray,\
                OPERATION_ADDR, NORMAL);
}

void Max7219DisplayEightDigitV0909(uint8_t spiChannelNumber,  uint8_t slaveSelectNumber, \
                                   uint8_t digit0, uint8_t digit1, uint8_t digit2, \
                      uint8_t digit3, uint8_t digit4, uint8_t digit5, \
                      uint8_t digit6, uint8_t digit7, \
                      uint8_t debugMode)
{
displayMax7219EightDigitV091(spiChannelNumber, slaveSelectNumber, \
             (*WuyinsSlaveSelectPortPinArrayPointerArrayPointerArrayV095[SPI_CHANNEL_0])[slaveSelectNumber], \
                    digit0, digit1, digit2, digit3, \
                digit4, digit5, digit6, digit7);
}

void displayMax7219EightDigitV091(uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
                                  portPinArray *spiSselPortPinArrayPointerArray[], \
                         uint8_t digit1, uint8_t digit2, uint8_t digit3, \
                                  uint8_t digit4, uint8_t digit5, uint8_t digit6, \
                                  uint8_t digit7, uint8_t digit8)
{
shutDownMax7219V0901(spiChannelNumber, slaveSelectNumber, spiSselPortPinArrayPointerArray);

displayMax7219OneDigitV0901(spiChannelNumber, slaveSelectNumber, spiSselPortPinArrayPointerArray, DIGIT_ADDR_7, digit1);
displayMax7219OneDigitV0901(spiChannelNumber, slaveSelectNumber, spiSselPortPinArrayPointerArray, DIGIT_ADDR_6, digit2);
displayMax7219OneDigitV0901(spiChannelNumber, slaveSelectNumber, spiSselPortPinArrayPointerArray, DIGIT_ADDR_5, digit3);
displayMax7219OneDigitV0901(spiChannelNumber, slaveSelectNumber, spiSselPortPinArrayPointerArray, DIGIT_ADDR_4, digit4);
displayMax7219OneDigitV0901(spiChannelNumber, slaveSelectNumber, spiSselPortPinArrayPointerArray, DIGIT_ADDR_3, digit5);
displayMax7219OneDigitV0901(spiChannelNumber, slaveSelectNumber, spiSselPortPinArrayPointerArray, DIGIT_ADDR_2, digit6);
displayMax7219OneDigitV0901(spiChannelNumber, slaveSelectNumber, spiSselPortPinArrayPointerArray, DIGIT_ADDR_1, digit7);
displayMax7219OneDigitV0901(spiChannelNumber, slaveSelectNumber, spiSselPortPinArrayPointerArray, DIGIT_ADDR_0, digit8);

startUpMax7219V0901(spiChannelNumber, slaveSelectNumber, spiSselPortPinArrayPointerArray);
}

void shutDownMax7219V0901(uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
                          portPinArray *spiSselPortPinArrayPointerArray[])
{
writeMax7219CommandV0901(spiChannelNumber, slaveSelectNumber, spiSselPortPinArrayPointerArray, \
                OPERATION_ADDR, SHUT_DOWN);
}

void startUpMax7219V0901(uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
                         portPinArray *spiSselPortPinArrayPointerArray[])
{
writeMax7219CommandV0901(spiChannelNumber, slaveSelectNumber, spiSselPortPinArrayPointerArray, \
                OPERATION_ADDR, NORMAL);
}

void displayMax7219OneDigitV0901(uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
                                 portPinArray *spiSselPortPinArrayPointerArray[], \
                        uint8_t digitAddress, uint8_t digitData)
{
writeMax7219CommandV0901(spiChannelNumber, slaveSelectNumber, spiSselPortPinArrayPointerArray, \
                digitAddress, digitData);
}

void Max7219DisplayEightDigitV0903(uint8_t spiChannelNumber,  uint8_t slaveSelectNumber, \
                          portPinArray *spiSselPortPinArrayPointerArray[], \
                                   uint8_t digit0, uint8_t digit1, uint8_t digit2, \
                      uint8_t digit3, uint8_t digit4, uint8_t digit5, \
                      uint8_t digit6, uint8_t digit7, \
                      uint8_t debugMode)
{
// *** Set up SPI channels SPI0, SPI1 ***
// printf("\n*** Set up SPI channels SPI0, SPI1 ***\n\n");
setupAllSpiChannelV090();

// *** Set up all slave select ports of SPI channel ***
// printf("\n*** Set up Slave Select ports ***\n\n");
setupAllSlaveSelectPortV090(spiSselPortPinArrayPointerArray);

// *** Set up slave selected Max7219 digit mode ***
printf("\n*** Set up Max7219 digit mode ***\n\n");
setupMax7219DigitModeV0901(spiChannelNumber, slaveSelectNumber,
                            spiSselPortPinArrayPointerArray);

// setupMax7219DigitModeV0909(spiChannelNumber, slaveSelectNumber); // bad!!!

// *** Display 8 digits ***
// printf("\n*** Display Max7912 8 digits ***\n\n");
displayMax7219EightDigitV091(spiChannelNumber, slaveSelectNumber, \
                    spiSselPortPinArrayPointerArray, \
                digit0, digit1, digit2, digit3, \
                digit4, digit5, digit6, digit7);

// *** For debugging ***
if (debugMode == 1)
{
uint8_t i;
for (i = 0; i < 40000; i++)
{
displayMax7219EightDigitV091(spiChannelNumber, slaveSelectNumber, \
                    spiSselPortPinArrayPointerArray, \
                digit0, digit1, digit2, digit3, \
                digit4, digit5, digit6, digit7);
}
}
}


// ***************************************************************************
// End
// ***************************************************************************



void Max7219DisplayEightDigitV09039(uint8_t spiChannelNumber,  uint8_t slaveSelectNumber, \
                          portPinArray *spiSselPortPinArrayPointerArray[], \
                                   uint8_t digit0, uint8_t digit1, uint8_t digit2, \
                      uint8_t digit3, uint8_t digit4, uint8_t digit5, \
                      uint8_t digit6, uint8_t digit7, \
                      uint8_t debugMode)
{
// *** Set up SPI channels SPI0, SPI1 ***
// printf("\n*** Set up SPI channels SPI0, SPI1 ***\n\n");
// setupAllSpiChannelV090();

// *** Set up all slave select ports of SPI channel ***
// printf("\n*** Set up Slave Select ports ***\n\n");
// setupAllSlaveSelectPortV090(spiSselPortPinArrayPointerArray);

// *** Set up slave selected Max7219 digit mode ***
// printf("\n*** Set up Max7219 digit mode ***\n\n");
setupMax7219DigitModeV0901(spiChannelNumber, slaveSelectNumber, \
                            spiSselPortPinArrayPointerArray);

// *** Display 8 digits ***
// printf("\n*** Display Max7912 8 digits ***\n\n");
displayMax7219EightDigitV091(spiChannelNumber, slaveSelectNumber, \
                    spiSselPortPinArrayPointerArray, \
                digit0, digit1, digit2, digit3, \
                digit4, digit5, digit6, digit7);

// *** For debugging ***
if (debugMode == 1)
{
uint8_t i;
for (i = 0; i < 40000; i++)
{
displayMax7219EightDigitV091(spiChannelNumber, slaveSelectNumber, \
                    spiSselPortPinArrayPointerArray, \
                digit0, digit1, digit2, digit3, \
                digit4, digit5, digit6, digit7);
}
}
}



void Max7219DisplayEightDigitV0906(uint8_t spiChannelNumber,  uint8_t slaveSelectNumber, \
                                   uint8_t digit0, uint8_t digit1, uint8_t digit2, \
                      uint8_t digit3, uint8_t digit4, uint8_t digit5, \
                      uint8_t digit6, uint8_t digit7, \
                      uint8_t debugMode)
{
// *** Display 8 digits ***
// printf("\n*** Display Max7219 8 digits ***\n\n");
displayMax7219EightDigitV091(spiChannelNumber, slaveSelectNumber, \
                    *WuyinsSlaveSelectPortPinArrayPointerArrayPointerArrayV095[spiChannelNumber], \
                    digit0, digit1, digit2, digit3, \
                digit4, digit5, digit6, digit7);
}

void Max7219DisplayEightDigitV0905(uint8_t spiChannelNumber,  uint8_t slaveSelectNumber, \
                                   uint8_t digit0, uint8_t digit1, uint8_t digit2, \
                      uint8_t digit3, uint8_t digit4, uint8_t digit5, \
                      uint8_t digit6, uint8_t digit7, \
                      uint8_t debugMode)
{
slaveSelectPortPinArrayPointerArray *slaveSelectPortPinArrayPointerArrayPointer;
slaveSelectPortPinArrayPointerArrayPointer = WuyinsSlaveSelectPortPinArrayPointerArrayPointerArrayV095[SPI_CHANNEL_0];

// *** Set up slave selected Max7219 digit mode ***
// printf("\n*** Set up Max7219 digit mode ***\n\n");
setupMax7219DigitModeV0901(spiChannelNumber, slaveSelectNumber, \
                  // WuyinsSlaveSelectPortPinArrayPointerArraySp0V095);
                               (*WuyinsSlaveSelectPortPinArrayPointerArrayPointerArrayV095[SPI_CHANNEL_0])[slaveSelectNumber]);
                  // *slaveSelectPortPinArrayPointerArrayPointer);

// *** Display 8 digits ***
// printf("\n*** Display Max7219 8 digits ***\n\n");
displayMax7219EightDigitV091(spiChannelNumber, slaveSelectNumber, \
             (*WuyinsSlaveSelectPortPinArrayPointerArrayPointerArrayV095[SPI_CHANNEL_0])[slaveSelectNumber], \
                    digit0, digit1, digit2, digit3, \
                digit4, digit5, digit6, digit7);
}

void Max7219DisplayEightDigitV0905x(uint8_t spiChannelNumber,  uint8_t slaveSelectNumber, \
                                   uint8_t digit0, uint8_t digit1, uint8_t digit2, \
                      uint8_t digit3, uint8_t digit4, uint8_t digit5, \
                      uint8_t digit6, uint8_t digit7, \
                      uint8_t debugMode)
{
// *** Set up slave selected Max7219 digit mode ***
// printf("\n*** Set up Max7219 digit mode ***\n\n");
setupMax7219DigitModeV0901(spiChannelNumber, slaveSelectNumber, \
                  // WuyinsSlaveSelectPortPinArrayPointerArraySp0V095);
                  *WuyinsSlaveSelectPortPinArrayPointerArrayPointerArrayV095[SPI_CHANNEL_0]);

// *** Display 8 digits ***
// printf("\n*** Display Max7219 8 digits ***\n\n");
displayMax7219EightDigitV091(spiChannelNumber, slaveSelectNumber, \
                    *WuyinsSlaveSelectPortPinArrayPointerArrayPointerArrayV095[SPI_CHANNEL_0], \
                    digit0, digit1, digit2, digit3, \
                digit4, digit5, digit6, digit7);
}


/*
slaveSelectPortPinArrayPointerArray *slaveSelectPortPinArrayPointerArrayPointer;

slaveSelectPortPinArrayPointerArrayPointer = WuyinsSlaveSelectPortPinArrayPointerArrayPointerArrayV095[spiChannelNumber];

//slaveSelectPortPinArrayPointerArray WuyinsSlaveSelectPortPinArrayPointerArraySp0V095[SPI_SLAVE_SELECT_TOTAL] = \
// {&SlaveSelectPortPinArray00, &SlaveSelectPortPinArray01, &SlaveSelectPortPinArray02, \
 //   &SlaveSelectPortPinArray03, &SlaveSelectPortPinArray04, &SlaveSelectPortPinArray05, \
   // &SlaveSelectPortPinArray06, &SlaveSelectPortPinArray07, &SlaveSelectPortPinArray08};

//void setupMax7219DigitModeV0901(uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
//                        portPinArray *spiSselPortPinArrayPointerArray[])
*/

void Max7219DisplayEightDigitV0904(uint8_t spiChannelNumber,  uint8_t slaveSelectNumber, \
                          portPinArray *spiSselPortPinArrayPointerArray[], \
                                   uint8_t digit0, uint8_t digit1, uint8_t digit2, \
                      uint8_t digit3, uint8_t digit4, uint8_t digit5, \
                      uint8_t digit6, uint8_t digit7, \
                      uint8_t debugMode)
{
// *** Set up SPI channels SPI0, SPI1 ***
// printf("\n*** Set up SPI channels SPI0, SPI1 ***\n\n");
setupAllSpiChannelV090();

// *** Set up all slave select ports of SPI channel ***
// printf("\n*** Set up Slave Select ports ***\n\n");
setupAllSlaveSelectPortV090(spiSselPortPinArrayPointerArray);

// *** Set up slave selected Max7219 digit mode ***
// printf("\n*** Set up Max7219 digit mode ***\n\n");
setupMax7219DigitModeV0901(spiChannelNumber, slaveSelectNumber, \
                               spiSselPortPinArrayPointerArray);

// *** Display 8 digits ***
// printf("\n*** Display Max7912 8 digits ***\n\n");
displayMax7219EightDigitV091(spiChannelNumber, slaveSelectNumber, \
                    spiSselPortPinArrayPointerArray, \
                digit0, digit1, digit2, digit3, \
                digit4, digit5, digit6, digit7);

// *** For debugging ***
if (debugMode == 1)
{
uint8_t i;
for (i = 0; i < 40000; i++)
{
displayMax7219EightDigitV091(spiChannelNumber, slaveSelectNumber, \
                    spiSselPortPinArrayPointerArray, \
                digit0, digit1, digit2, digit3, \
                digit4, digit5, digit6, digit7);
}
}
}




// ***************************************************************************
// End
// ***************************************************************************


void setupAndDisplayMax7219EightDigitsV091(portPinArray *spiSselPortPinArrayPointerArray[],\
                       uint8_t slaveSelectNumber, \
                                uint8_t digit1, uint8_t digit2, uint8_t digit3, uint8_t digit4, \
                                uint8_t digit5, uint8_t digit6, uint8_t digit7, uint8_t digit8)
{
setupMax7219DigitModeV091(spiSselPortPinArrayPointerArray, slaveSelectNumber);

    displayMax7219EightDigitsV091(spiSselPortPinArrayPointerArray, slaveSelectNumber, \
               digit1, digit2, \
               digit3, digit4, digit5, digit6, digit7, digit8);
}

void displayMax7219EightDigitV090(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
                     uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
                     uint8_t digit1, uint8_t digit2, uint8_t digit3, uint8_t digit4, \
                     uint8_t digit5, uint8_t digit6, uint8_t digit7, uint8_t digit8)
{
// *** Set up all SPI channels and SPI slave select ports ***
setupAllSpiChannelsAndSlaveSelectPorts(portPinArraryPointerArrayArray);

    // *** Display 8 digits ***
// printf("\n\n*** test Max7219 - 2013nov22 ***\n\n");
setupAndDisplayMax7219EightDigitsV080(portPinArraryPointerArrayArray, \
                        spiChannelNumber, slaveSelectNumber, \
                                     digit1, digit2, digit3, digit4, \
                                     digit5, digit6, digit7, digit8);
// printf("\n*** End of test ***\n");
}

void setupAndDisplayMax7219EightDigitsV080(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
                       uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
                                uint8_t digit1, uint8_t digit2, uint8_t digit3, uint8_t digit4, \
                                uint8_t digit5, uint8_t digit6, uint8_t digit7, uint8_t digit8)
{
setupMax7219DigitModeV080(portPinArraryPointerArrayArray, \
                 spiChannelNumber, slaveSelectNumber);

    displayMax7219EightDigitsV080(portPinArraryPointerArrayArray, \
    spiChannelNumber, slaveSelectNumber, MATRIX_1, digit1, digit2, \
               digit3, digit4, digit5, digit6, digit7, digit8);
}

void setupMax7219DigitModeV080(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber)
{
writeMax7219CommandV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, OPERATION_ADDR, SHUT_DOWN);
writeMax7219CommandV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, DECODE_MODE_ADDR, DECODE_ALL_8_DIGITS);
writeMax7219CommandV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, SCAN_LIMIT_ADDR, SCAN_ALL_8_DIGITS);
}

void setupMax7219PositionDigitModeV080(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber, uint8_t positionNumber)
{
writeMax7219PositionCommandV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, OPERATION_ADDR, SHUT_DOWN, positionNumber);
writeMax7219PositionCommandV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, DECODE_MODE_ADDR, DECODE_ALL_8_DIGITS, positionNumber);
writeMax7219PositionCommandV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, SCAN_LIMIT_ADDR, SCAN_ALL_8_DIGITS, positionNumber);
}

void displayMax7219EightDigitsV080(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber, uint8_t ledDriverNumber, \
           uint8_t digit1, uint8_t digit2, uint8_t digit3, uint8_t digit4, \
           uint8_t digit5, uint8_t digit6, uint8_t digit7, uint8_t digit8)
{
shutDownMax7219V080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, ledDriverNumber);
displayMax7219OneDigitV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, ledDriverNumber, DIGIT_ADDR_7, digit1);
displayMax7219OneDigitV080(portPinArraryPointerArrayArray, \
    spiChannelNumber, slaveSelectNumber, ledDriverNumber, DIGIT_ADDR_6, digit2);
displayMax7219OneDigitV080(portPinArraryPointerArrayArray, \
    spiChannelNumber, slaveSelectNumber, ledDriverNumber, DIGIT_ADDR_5, digit3);
displayMax7219OneDigitV080(portPinArraryPointerArrayArray, \
    spiChannelNumber, slaveSelectNumber, ledDriverNumber, DIGIT_ADDR_4, digit4);
displayMax7219OneDigitV080(portPinArraryPointerArrayArray, \
    spiChannelNumber, slaveSelectNumber, ledDriverNumber, DIGIT_ADDR_3, digit5);
displayMax7219OneDigitV080(portPinArraryPointerArrayArray, \
    spiChannelNumber, slaveSelectNumber, ledDriverNumber, DIGIT_ADDR_2, digit6);
displayMax7219OneDigitV080(portPinArraryPointerArrayArray, \
    spiChannelNumber, slaveSelectNumber, ledDriverNumber, DIGIT_ADDR_1, digit7);
displayMax7219OneDigitV080(portPinArraryPointerArrayArray, \
    spiChannelNumber, slaveSelectNumber, ledDriverNumber, DIGIT_ADDR_0, digit8);
    startUpMax7219V080(portPinArraryPointerArrayArray, \
    spiChannelNumber, slaveSelectNumber, ledDriverNumber);
}

void displayMax7219OneDigitV080(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
               uint8_t deviceNumber, uint8_t digitAddress, uint8_t digitData)
{
writeMax7219CommandV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, digitAddress, digitData);
}

void writeMax7219CommandV080(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
                    uint8_t commandRegisterAddress, uint8_t command)
{
uint8_t txBuffer[2];
uint8_t rxBuffer[2];

SSP_DATA_SETUP_Type xferConfig;
    xferConfig.tx_data = txBuffer;
    xferConfig.rx_data = rxBuffer;
    xferConfig.length =  2;

    txBuffer[ADDRESS_INDEX] = commandRegisterAddress;
txBuffer[DATA_INDEX] = command;

    spiTransmit082(portPinArraryPointerArrayArray, spiChannelNumber, slaveSelectNumber, xferConfig);
}

void writeMax7219CommandV0803(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
                     uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
                     uint8_t matrixNumber, \
                     uint8_t commandRegisterAddress, uint8_t command)
{
uint8_t txBuffer[MAX_BUFFER_SIZE];
uint8_t rxBuffer[MAX_BUFFER_SIZE];

SSP_DATA_SETUP_Type xferConfig;
    xferConfig.tx_data = txBuffer;
    xferConfig.rx_data = rxBuffer;
    xferConfig.length =  2 * (matrixNumber + 1);

    txBuffer[ADDRESS_INDEX] = commandRegisterAddress;
txBuffer[DATA_INDEX] = command;

int i;
for (i = 1; i < matrixNumber; i++)
{
   txBuffer[(i * 2) + ADDRESS_INDEX] = NO_OP_ADDR;
}

    spiTransmit082(portPinArraryPointerArrayArray, spiChannelNumber, slaveSelectNumber, xferConfig);
}

void shutDownMax7219V080(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber)
{
writeMax7219CommandV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, OPERATION_ADDR, SHUT_DOWN);
}

void startUpMax7219V080(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber)
{
writeMax7219CommandV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, OPERATION_ADDR, NORMAL);
}

void shutDownMax7219V0803(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber, uint8_t matrixNumber)
{
writeMax7219CommandV0803(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, matrixNumber, OPERATION_ADDR, SHUT_DOWN);
}

void startUpMax7219V0803(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber, uint8_t matrixNumber)
{
writeMax7219CommandV0803(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, matrixNumber, OPERATION_ADDR, NORMAL);
}

// *** Matrix mode ***********************************************************

void setupMax7219MatrixModeV080(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber)
{
writeMax7219CommandV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, OPERATION_ADDR, SHUT_DOWN);
writeMax7219CommandV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, DECODE_MODE_ADDR, NO_DECODE_ALL_DIGITS); // No decode
writeMax7219CommandV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, SCAN_LIMIT_ADDR, SCAN_ALL_8_DIGITS);
}

void setupMax7219MatrixModeV090(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber, uint8_t matrixNumber)
{
writeMax7219CommandV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, OPERATION_ADDR, SHUT_DOWN);
writeMax7219CommandV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, DECODE_MODE_ADDR, NO_DECODE_ALL_DIGITS); // No decode
writeMax7219CommandV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, SCAN_LIMIT_ADDR, SCAN_ALL_8_DIGITS);
}

void setupAndDisplayMax7219MatrixV080(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
                       uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
                                uint8_t matrixColumn[])
{
setupMax7219MatrixModeV080(portPinArraryPointerArrayArray, \
                 spiChannelNumber, slaveSelectNumber);

displayMax7219OneMatrix080(portPinArraryPointerArrayArray, \
                               spiChannelNumber, slaveSelectNumber, \
                  matrixColumn);
}

void displayMax7219OneMatrix0803(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
                       uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
                       uint8_t matrixNumber, uint8_t matrixColumn[])
{
shutDownMax7219V0803(portPinArraryPointerArrayArray, \
           spiChannelNumber, slaveSelectNumber, matrixNumber);

uint8_t columnNumber;
uint8_t digitAddress;

for (columnNumber = 0; columnNumber < 8; columnNumber++)
{
digitAddress = columnNumber + 1;
displayMax7219OneMatrixColumnV0803(portPinArraryPointerArrayArray, \
                  spiChannelNumber, slaveSelectNumber, \
                          matrixNumber, digitAddress,  matrixColumn[7 - columnNumber]);
}

startUpMax7219V0803(portPinArraryPointerArrayArray, \
           spiChannelNumber, slaveSelectNumber, matrixNumber);
}


void displayMax7219OneMatrixColumnV0803(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
               uint8_t matrixNumber, uint8_t digitAddress, uint8_t digitData)
{
writeMax7219CommandV0803(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, matrixNumber, digitAddress, digitData);
}


void displayMax7219OneMatrix080(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
                       uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
                       uint8_t matrixColumn[])
{
shutDownMax7219V080(portPinArraryPointerArrayArray, \
           spiChannelNumber, slaveSelectNumber);

uint8_t columnNumber;
uint8_t digitAddress;

for (columnNumber = 0; columnNumber < 8; columnNumber++)
{
digitAddress = columnNumber + 1;
displayMax7219OneDigitV080(portPinArraryPointerArrayArray, \
                  spiChannelNumber, slaveSelectNumber, \
                          0, digitAddress,  matrixColumn[7 - columnNumber]);
}

startUpMax7219V080(portPinArraryPointerArrayArray, \
           spiChannelNumber, slaveSelectNumber);
}

// ***************************************************************************
// Test functions
// ***************************************************************************
void testMax7219V0901()
{
// *** Set up all SPI channels and SPI slave select ports ***
setupAllSpiChannelsAndSlaveSelectPorts(Olimex20SlaveSelectPortPinArrayPointerArrayArray);

// *** Set up Max7219 digit mode for SPI 0,1, 0,2, 0,3, 0,4 ***
setupMax7219DigitModeV080(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                 SPI_CHANNEL_0, SLAVE_SELECT_0);
setupMax7219DigitModeV080(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                 SPI_CHANNEL_0, SLAVE_SELECT_1);
setupMax7219DigitModeV080(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                 SPI_CHANNEL_0, SLAVE_SELECT_2);
setupMax7219DigitModeV080(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                 SPI_CHANNEL_0, SLAVE_SELECT_3);
setupMax7219DigitModeV080(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                 SPI_CHANNEL_0, SLAVE_SELECT_4);

// *** Set up Max7219 matrix mode for SPI 0,5 Matrix #1 and Matrix #2 ***
setupMax7219MatrixModeV090(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                               SPI_CHANNEL_0, SLAVE_SELECT_5, MATRIX_0);
setupMax7219MatrixModeV090(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                               SPI_CHANNEL_0, SLAVE_SELECT_5, MATRIX_1);

// *** Display 8 digits for SPI 0,1 to 0,4 ***
displayMax7219EightDigitV090(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
   SPI_CHANNEL_0, SLAVE_SELECT_0, 2, 0, 1, 3, 1, 1, 2, 6);

displayMax7219EightDigitV090(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
   SPI_CHANNEL_0, SLAVE_SELECT_1, 3, 0, 0, 0, 0, 0, 0, 1);

displayMax7219EightDigitV090(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
   SPI_CHANNEL_0, SLAVE_SELECT_2, 3, 0, 0, 0, 0, 0, 0, 2);

displayMax7219EightDigitV090(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
   SPI_CHANNEL_0, SLAVE_SELECT_3, 3, 0, 0, 0, 0, 0, 0, 3);

displayMax7219EightDigitV090(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
   SPI_CHANNEL_0, SLAVE_SELECT_4, 3, 0, 0, 0, 0, 0, 0, 4);

// *** Display matrix for for SPI 0,5 Matrix #1 and #2 ***
displayMax7219OneMatrix0803(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                                SPI_CHANNEL_0, SLAVE_SELECT_5, \
                                MATRIX_0, MatrixChar_O);

displayMax7219OneMatrix0803(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                                SPI_CHANNEL_0, SLAVE_SELECT_5, \
                                MATRIX_1, MatrixChar_K);
delayMilliSecond(2000);

// *** Looping display ***
/*
while (1)
    {
displayMax7219OneMatrix0803(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                                SPI_CHANNEL_0, SLAVE_SELECT_5, \
                                MATRIX_0, MatrixChar_O);
delayMilliSecond(1000);

displayMax7219OneMatrix0803(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                                SPI_CHANNEL_0, SLAVE_SELECT_5, \
                                MATRIX_0, MatrixChar_K);
delayMilliSecond(1000);
    }
*/
}

void testMax7219V0902()
{
// *** Set up all SPI channels and SPI slave select ports ***
setupAllSpiChannelsAndSlaveSelectPorts(Olimex20SlaveSelectPortPinArrayPointerArrayArray);

// *** Set up Max7219 digit mode for SPI 0,0 ***
setupMax7219DigitModeV080(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                 SPI_CHANNEL_0, SLAVE_SELECT_0);

// *** Set up Max7219 matrix mode for SPI 0,1 Matrix #1 and Matrix #2 ***
setupMax7219MatrixModeV090(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                               SPI_CHANNEL_0, SLAVE_SELECT_1, MATRIX_0);
setupMax7219MatrixModeV090(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                               SPI_CHANNEL_0, SLAVE_SELECT_1, MATRIX_1);

// *** Display 8 digits for SPI 0,0 ***
displayMax7219EightDigitV090(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
   SPI_CHANNEL_0, SLAVE_SELECT_0, 0, 1, 2, 3, 4, 5, 6, 7);

// *** Display matrix for for SPI 0,1 Matrix #1 and #2 ***
displayMax7219OneMatrix0803(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                                SPI_CHANNEL_0, SLAVE_SELECT_1, \
                                MATRIX_0, MatrixChar_O);

displayMax7219OneMatrix0803(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                                SPI_CHANNEL_0, SLAVE_SELECT_1, \
                                MATRIX_1, MatrixChar_K);
}

// ***********************************************************************
// Function    - testMax7219V0903()
// Description - Display "O", "K" at MAX7219s at SPI 0,0 and 0,1
// Date        - 2013nov27hkt1300
// Notes       - 1. Set up 2 SPI channels and 6 Slave Select ports
//               2. Set up SPI 0,0 MATRIX0 and MATRIX1 for matrix mode
//               3. Display "O" at MATIX0 and "K" at MATRIX1
// ***********************************************************************
void testMax7219V0903()
{
// *** Set up all SPI channels and SPI slave select ports ***
setupAllSpiChannelsAndSlaveSelectPorts(Olimex20SlaveSelectPortPinArrayPointerArrayArray);

// *** Set up Max7219 matrix mode for SPI 0,0 Matrix #1, 2, 3 ***
setupMax7219MatrixModeV090(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                               SPI_CHANNEL_0, SLAVE_SELECT_0, MATRIX_0);
setupMax7219MatrixModeV090(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                               SPI_CHANNEL_0, SLAVE_SELECT_0, MATRIX_1);
setupMax7219MatrixModeV090(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                               SPI_CHANNEL_0, SLAVE_SELECT_0, MATRIX_2);
setupMax7219MatrixModeV090(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                               SPI_CHANNEL_0, SLAVE_SELECT_0, MATRIX_3);
setupMax7219MatrixModeV090(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                               SPI_CHANNEL_0, SLAVE_SELECT_0, MATRIX_4);
setupMax7219MatrixModeV090(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                               SPI_CHANNEL_0, SLAVE_SELECT_0, MATRIX_5);

// delayMilliSecond(200);

// *** Display matrix for for SPI 0,1 Matrix #1 and #2 ***
displayMax7219OneMatrix0803(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                                SPI_CHANNEL_0, SLAVE_SELECT_0, \
//                                MATRIX_0, MatrixChar_Blank);
//                                MATRIX_0, MatrixChar_Test);
                                  MATRIX_0, MatrixChar_H);
displayMax7219OneMatrix0803(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                                SPI_CHANNEL_0, SLAVE_SELECT_0, \
                                MATRIX_1, MatrixChar_K);
displayMax7219OneMatrix0803(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                                SPI_CHANNEL_0, SLAVE_SELECT_0, \
                                MATRIX_2, MatrixChar_G);
displayMax7219OneMatrix0803(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                                SPI_CHANNEL_0, SLAVE_SELECT_0, \
                                MATRIX_3, MatrixChar_S);
displayMax7219OneMatrix0803(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                                SPI_CHANNEL_0, SLAVE_SELECT_0, \
                                MATRIX_4, MatrixChar_S);
displayMax7219OneMatrix0803(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                                SPI_CHANNEL_0, SLAVE_SELECT_0, \
                                MATRIX_5, MatrixChar_P);
}

// ***********************************************************************
// Function    - testMax7219V0904()
// ***********************************************************************
void testMax7219V0904()
{
// *** Set up all SPI channels and SPI slave select ports ***
setupAllSpiChannelsAndSlaveSelectPorts(Olimex20SlaveSelectPortPinArrayPointerArrayArray);

// *** Set up Max7219 digit mode for SPI 1,0 ***
setupMax7219DigitModeV080(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                 SPI_CHANNEL_0, SLAVE_SELECT_0);

// *** Display 8 digits for SPI 1,0 ***
displayMax7219EightDigitV090(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
   SPI_CHANNEL_0, SLAVE_SELECT_0, 0, 1, 2, 3, 4, 5, 6, 7);

// *** For debugging ***
uint8_t i;
for (i = 0; i < 40000; i++)
{
displayMax7219EightDigitV090(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
   SPI_CHANNEL_0, SLAVE_SELECT_0, 0, 1, 2, 3, 4, 5, 6, 7);
}
}

void testMax7219V0905()
{
// *** Set up all SPI channels and SPI slave select ports ***
setupAllSpiChannelsAndSlaveSelectPorts(Olimex20SlaveSelectPortPinArrayPointerArrayArray);

// *** Set up Max7219 digit mode for SPI 1,0 ***
setupMax7219DigitModeV080(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                 SPI_CHANNEL_1, SLAVE_SELECT_0);

// *** Display 8 digits for SPI 1,0 ***
displayMax7219EightDigitV090(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
   SPI_CHANNEL_1, SLAVE_SELECT_0, 0, 1, 2, 3, 4, 5, 6, 7);
}

/*
// *** For debugging ***
uint8_t i;
for (i = 0; i < 40000; i++)
{
displayMax7219EightDigitV090(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
   SPI_CHANNEL_1, SLAVE_SELECT_0, 0, 1, 2, 3, 4, 5, 6, 7);
}
*/

void testMax7219EightDigitV0907(uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
                 uint8_t digit0, uint8_t digit1, uint8_t digit2, uint8_t digit3, \
                 uint8_t digit4, uint8_t digit5, uint8_t digit6, uint8_t digit7, \
                 uint8_t debugMode)
{
// *** Set up all SPI channels and SPI slave select ports ***
setupAllSpiChannelsAndSlaveSelectPorts(Olimex20SlaveSelectPortPinArrayPointerArrayArray);

// *** Set up Max7219 digit mode ***
setupMax7219DigitModeV080(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                 spiChannelNumber, slaveSelectNumber);

// *** Display 8 digits ***
displayMax7219EightDigitV090(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
   spiChannelNumber, slaveSelectNumber, \
   digit0, digit1, digit2, digit3, \
   digit4, digit5, digit6, digit7);

// *** For debugging ***
if (debugMode == 1)
{
uint8_t i;
for (i = 0; i < 40000; i++)
{
displayMax7219EightDigitV090(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
   spiChannelNumber, slaveSelectNumber, \
   digit0, digit1, digit2, digit3, \
   digit4, digit5, digit6, digit7);
}
}
}



// ***************************************************************************
// End
// ***************************************************************************

No comments:

Post a Comment