2013-11-22

MAX7219 testig 4 drivers at the same time OK



































Now I am testing 4 MAX7219 at the same time.  Everything goes smoothly.


int main()
{
testMax7219v081(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
   SPI_CHANNEL_0, SLAVE_SELECT_0, \
   0, 0, 0, 0, 0, 0, 0, 0);

testMax7219v081(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
   SPI_CHANNEL_0, SLAVE_SELECT_1, \
   0, 0, 0, 0, 0, 0, 0, 1);

testMax7219v081(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
   SPI_CHANNEL_0, SLAVE_SELECT_2, \
   0, 0, 0, 0, 0, 0, 0, 2);

testMax7219v081(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
   SPI_CHANNEL_0, SLAVE_SELECT_3, \
   0, 0, 0, 0, 0, 0, 0, 3);
}



void testMax7219v081(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");
displayMcp7219Display8DigitsV080(portPinArraryPointerArrayArray, \
                        spiChannelNumber, slaveSelectNumber, \
                                     digit1, digit2, digit3, digit4, \
                                     digit5, digit6, digit7, digit8);
printf("\n*** End of test ***\n");

/*
// *** For debugging only ***
printf("\n\n*** Debugging only - repeat display every 10 mS ***\n");
uint8_t i;
for (i = 0; i < 200000; i++)
{
displayMcp7219Display8DigitsV080(portPinArraryPointerArrayArray, \
                        spiChannelNumber, slaveSelectNumber, \
                                    digit1, digit2, digit3, digit4, \
                                    digit5, digit6, digit7, digit8);
delayMilliSecond(10);
}
*/
}

// ***********************************************************************
// spi080.h 2013nov22hkt1141
// ***********************************************************************

#include "gpio050.h"
#include "led050.h"
#include "lpc11xx_ssp.h"
#include "semihosting.h"
#include "stdio.h"
#include "config050.h"

#ifndef SPI_HEADER_SEEN
#define SPI_HEADER_SEEN

// *** SPI #defines ***

#define MAX_SPI_CHANNEL_NUMBER 2
#define MAX_SPI_SLAVE_SELECT_NUMBER 7

#define SPI_CHANNEL_0 0
#define SPI_CHANNEL_1 1

#define SLAVE_SELECT_0 0
#define SLAVE_SELECT_1 1
#define SLAVE_SELECT_2 2
#define SLAVE_SELECT_3 3
#define SLAVE_SELECT_4 4
#define SLAVE_SELECT_5 5
#define SLAVE_SELECT_6 6

// *** SPI PortPinArray assignment ***

portPinArray PortPinArraySsel0  = {PORT0, PIN2};
portPinArray PortPinArraySsel1  = {PORT2, PIN0};

portPinArray PortPinArraySsel00 = {PORT0, PIN2};
portPinArray PortPinArraySsel01 = {PORT3, PIN0};
portPinArray PortPinArraySsel02 = {PORT3, PIN1};
portPinArray PortPinArraySsel03 = {PORT3, PIN2};
portPinArray PortPinArraySsel04 = {PORT3, PIN3};
portPinArray PortPinArraySsel05 = {PORT2, PIN6};
portPinArray PortPinArraySsel06 = {PORT2, PIN7};

portPinArray PortPinArraySsel10 = {PORT2, PIN0};
portPinArray PortPinArraySsel11 = {PORT3, PIN0};
portPinArray PortPinArraySsel12 = {PORT3, PIN1};
portPinArray PortPinArraySsel13 = {PORT3, PIN2};
portPinArray PortPinArraySsel14 = {PORT3, PIN3};
portPinArray PortPinArraySsel15 = {PORT2, PIN6};
portPinArray PortPinArraySsel16 = {PORT2, PIN7};

portPinArray *Olimex2SlaveSelectPortPinArrayPointerArray0[] = {&PortPinArraySsel00, \
    &PortPinArraySsel01, &PortPinArraySsel02, &PortPinArraySsel03, \
    &PortPinArraySsel04, &PortPinArraySsel05, &PortPinArraySsel06};

portPinArray *Olimex2SlaveSelectPortPinArrayPointerArray1[] = {&PortPinArraySsel10, \
    &PortPinArraySsel11, &PortPinArraySsel12, &PortPinArraySsel13, \
    &PortPinArraySsel14, &PortPinArraySsel15, &PortPinArraySsel16};

portPinArray *Olimex20SlaveSelectPortPinArrayPointerArrayArray[2][7] = \
     {&PortPinArraySsel00, &PortPinArraySsel01, &PortPinArraySsel02, \
          &PortPinArraySsel03, &PortPinArraySsel04, &PortPinArraySsel05, \
          &PortPinArraySsel06, \
          &PortPinArraySsel10, &PortPinArraySsel11, &PortPinArraySsel12, \
          &PortPinArraySsel13, &PortPinArraySsel14, &PortPinArraySsel15, \
          &PortPinArraySsel16};

portPinArray *Olimex21SlaveSelectPortPinArrayPointerArrayArray[2][7] = \
     {Olimex2SlaveSelectPortPinArrayPointerArray0, \
          Olimex2SlaveSelectPortPinArrayPointerArray1};

// ***************************************************************************
// SPI Functions
// ***************************************************************************

// ***************************************************************************
// Function - Setup SPI channels
// Date     - 2013nov20
// Notes    - 1. Port P06 selected as Slave Select default, BUT DISABLED!!!
//               Instead, P02 and P20 are the default SSEL00 and SSEL10.
//            2. There is a bug in lpc11xx_iocon.c v1.0, fixed here
//            3. SlaveSelect GPIO port is initialized to output High
// ***************************************************************************
void setupOneSpiChannel080(uint8_t spiChannelNumber)
{
// printf("\nSPI Channel number = %01d", spiChannelNumber);

if (spiChannelNumber == 0)
{
// Enable SSP0 block clock
SYSCON_AHBPeriphClockCmd(SYSCON_AHBPeriph_SSP0, ENABLE);

// Reset SSP0 and clock divider
SYSCON_PeriphResetCmd(SYSCON_RSTPeriph_SSP0, ENABLE);
SYSCON_PeriphResetCmd(SYSCON_RSTPeriph_SSP0, DISABLE);
SYSCON_SetSPI0ClockDiv(10);

// Assign GPIO pins for SPI
SSP_SSP0PinsInit(SCK0_PIO0_6, DISABLE); // Select P06, BUT disable

// Initialize SSP with default configuration (Master mode, 8 bit data)
SSP_CFG_Type SSP_ConfigStruct;
SSP_ConfigStructInit(&SSP_ConfigStruct);
SSP_Init(LPC_SSP0, &SSP_ConfigStruct);

// Enable SSP peripheral
SSP_Cmd(LPC_SSP0, ENABLE);
}
else // (if spiChannelNumber == 1)
{
// Enable SSP1 block clock
SYSCON_AHBPeriphClockCmd(SYSCON_AHBPeriph_SSP1, ENABLE);

// Reset SSP1 and clock divider
SYSCON_PeriphResetCmd(SYSCON_RSTPeriph_SSP1, ENABLE);
SYSCON_PeriphResetCmd(SYSCON_RSTPeriph_SSP1, DISABLE);
SYSCON_SetSPI1ClockDiv(10);

// No need to assign GPIO pins for SPI1, just disable
SSP_SSP1PinsInit(DISABLE); // disable SSEL

// Note: A bug!!! in Coocox lpc11xx_iocon.c v1.0 26Jan2010
// IOCON_SetPinFunc(IOCON_PIO2_2, PIO2_2_FUN_MISO1);
// IOCON_SetPinFunc(IOCON_PIO2_3, PIO2_3_FUN_PIO_MOSI1);
// IOCON_SetPinFunc(IOCON_PIO2_1, PIO2_1_FUN_SCK1);
// if(useSSEL == ENABLE) {
        //    IOCON_SetPinFunc(IOCON_PIO2_0, PIO2_0_FUN_SSEL1);

// Initialize SSP with default configuration (Master mode, 8 bit data)
SSP_CFG_Type SSP_ConfigStruct;
SSP_ConfigStructInit(&SSP_ConfigStruct);
SSP_Init(LPC_SSP1, &SSP_ConfigStruct);

// Enable SSP1 peripheral
SSP_Cmd(LPC_SSP1, ENABLE);
}
}

// ***************************************************************************
// Function - Setup SPI slave select ports
// Date     - 2013nov21
// ***************************************************************************
void setupSpiSlaveSelectPort(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
                             uint8_t spiChannelNumber, uint8_t slaveSelectNumber)
{
initializeOutputPin01High(portPinArraryPointerArrayArray[spiChannelNumber][slaveSelectNumber]);
}

void setupAllSpiChannelSlaveSelectPorts080(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
                                  uint8_t spiChannelNumber)
{
    uint8_t i;
    for (i = 0; i < MAX_SPI_SLAVE_SELECT_NUMBER; i++)
    {
    setupSpiSlaveSelectPort(portPinArraryPointerArrayArray, spiChannelNumber, i);
    }
}

void setupAllSpiChannelsAndSlaveSelectPorts(portPinArrayPointerArray portPinArraryPointerArrayArray[])
{
setupOneSpiChannel080(SPI_CHANNEL_0);
setupOneSpiChannel080(SPI_CHANNEL_1);

setupAllSpiChannelSlaveSelectPorts080(portPinArraryPointerArrayArray, SPI_CHANNEL_0);
setupAllSpiChannelSlaveSelectPorts080(portPinArraryPointerArrayArray, SPI_CHANNEL_1);
}

// ***************************************************************************
// Function - SPI transmit functions
// Date     - 2013nov21
// ***************************************************************************
void spiTransmit082(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
           uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
           SSP_DATA_SETUP_Type xferConfig)
{
setGpioDataPinLow01(portPinArraryPointerArrayArray[spiChannelNumber][slaveSelectNumber]);
if (spiChannelNumber == 0)
SSP_ReadWrite(LPC_SSP0, &xferConfig, SSP_TRANSFER_POLLING);
else // (spiChannelNumber == 1)
SSP_ReadWrite(LPC_SSP1, &xferConfig, SSP_TRANSFER_POLLING);
    setGpioDataPinHigh01(portPinArraryPointerArrayArray[spiChannelNumber][slaveSelectNumber]);
}


// ***************************************************************************
// Function - SPI loop back test
// Date     - 2013nov21
// ***************************************************************************
void spiLoopBack082(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
                    uint8_t spiChannelNumber, uint8_t slaveSelectNumber)
{
    // *** Setup transfer buffers TxBuf, RxBuf ***
#define BUFFER_SIZE 2

uint8_t TxBuf[BUFFER_SIZE];
uint8_t RxBuf[BUFFER_SIZE];
uint8_t TxBuf0[BUFFER_SIZE]; // to store init data for printing
uint8_t RxBuf0[BUFFER_SIZE]; // to store init data for printing

    // *** Setup xferConfig ***
    SSP_DATA_SETUP_Type xferConfig;
    xferConfig.tx_data = (void*)TxBuf;
    xferConfig.rx_data = (void*)RxBuf;
    xferConfig.length = BUFFER_SIZE;

    // *** Initialize transfer buffers ***************************************

    TxBuf[0] = 0x55;
    TxBuf[1] = 0xaa;
RxBuf[0] = 0x00;
RxBuf[1] = 0x00;

memcpy(TxBuf0, TxBuf, BUFFER_SIZE); // store init values
memcpy(RxBuf0, RxBuf, BUFFER_SIZE); // store init values

    // *** SPI Transfer ***
spiTransmit082(portPinArraryPointerArrayArray, \
      spiChannelNumber, slaveSelectNumber, xferConfig);

    // *** Print results *****************************************************

/*
printf("\n*** Tx Rx buffer contents before transfer *** \n\n");
printf("Index    0  1 \n\n");
printf("%02x %02x \n", TxBuf0[0], TxBuf0[1]);
printf("%02x %02x \n", RxBuf0[0], RxBuf0[1]);

printf("\n*** Tx Rx buffer contents after transfer *** \n\n");
printf("Index    0  1 \n\n");
printf("%02x %02x \n", TxBuf[0], TxBuf[1]);
printf("%02x %02x \n", RxBuf[0], RxBuf[1]);
*/

    // *** Debug only !!! ***

    printf("\n*** Now looping SPI transfers every mS *** \n\n");

    uint8_t i;

    for (i = 0; i < 2; i++)
    {
    spiTransmit082(portPinArraryPointerArrayArray, \
          spiChannelNumber, slaveSelectNumber, xferConfig);
        delayMilliSecond(1);
    }
}

// ***************************************************************************
// Function - Test SPI loopig back
// Date     - 2013nov21
// ***************************************************************************

void testSpiLoopBack01()
{
// *** Set up SPI channel and slave select port ***
/*
setupOneSpiChannel080(SPI_CHANNEL_0);
setupOneSpiChannel080(SPI_CHANNEL_1);
setupAllSpiChannelSlaveSelectPorts080(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                             SPI_CHANNEL_0);
setupAllSpiChannelSlaveSelectPorts080(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                             SPI_CHANNEL_1);
*/

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);
}
}

// ***************************************************************************
// Function - Test SPI0 SSEL pins
// Notes    - Use a scope to display the waveform of each blinking ssel pin
// Date     - 2013nov21
// ***************************************************************************

void blinkSpiSlaveSelectPort(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
                             uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
                             int onMilliSecond, int offMilliSecond, int blinkCount)
{
blinkOneLed080(portPinArraryPointerArrayArray[spiChannelNumber][slaveSelectNumber], \
     onMilliSecond, offMilliSecond, blinkCount);
}

void testSpiSselPin0801()
{
initializeOutputPin01High(PortPinArrayP02);

initializeOutputPin01High(PortPinArrayP30);
initializeOutputPin01High(PortPinArrayP31);
initializeOutputPin01High(PortPinArrayP32);
initializeOutputPin01High(PortPinArrayP33);

initializeOutputPin01High(PortPinArrayP26);
initializeOutputPin01High(PortPinArrayP27);

uint8_t i;
for (i = 0; i < 10000; i++)
{
blinkOneLed080(PortPinArrayP02, 1, 1, 200);

  blinkOneLed080(PortPinArrayP30, 1, 1, 200);
  blinkOneLed080(PortPinArrayP31, 1, 1, 200);
  blinkOneLed080(PortPinArrayP32, 1, 1, 200);
  blinkOneLed080(PortPinArrayP33, 1, 1, 200);

  blinkOneLed080(PortPinArrayP26, 1, 1, 200);
  blinkOneLed080(PortPinArrayP27, 1, 1, 200);
}
}

void testSpiSselPin0802()
{
uint8_t i, j;
for (i = 0; i < MAX_SPI_SLAVE_SELECT_NUMBER; i++)
{
initializeOutputPin01High(Olimex2SlaveSelectPortPinArrayPointerArray0[i]);
}

for (i = 0; i < 10000; i++)
{
for (i = 0; i < MAX_SPI_SLAVE_SELECT_NUMBER; i++)
{
blinkOneLed080(Olimex2SlaveSelectPortPinArrayPointerArray0[i], 1, 1, 200);
}
}
}

void testSpiSselPin0803()
{
uint8_t i, j;
for (i = 0; i < MAX_SPI_SLAVE_SELECT_NUMBER; i++)
{
initializeOutputPin01High(Olimex20SlaveSelectPortPinArrayPointerArrayArray[0][i]);
}

for (i = 0; i < 10000; i++)
{
for (i = 0; i < MAX_SPI_SLAVE_SELECT_NUMBER; i++)
{
              blinkOneLed080(Olimex20SlaveSelectPortPinArrayPointerArrayArray[0][i], 1, 1, 200);
}
}
}

void testSpiSselPin0804(portPinArrayPointerArray portPinArraryPointerArrayArray[])
{
uint8_t i, j;
for (i = 0; i < MAX_SPI_SLAVE_SELECT_NUMBER; i++)
{
initializeOutputPin01High(portPinArraryPointerArrayArray[0][i]);
}

for (i = 0; i < 10000; i++)
{
// for (i = 0; i < MAX_SPI_SLAVE_SELECT_NUMBER; i++)
for (i = 0; i < 4; i++)
{
              blinkOneLed080(portPinArraryPointerArrayArray[0][i], 1, 1, 200);
}
}
}

void testSpiSselPin0805(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
        uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
        uint8_t onMilliSecond, uint8_t offMilliSecond, uint8_t blinkCount)
{
setupSpiSlaveSelectPort(portPinArraryPointerArrayArray, \
                           spiChannelNumber, slaveSelectNumber);
blinkSpiSlaveSelectPort(portPinArraryPointerArrayArray, \
                           spiChannelNumber, slaveSelectNumber, onMilliSecond, offMilliSecond, blinkCount);
}

testSpiSselPin0806() // blink SPI channel 0, slave select pins 1 to 6
{
testSpiSselPin0805(Olimex20SlaveSelectPortPinArrayPointerArrayArray, SPI_CHANNEL_0, \
SLAVE_SELECT_1, 500, 500, 1);
testSpiSselPin0805(Olimex20SlaveSelectPortPinArrayPointerArrayArray, SPI_CHANNEL_0, \
SLAVE_SELECT_2, 500, 500, 2);
testSpiSselPin0805(Olimex20SlaveSelectPortPinArrayPointerArrayArray, SPI_CHANNEL_0, \
SLAVE_SELECT_3, 500, 500, 3);
testSpiSselPin0805(Olimex20SlaveSelectPortPinArrayPointerArrayArray, SPI_CHANNEL_0, \
SLAVE_SELECT_4, 500, 500, 4);
testSpiSselPin0805(Olimex20SlaveSelectPortPinArrayPointerArrayArray, SPI_CHANNEL_0, \
SLAVE_SELECT_5, 500, 500, 5);
testSpiSselPin0805(Olimex20SlaveSelectPortPinArrayPointerArrayArray, SPI_CHANNEL_0, \
SLAVE_SELECT_6, 500, 500, 6);
}

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


// ***********************************************************************
// mled050.h 2013nov10hkt1152
// MAX7219 4-digit 7-segment and 8x8 matrix LED
// ***********************************************************************

#include "spi050.h"

// *** MAX7219 Register Address Map ***
#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 Command Format ***
#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 DEVICE_1 1
#define DEVICE_2 2
#define DEVICE_3 3
#define DEVICE_4 4

#define LED_DRIVER_1 1
#define LED_DRIVER_2 2
#define LED_DRIVER_3 3
#define LED_DRIVER_4 4

#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_DEVICE_NUMBER 16
#define MAX_BUFFER_SIZE 32
#define MAX_MATRIX_NUMBER 4

uint8_t char_A[5] = {0x7E, 0x11, 0x11, 0x11, 0x7E};
uint8_t char_K[5] = {0x41, 0x22, 0x14, 0x08, 0x7f};
uint8_t char_O[5] = {0x3E, 0x41, 0x41, 0x41, 0x3E};

uint8_t CharBigO[8] = {0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00, 0x00, 0x00};
uint8_t CharBigK[8] = {0x41, 0x22, 0x14, 0x08, 0x7F, 0x00, 0x00, 0x00};

uint8_t TriGram0[8] = {0x54, 0x54, 0x54, 0x00, 0x54, 0x54, 0x54, 0x00};


// *** Version 0.80 ***

void displayMcp7219Display8DigitsV080(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)
{
setupMcp7219DigitModeV080(portPinArraryPointerArrayArray, \
                 spiChannelNumber, slaveSelectNumber);

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

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

void display8LedDigit080(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)
{
shutDownLedDriver080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, ledDriverNumber);
displayLedDigit080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, ledDriverNumber, DIGIT_ADDR_7, digit1);
    displayLedDigit080(portPinArraryPointerArrayArray, \
    spiChannelNumber, slaveSelectNumber, ledDriverNumber, DIGIT_ADDR_6, digit2);
    displayLedDigit080(portPinArraryPointerArrayArray, \
    spiChannelNumber, slaveSelectNumber, ledDriverNumber, DIGIT_ADDR_5, digit3);
    displayLedDigit080(portPinArraryPointerArrayArray, \
    spiChannelNumber, slaveSelectNumber, ledDriverNumber, DIGIT_ADDR_4, digit4);
    displayLedDigit080(portPinArraryPointerArrayArray, \
    spiChannelNumber, slaveSelectNumber, ledDriverNumber, DIGIT_ADDR_3, digit5);
    displayLedDigit080(portPinArraryPointerArrayArray, \
    spiChannelNumber, slaveSelectNumber, ledDriverNumber, DIGIT_ADDR_2, digit6);
    displayLedDigit080(portPinArraryPointerArrayArray, \
    spiChannelNumber, slaveSelectNumber, ledDriverNumber, DIGIT_ADDR_1, digit7);
    displayLedDigit080(portPinArraryPointerArrayArray, \
    spiChannelNumber, slaveSelectNumber, ledDriverNumber, DIGIT_ADDR_0, digit8);
    startUpLedDriver080(portPinArraryPointerArrayArray, \
    spiChannelNumber, slaveSelectNumber, ledDriverNumber);
}

void writeMcp7219Command080(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 shutDownLedDriver080(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber)
{
writeMcp7219Command080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, OPERATION_ADDR, SHUT_DOWN);
}

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

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

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

.END



No comments:

Post a Comment