2013-10-24

Max7219 normal operation and shutdown command tested OK





















Now I have tested the Max7219 shutdown and normal operation commands and found everything OK.


    // writeMax7219Command(digitControlRegisterBuffer, SHUTDOWN_ADDR, NORMAL_OPERATION_MODE);

    // writeMax7219Command(digitControlRegisterBuffer, SHUTDOWN_ADDR, SHUTDOWN_MODE);



// ***********************************************************************
// spi050.h 2013oct24hkt0900
// ***********************************************************************

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

// ***********************************************************************
// Max7219 Functions
// ***********************************************************************

void max7219v01() // 2013oct24hkt1020
{
    // *** Print project title ***********************************************
printf("*** MAX7219 Test - 2013oct24hk0937 ***\n\n");


// *** Setup MAX7219 digit control register buffer ***********************
// Digit control register buffer
#define BUFFER_SIZE 2
#define ADDRESS_INDEX 0
#define DATA_INDEX 1

uint8_t digitControlRegisterBuffer[BUFFER_SIZE];
uint8_t dummyReceiveBuffer[BUFFER_SIZE];


// *** Set up SPI ********************************************************
// Setup SCLK and SSEL
setUpSpi050(SCK0_PIO0_6);
setupSpiSsel();

// Setup xferConfig
    SSP_DATA_SETUP_Type xferConfig;
    xferConfig.tx_data = (void*)digitControlRegisterBuffer;
    xferConfig.rx_data = (void*)dummyReceiveBuffer;
    xferConfig.length = BUFFER_SIZE;


// *** Setup Max7219 digit and control ***********************************
    // Register addresses
#define NO_OP_ADDR 0x00
#define DIGIT_0_ADDR 0x01
    #define DIGIT_1_ADDR 0x02
#define DIGIT_2_ADDR 0x03
#define DIGIT_3_ADDR 0x04
#define DIGIT_4_ADDR 0x05
#define DIGIT_5_ADDR 0x06
#define DIGIT_6_ADDR 0x07
#define DIGIT_7_ADDR 0x08
#define DECODE_MODE_ADDR 0x09
#define INTENSITY       0x0a
#define SCAN_LIMIT_ADDR 0x0b
#define SHUTDOWN_ADDR   0x0c
#define DISPLAY_TEST     0x0f

// Control byte
#define SHUTDOWN_MODE 0x00
#define NORMAL_OPERATION_MODE 0x01


    // *** Test Max7219 ******************************************************

    // Load normal operation instruction into Shutdown register buffer
    // max7219NormalOperation(digitControlRegisterBuffer);

    // writeMax7219Command(digitControlRegisterBuffer, SHUTDOWN_ADDR, NORMAL_OPERATION_MODE);
    writeMax7219Command(digitControlRegisterBuffer, SHUTDOWN_ADDR, SHUTDOWN_MODE);

    // Write instruction to Max7219 every millisecond
    uint8_t i;
    for (i = 0; i < 10000000; i++)
    {
    delayMilliSecond(1);
    setSselLow();
        SSP_ReadWrite(LPC_SSP0, &xferConfig, SSP_TRANSFER_POLLING);
        setSselHigh();
    }
}

void writeMax7219Command(uint8_t digitControlRegisterBuffer[BUFFER_SIZE], \
                    uint8_t commandRegisterAddress, uint8_t command)
{
digitControlRegisterBuffer[ADDRESS_INDEX] = commandRegisterAddress;
digitControlRegisterBuffer[DATA_INDEX] = command;
}

void max7219ShutDown(uint8_t digitControlRegisterBuffer[BUFFER_SIZE])
{
digitControlRegisterBuffer[ADDRESS_INDEX] = SHUTDOWN_ADDR;
digitControlRegisterBuffer[DATA_INDEX] = SHUTDOWN_MODE;
}

void max7219NormalOperation(uint8_t digitControlRegisterBuffer[BUFFER_SIZE])
{
digitControlRegisterBuffer[ADDRESS_INDEX] = SHUTDOWN_ADDR;
digitControlRegisterBuffer[DATA_INDEX] = NORMAL_OPERATION_MODE;
}

// ***********************************************************************
// End of max7219
// ***********************************************************************

.END

No comments:

Post a Comment